ZigZag

Metatrader, MQL4

 

ZigZag , , . , .

 

 

//

//

//+------------------------------------------------------------------+

#property copyright "Shumi"

#property link "http://apsheronsk.bozo.ru"

 

int max_lenght_size = 1;// . -

double sea[50000][3]; // 0- = , 1- = , 2- = , 3- =

datetime tt[50000];

int count = 0;

double height_koef = 3600; //

//+------------------------------------------------------------------+

int start()

{

int i, up=0, down=0, trigger_up = 0, trigger_down = 0, up_i, down_i;

int first=0; // - (=1) (=-1)

int kolvo = Bars;

Alert(kolvo);

datetime time_down, time_up;

double cur_up = High[kolvo];

double cur_down = High[kolvo];

for(i=kolvo-1;i>0;i--)

{

if(High[i] > cur_up)

{

cur_up = High[i]; time_up = Time[i]; up_i = i;

up++;

if((up > max_lenght_size) && (trigger_down == 0))

{

ObjectCreate(DS(i,0), OBJ_ARROW, 0, time_down, cur_down); //

ObjectSet(DS(i,0), OBJPROP_ARROWCODE, 242);

//Alert("down ", time_down, " || ", iLow(Symbol(),Period(),down_i));

if(count != 0)

{

sea[count][0] = (iHigh(Symbol(),Period(),tt[count-1]) - iLow(Symbol(),Period(),down_i)); //

sea[count][1] = tt[count-1] - down_i; //

if(sea[count][1] != 0)

{sea[count][2] = MathArctan(sea[count][0]/(sea[count][1]/height_koef))*180/3.14159;} //

else {sea[count][2] = 0;}

tt[count] = down_i; //

}

//Alert("up = ", sea[count][0]," || = ", sea[count][1]," || = ", sea[count][2]);

down = 0; cur_down = Low[i]; time_down = Time[i]; down_i = i;

trigger_down = 1; trigger_up = 0;

if(first == 0) {first = 1;}

count++;

}

else if(up > max_lenght_size)

{

//Alert("up>lenght :i=", i);

down = 0; cur_down = Low[i]; time_down = Time[i];

}

}

if(Low[i] < cur_down)

{

cur_down = Low[i]; time_down = Time[i]; down_i = i;

down++;

if((down > max_lenght_size) && (trigger_up == 0))

{

ObjectCreate(DS(i,0), OBJ_ARROW, 0, time_up, cur_up); //

ObjectSet(DS(i,0), OBJPROP_ARROWCODE, 241);

//Alert(" up ", time_up, " || ", iHigh(Symbol(),Period(),up_i));

if(count != 0)

{

sea[count][0] = (iLow(Symbol(), Period(), tt[count-1]) - iHigh(Symbol(),Period(),up_i))*(-1); //

sea[count][1] = tt[count-1] - up_i; //

if(sea[count][1] != 0)

{sea[count][2] = MathArctan(sea[count][0]/(sea[count][1]/height_koef))*180/3.14159;} //

else {sea[count][2] = 0;}

tt[count] = up_i; //

}

//Alert("down = ", sea[count][0]," || = ", sea[count][1]," || = ", sea[count][2]);

up = 0; cur_up = High[i]; time_up = Time[i]; up_i = i;

trigger_up = 1; trigger_down = 0;

if(first == 0) {first = -1;}

count++;

}

else if(down > max_lenght_size)

{

//Alert("down>lenght :i=", i);

up = 0; cur_up = High[i]; time_up = Time[i];

}

}

}

 

Alert(" = ",count);

Print_Params_in_File();

return(0);

}

//+------------------------------------------------------------------+

string DS(double a, int kol)

{

return (DoubleToStr(a,kol));

}

//+------------------------------------------------------------------+

void Print_Params_in_File()

{

// csv

int handle = FileOpen("zigzag.csv", FILE_CSV|FILE_WRITE,';');

for(int i=2;i<count;i++)

{

//FileWrite(handle, DoubleToStr(sea[i][0],4), sea[i][1], MathRound(sea[i][2]));

FileWrite(handle,DoubleToStr(sea[i][0],4));

FileWrite(handle,sea[i][1]);

FileWrite(handle,MathRound(sea[i][2]));

}

FileClose(handle);

}

//+------------------------------------------------------------------+

<<



@Mail.ru

 
 
VBA -2014
, E-mail: apsheronka@mail.ru
,


http://apsheronsk.bozo.ru - !


`