//+------------------------------------------------------------------+
//| Trade Day Of Week.mq4 |
//| Copyright © 2008, Vasily Sokolov (C-4) |
//| e-mail: vs-box@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, BazilSoft"
#property link "vs-box@mail.ru"
#property show_inputs
extern int BeginYear=1998;
extern int EndYear=2008;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
//ÏÅÐÅÌÅÍÍÛÅ ÂÛÂÎÄßÙÈÅÑß Â ÔÀÉË:
// ïåðâîé ÿ÷åéêå ìàññèâà õðàíèòñÿ ñòàòèñòèêà çà ãîä, âî âòîðîé ñîâîêóïíàÿ ñòàòèñòèêà çà âñå ãîäû
double AllDaysOfWeek[2]; //1. Âñåãî äíåé íåäåëè â ãîäó (íàïðèìåð â ãîäó 52 ïîíåäåëüíèêà)*
double PositivelyDays[2]; //2. Äíè çàêðûâøèåñÿ ïîëîæèòåëüíî*
double NegativelyDays[2]; //3. Äíè çàêðûâøèåñÿ îòðèöàòåëüíî*
double PercentPositivelyDays[2]; //4. Ïðîöåíò äíåé çàêðûâøèõñÿ ïîëîæèòåëüíî îò AllDaysOfWeek
double AllPtM[2]; //5. Âñåãî ïóíêòîâ ïî ìîäóëþ (Close-Open)*
double AllPt[2]; //6. Âñåãî ïóíêòîâ (Close-Open)*
double PositivelyPt[2]; //7. Ïîëîæèòåëüíûõ ïóíêòîâ (Close-Open, òîëüêî åñëè Close>Open)*
double NegativelyPt[2]; //8. Îòðèöàòåëüíûõ ïóíêòîâ (Close-Open, òîëüêî åñëè Close<Open)*
double PercentPosityvelyPt[2]; //9. Ïðîöåíò ïîëîæèòåëüíûõ ïóíêòîâ îò AllPtM
double RangeOfPrice[2]; //10. Äèàïàçîí öåí äíÿ, (High-Low)
int FileHandle;
int FileStat;
void WriteResults(int FileName, int BYear, int a){
string Y, N;
if(BYear==0){Y="Èòîãî";N="\n";}
else{Y=BYear;}
FileWrite(FileName, Y,"\t", DoubleToStr(AllDaysOfWeek[a], 0), DoubleToStr(PositivelyDays[a], 0),
DoubleToStr(NegativelyDays[a], 0), DoubleToStr(PercentPositivelyDays[a], 1), DoubleToStr((RangeOfPrice[a]/AllDaysOfWeek[a]), 0),
DoubleToStr(AllPtM[a]/AllDaysOfWeek[a], 0), DoubleToStr(AllPt[a]/AllDaysOfWeek[a], 0), DoubleToStr(PositivelyPt[a]/AllDaysOfWeek[a], 0),
DoubleToStr(NegativelyPt[a]/AllDaysOfWeek[a], 0), DoubleToStr(PercentPosityvelyPt[a], 1), N);
}
void WriteStatistic(int index){
string YY, MM, DD, YYMMDD;
double RangeOfPrice;
double AllPt;
YY=TimeYear(Time[index]);
MM=TimeMonth(Time[index]);
DD=TimeDay(Time[index]);
YYMMDD=YY+"."+MM+"."+DD;
RangeOfPrice=(High[index]-Low[index])/Point;
AllPt=(Close[index]-Open[index])/Point;
FileWrite(FileStat, YYMMDD, " ", RangeOfPrice, " ", AllPt);
}
int start()
{
//--------------------------------------------------------------------
//ÑËÓÆÅÁÍÛÅ ÏÅÐÅÌÅÍÍÛÅ:
int index; //Íîìåð èññëåäóåìîãî äíÿ
string DW; //Íàçâàíèå äíÿ íåäåëè
string FileName;
//--------------------------------------------------------------------
if(Period()<1440||Period()>1440){
Print("Ïîìåíÿéòå òàéìôðåéì íà äåíü");
return(0);}
if(BeginYear>Year()||EndYear>Year()){
Print("Íà÷àëüíûé èëè êîíå÷íûé ãîä íå ìîæåò áûòü áîëüøå òåêóùåãî");
return(0);}
if(BeginYear<TimeYear(Time[Bars-1])||EndYear<TimeYear(Time[Bars-1])){
Print("Íà÷àëüíûé èëè êîíå÷íûé ãîä íå ìîæåò áûòü ìåíüøå ñàìîé ñòàðîé èçâåñòíîé öåíû");
return(0);}
if(BeginYear>EndYear){
Print("Êîíå÷íûé ãîä íå ìîæåò áûòü ìåíüøå íà÷àëüíîãî");
return(0);}
if(Bars<270){
Print("Ñëèøêîì ìàëî äàííûõ. Çàãðóçèòå áîëüøå äàííûõ");
return(0);}
FileName="TDW_"+Symbol()+BeginYear+"-"+EndYear+".txt";
FileHandle=FileOpen(FileName, FILE_WRITE | FILE_CSV, "\t");
FileStat=FileOpen("_StatisticTDW.txt", FILE_WRITE | FILE_CSV, "\t");
if(FileHandle<1){
Print("Íå óäàëîñü îòêðûòü ôàéë, ïðè÷èíà:", GetLastError());
return;
}
for(int MDayOfWeek=1;MDayOfWeek<=5;MDayOfWeek++) //Íà÷èíàåì ñ ïîíåäåëüíèêà(1), çàêàí÷èâàåì ïÿòíèöåé(5)
{
index=Bars-1;
while(BeginYear!=TimeYear(Time[index])){index--;}
switch(MDayOfWeek)
{
case 1: DW="ÏÎÍÅÄÅËÜÍÈÊ"; break;
case 2: DW="ÂÒÎÐÍÈÊ"; break;
case 3: DW="ÑÐÅÄÀ\t"; break;
case 4: DW="×ÅÒÂÅÐÃ"; break;
case 5: DW="ÏßÒÍÈÖÎ\t";
}
FileWrite(FileHandle, DW);
for(int BYear=BeginYear; (BYear<=EndYear)&&(index>=0); BYear++)
{
Print(DW, " ", BYear);
while(BYear==TimeYear(Time[index])) //Ïðîñìàòðèâàåì âñå äíè ãîäà
{
if(TimeDayOfWeek(Time[index])==MDayOfWeek) //Âûáèðàåì èç íèõ òîëüêî MDayOfWeek (íàïð. ïîíåäåëüíèêè)
{
AllDaysOfWeek[0]++;
RangeOfPrice[0]=RangeOfPrice[0]+(High[index]-Low[index])/Point;
AllPt[0]=AllPt[0]+(Close[index]-Open[index])/Point;
if(Close[index]>Open[index]) //Åñëè çàêðûòèå áîëüøå îòêðûòèÿ - äåíü ïîëîæèòåëüíûé
{
PositivelyDays[0]++;
PositivelyPt[0]=PositivelyPt[0]+(Close[index]-Open[index])/Point;
AllPtM[0]=AllPtM[0]+(Close[index]-Open[index])/Point;
}
if(Close[index]<Open[index]) //Åñëè çàêðûòèå ìåíüøå îòêðûòèÿ - äåíü îòðèöàòåëüíûé
{
NegativelyDays[0]++;
NegativelyPt[0]=NegativelyPt[0]-(Close[index]-Open[index])/Point;
AllPtM[0]=AllPtM[0]+(-1*(Close[index]-Open[index])/Point);
}
//Äëÿ ïðîâåðêè ïðàâèëüíîñòè ïîäñ÷åòà èñïîëüçîâàëàñü âñïîìîãàòåëüíàÿ ôóíêöèÿ WriteStatistic
//îíà ïèøåò â îòäåëüíûé ôàéë äàòó êàæäîãî äíÿ íåäåëè, åãî äíåâíîé äèàïîçîí è äèàïîçîí Close-Open
//Ïðè æåëàíèè åå ìîæíî çàêîììåíòèðîâàòü.
WriteStatistic(index);
}
index--;
}
if(AllPtM[0]>0){
PercentPosityvelyPt[0]=PositivelyPt[0]*100/AllPtM[0];}
if(AllDaysOfWeek[0]>0){
PercentPositivelyDays[0]=PositivelyDays[0]*100/AllDaysOfWeek[0];}
AllDaysOfWeek[1]=AllDaysOfWeek[1]+AllDaysOfWeek[0];
AllPt[1]=AllPt[1]+AllPt[0];
AllPtM[1]=AllPtM[1]+AllPtM[0];
PositivelyDays[1]=PositivelyDays[1]+PositivelyDays[0];
NegativelyDays[1]=NegativelyDays[1]+NegativelyDays[0];
PositivelyPt[1]=PositivelyPt[1]+PositivelyPt[0];
NegativelyPt[1]=NegativelyPt[1]+NegativelyPt[0];
RangeOfPrice[1]=RangeOfPrice[1]+RangeOfPrice[0];
//Âûâîäèì ïåðåìåííûå â ôàéë
WriteResults(FileHandle, BYear, 0);
AllDaysOfWeek[0]=0;AllPt[0]=0;AllPtM[0]=0;PositivelyDays[0]=0;NegativelyDays[0]=0;RangeOfPrice[0]=0;
PositivelyPt[0]=0;NegativelyPt[0]=0;PercentPosityvelyPt[0]=0;PercentPositivelyDays[0]=0;
}
if(AllPtM[1]>0){
PercentPosityvelyPt[1]=PositivelyPt[1]*100/AllPtM[1];}
if(AllDaysOfWeek[1]>0){
PercentPositivelyDays[1]=PositivelyDays[1]*100/AllDaysOfWeek[1];}
//âûâîäèì èòîãîâóþ ñòàòèñòèêó â ôàéë
WriteResults(FileHandle, 0, 1);
AllDaysOfWeek[1]=0;AllPt[1]=0;AllPtM[1]=0;PositivelyDays[1]=0;NegativelyDays[1]=0;RangeOfPrice[1]=0;
PositivelyPt[1]=0;NegativelyPt[1]=0;PercentPosityvelyPt[1]=0;PercentPositivelyDays[1]=0;
}
return(0);
}
//+------------------------------------------------------------------+
Comments