Zigzag2_R_Color_Fibo_Grand_x3_Stat_Full_Line

Author: Copyright © 2005, MetaQuotes Software Corp.
0 Views
0 Downloads
0 Favorites
Zigzag2_R_Color_Fibo_Grand_x3_Stat_Full_Line
ÿþ//+------------------------------------------------------------------+

//|                 Zigzag2_R_Color_Fibo_Grand_x3_Stat_Full_Line.mq5 |

//|                      Copyright © 2005, MetaQuotes Software Corp. |

//|                                       http://www.metaquotes.net/ |

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

/*  AB0=40@B=>< 8=48:0B>@5 http://codebase.mql4.com/ru/238 4;O      |

@8A>20=8O 8A?>;L7>20;AO AB8;L DRAW_SECTION. -B>B AB8;L ?>72>;O5B     |

@8A>20BL >B@57:0<8 B>;L:> <564C B>G:0<8, =0E>4OI8<8<AO =0 @07=KE     |

10@0E. !B8;L >B@8A>2:8 DRAW_ZIGZAG ?>72>;O5B A=OBL MB> >3@0=8G5=85,  |

4;O MB>3> 8A?>;L7CNBAO 420 1CD5@0 2<5AB> >4=>3>. ;O 8;;NAB@0F88     |

MB>3> AB8;O 8 1K; =0?8A0= Zigzag2_R_.mq5.                            |

 :>4 4>102;5=0 >1@01>B:0 2=5H=53>  10@0 (outside bar), :>340  High  |

B5:CI53> 10@0 2KH5 ?@54K4CI8E, 0 Low B5:CI53> 10@0 =865 ?@54K4CI8E.  |

;>: >1@01>B:8 2=5H=53> 10@0 40= :0: ?@8<5@. K <>65B5 8A?>;L7>20BL  |

A2>9 0;3>@8B< 4;O B0:>9 A8BC0F88.                                    |

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

*/

//---- 02B>@AB2> 8=48:0B>@0

#property copyright "Copyright © 2005, MetaQuotes Software Corp."

//---- AAK;:0 =0 A09B 02B>@0

#property link      "http://www.metaquotes.net/"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.00"

#property description "ZigZag" 

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

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

//|  >1JO2;5=85 :>=AB0=B                         |

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

#define FIBO_LINES_TOTAL 7     // >=AB0=B0 4;O :>;8G5AB20 C@>2=59 D81>

#define SIZE 21                // >=AB0=B0 4;O :>;8G5AB20 2K7>2>2 DC=:F88 CountIndicator 2 :>45

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

//---- 4;O @0AGQB0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20= 4204F0BL >48= 1CD5@

#property indicator_buffers 24

//---- 8A?>;L7>20=> 2A53> 4204F0BL 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   20

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0              |

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

//---- 2 :0G5AB25 8=48:0B>@0 8A?>;L7>20= ZIGZAG

#property indicator_type20   DRAW_COLOR_ZIGZAG

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label20  "ZigZag"

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20=K

#property indicator_color20 clrMediumVioletRed,clrMediumSeaGreen

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style20  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 3

#property indicator_width20  3

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

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

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

input int ExtDepth=12;

input int ExtDeviation=5;

input int ExtBackstep=3;

input int Shift=0;                                  // A4283 7837030 ?> 3>@87>=B0;8 2 10@0E

input double  FiboRatio =1.000;                     //>MDD8F85=B 4><=>65=8O 2A5E D81>C@>2=59

uint    FiboTotal=1;                                //>;8G5AB2> 4>?>;=8B5;L=KE A5:B>@>2 $81> A25@EC 8;8 A=87C

//----

input double  FiboLevel1 =0.000;                    //7=0G5=85 D81>C@>2=O 1

input ENUM_LINE_STYLE StyleLevel1=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 1

input uint   WidthLevel1=4;                         //B>;I8=0 ;8=88 D81>C@>2=O 1

input color  Color_Level1 = clrDodgerBlue;          //F25B D81>C@>2=O 1

//----

input double  FiboLevel2=0.236;                     //7=0G5=85 D81>C@>2=O 2

input ENUM_LINE_STYLE StyleLevel2=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 2

input uint    WidthLevel2=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 2

input color   Color_Level2= clrDarkViolet;          //F25B D81>C@>2=O 2

//----

input double  FiboLevel3 =0.382;                    //7=0G5=85 D81>C@>2=O 3

input ENUM_LINE_STYLE StyleLevel3=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 3

input uint    WidthLevel3=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 3

input color   Color_Level3 = clrOrange;             //F25B D81>C@>2=O 3

//----

input double  FiboLevel4 =0.500;                    //7=0G5=85 D81>C@>2=O 4

input ENUM_LINE_STYLE StyleLevel4=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 4

input uint    WidthLevel4=2;                        //B>;I8=0 ;8=88 D81>C@>2=O 4

input color   Color_Level4 = clrMagenta;            //F25B D81>C@>2=O 4

//----  

input double  FiboLevel5 =0.618;                    //7=0G5=85 D81>C@>2=O 5

input ENUM_LINE_STYLE StyleLevel5=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 5

input uint    WidthLevel5=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 5

input color   Color_Level5 = clrBlue;               //F25B D81>C@>2=O 5

//----

input double  FiboLevel6=0.764;                     //7=0G5=85 D81>C@>2=O 6

input ENUM_LINE_STYLE StyleLevel6=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 6

input uint    WidthLevel6=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 6

input color   Color_Level6 = clrGray;               //F25B D81>C@>2=O 6

//----

input double  FiboLevel7 = 1.000;                   //7=0G5=85 D81>C@>2=O 7

input ENUM_LINE_STYLE StyleLevel7=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 7

input uint    WidthLevel7=4;                        //B>;I8=0 ;8=88 D81>C@>2=O 7

input color   Color_Level7 = clrDodgerBlue;         //F25B D81>C@>2=O 7

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

#define FIBO_LINES_TOTAL_XN_FULL FIBO_LINES_TOTAL*(1+FiboTotal*2)-FiboTotal*2    // >=AB0=B0 4;O :>;8G5AB20 C@>2=59 D81>

//---- <0AA82K ?5@5<5==KE 4;O ;8=89 $81>

double Values[];

color Colors[];

ENUM_LINE_STYLE Styles[];

uint Widths[];

string FiboLineNames[];

//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double ZigzagPeakBuffer[],ZigzagLawnBuffer[];

double HighMapBuffer[],LowMapBuffer[];

double ColorBuffer[];

int level=3; // recounting's depth 

bool downloadhistory=false;

double dExtDeviation;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

int min_rates_total;

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

//|  0AA82K ?5@5<5==KE 4;O A>740=8O 8=48:0B>@=KE 1CD5@>2            |

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

class CIndicatorsBuffers

  {

public: double    LineIndBuffer[];

  };

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

//| !>740=85 8=48:0B>@=KE 1CD5@>2                                    |

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

CIndicatorsBuffers Ind[SIZE];

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

   min_rates_total=ExtDepth+ExtBackstep;

   dExtDeviation=ExtDeviation*_Point;



//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

   SetIndexBuffer(19,ZigzagLawnBuffer,INDICATOR_DATA);

   SetIndexBuffer(20,ZigzagPeakBuffer,INDICATOR_DATA);

   SetIndexBuffer(21,ColorBuffer,INDICATOR_COLOR_INDEX);

//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

   SetIndexBuffer(22,HighMapBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(23,LowMapBuffer,INDICATOR_CALCULATIONS);

//---- 70?@5B =0 >B@8A>2:C 8=48:0B>@>< ?CABKE 7=0G5=89

   PlotIndexSetDouble(19,PLOT_EMPTY_VALUE,NULL);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@0E :0: 2 B09<A5@8OE   

   ArraySetAsSeries(ZigzagLawnBuffer,true);

   ArraySetAsSeries(ZigzagPeakBuffer,true);

   ArraySetAsSeries(ColorBuffer,true);

   ArraySetAsSeries(HighMapBuffer,true);

   ArraySetAsSeries(LowMapBuffer,true);

//---- CAB0=>2:0 ?>78F88, A :>B>@>9 =0G8=05BAO >B@8A>2:0 C@>2=59 >;;8=465@0

   PlotIndexSetInteger(19,PLOT_DRAW_BEGIN,min_rates_total);

//---- #AB0=>2:0 D>@<0B0 B>G=>AB8 >B>1@065=8O 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 8<O 4;O >:>= 40==KE 8 ;M910 4;O AC1J>:>= 

   string shortname;

   StringConcatenate(shortname,"Zigzag2_R_(ExtDepth=",

                     ExtDepth,"ExtDeviation = ",ExtDeviation,"ExtBackstep = ",ExtBackstep,")");

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

   

   //----

   ArrayResize(Values,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(Colors,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(Styles,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(Widths,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(FiboLineNames,FIBO_LINES_TOTAL_XN_FULL);

//----  

   Values[0]=FiboLevel1*FiboRatio;

   Values[1]=FiboLevel2*FiboRatio;

   Values[2]=FiboLevel3*FiboRatio;

   Values[3]=FiboLevel4*FiboRatio;

   Values[4]=FiboLevel5*FiboRatio;

   Values[5]=FiboLevel6*FiboRatio;

   Values[6]=FiboLevel7*FiboRatio;

//----  

   FiboLineNames[0]="FiboLevel "+DoubleToString(100*Values[0],1);

   FiboLineNames[1]="FiboLevel "+DoubleToString(100*Values[1],1);

   FiboLineNames[2]="FiboLevel "+DoubleToString(100*Values[2],1);

   FiboLineNames[3]="FiboLevel "+DoubleToString(100*Values[3],1);

   FiboLineNames[4]="FiboLevel "+DoubleToString(100*Values[4],1);

   FiboLineNames[5]="FiboLevel "+DoubleToString(100*Values[5],1);

   FiboLineNames[6]="FiboLevel "+DoubleToString(100*Values[6],1);

//----   

   Colors[0]=Color_Level1;

   Colors[1]=Color_Level2;

   Colors[2]=Color_Level3;

   Colors[3]=Color_Level4;

   Colors[4]=Color_Level5;

   Colors[5]=Color_Level6;

   Colors[6]=Color_Level7;

//----   

   Styles[0]=StyleLevel1;

   Styles[1]=StyleLevel2;

   Styles[2]=StyleLevel3;

   Styles[3]=StyleLevel4;

   Styles[4]=StyleLevel5;

   Styles[5]=StyleLevel6;

   Styles[6]=StyleLevel7;

//----   

   Widths[0]=WidthLevel1;

   Widths[1]=WidthLevel2;

   Widths[2]=WidthLevel3;

   Widths[3]=WidthLevel4;

   Widths[4]=WidthLevel5;

   Widths[5]=WidthLevel6;

   Widths[6]=WidthLevel7;



   for(int count=1; count<=int(FiboTotal); count++)

      for(int lev=1; lev<7; lev++)

        {

         int kkk=lev+6*(2*count-1);

         Values[kkk]=Values[lev]+count;

         Colors[kkk]=Colors[lev];

         FiboLineNames[kkk]=FiboLineNames[lev];

         //Styles[kkk]=Styles[lev];

         Widths[kkk]=Widths[lev];

         //----

         kkk=lev+6*(2*count);

         Values[kkk]=-Values[7-lev]-count+1;

         FiboLineNames[kkk]="FiboLevel "+DoubleToString(100*Values[kkk],1);

         

         //Colors[kkk]=Colors[lev-1];

         Colors[kkk]=Colors[7-lev];

         //Styles[kkk]=Styles[lev-1];

         Widths[kkk]=Widths[lev-1];

        }

//---- 

   for(int numb=0; numb<int(FIBO_LINES_TOTAL_XN_FULL); numb++)

     {

      shortname=FiboLineNames[numb];

      //--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

      PlotIndexSetString(numb,PLOT_LABEL,shortname);

      //---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

      PlotIndexSetDouble(numb,PLOT_EMPTY_VALUE,EMPTY_VALUE);

      //---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0

      PlotIndexSetInteger(numb,PLOT_DRAW_BEGIN,min_rates_total);

      //---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

      SetIndexBuffer(numb,Ind[numb].LineIndBuffer,INDICATOR_DATA);

      //---- 8=45:A0F8O M;5<5=B>2 2 1CD5@0E :0: 2 B09<A5@8OE   

      ArraySetAsSeries(Ind[numb].LineIndBuffer,true);

      //---- :>?8@>20=85 A2>9AB2 ?5@2>9 ;8=88 8=48:0B>@0 4;O 2A5E >AB0;L=KE

      PlotIndexSetInteger(numb,PLOT_DRAW_TYPE,DRAW_LINE);

      PlotIndexSetInteger(numb,PLOT_LINE_WIDTH,Widths[numb]);

      PlotIndexSetInteger(numb,PLOT_COLOR_INDEXES,1);

      PlotIndexSetInteger(numb,PLOT_LINE_COLOR,0,Colors[numb]);

      //---- >ACI5AB2;5=85 A42830 8=48:0B>@0 ?> 3>@87>=B0;8 =0 Shift

      PlotIndexSetInteger(numb,PLOT_SHIFT,Shift);

      //---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

      PlotIndexSetInteger(numb,PLOT_SHOW_DATA,false);

     }

//----   

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(rates_total<min_rates_total) return(0);



//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE 

   bool Max,Min;

   int limit,climit,bar;  

   int iii=0,counterZ=0,whatlookfor=0;

   int back,lasthighpos=0,lastlowpos=0;

   double val,res;

   double curlow=9999999999.0,curhigh=0.0,lasthigh=0.0,lastlow=999999999.0;



//---- @0AGQB AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AGQB0 10@>2 8 AB0@B>20O 8=8F80;870F8O ?5@5<5==KE

   if(prev_calculated>rates_total || prev_calculated<=0)// ?@>25@:0 =0 ?5@2K9 AB0@B @0AGQB0 8=48:0B>@0

     {

      limit=rates_total-min_rates_total; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

      climit=limit; // AB0@B>2K9 =><5@ 4;O @0A:@0A:8 8=48:0B>@0

      ArrayInitialize(ZigzagPeakBuffer,NULL);

      ArrayInitialize(ZigzagLawnBuffer,NULL);

      ArrayInitialize(HighMapBuffer,NULL);

      ArrayInitialize(LowMapBuffer,NULL);

     }

   else

     {

      limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2

      climit=limit+min_rates_total; // AB0@B>2K9 =><5@ 4;O @0A:@0A:8 8=48:0B>@0



      //----

      while(counterZ<level && iii<100)

        {

         res=(ZigzagPeakBuffer[iii]+ZigzagLawnBuffer[iii]);

         //----

         if(res) counterZ++;

         iii++;

        }

      iii--;

      limit=iii;     

      //----

      if(LowMapBuffer[iii])

        {

         curlow=LowMapBuffer[iii];

         whatlookfor=1;

        }

      else

        {

         curhigh=HighMapBuffer[iii];

         whatlookfor=-1;

        }

      //----

      for(iii=limit-1; iii>=0; iii--)

        {

         ZigzagPeakBuffer[iii] = NULL;

         ZigzagLawnBuffer[iii] = NULL;

         LowMapBuffer[iii]=NULL;

         HighMapBuffer[iii]=NULL;

        }

     }



//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E :0: 2 B09<A5@8OE  

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);



//---- 5@2K9 1>;LH>9 F8:; @0AGQB0 8=48:0B>@0

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      val=low[ArrayMinimum(low,bar,ExtDepth)];

      //----

      if(val==lastlow)

         val=NULL;

      else

        {

         lastlow=val;

         //----

         if(low[bar]-val>dExtDeviation)

            val=NULL;

         else

           {

            //----

            for(back=1; back<=ExtBackstep; back++)

              {

               res=LowMapBuffer[bar+back];

               //----

               if(res && res>val) LowMapBuffer[bar+back]=NULL;

              }

           }

        }

      //----

      if(low[bar]==val)

         LowMapBuffer[bar]=val;

      else

         LowMapBuffer[bar]=NULL;

      //--- high

      val=high[ArrayMaximum(high,bar,ExtDepth)];

      //----

      if(val==lasthigh)

         val=NULL;

      else

        {

         lasthigh=val;

         //----

         if(val-high[bar]>dExtDeviation)

            val=NULL;

         else

           {

            //----

            for(back=1; back<=ExtBackstep; back++)

              {

               res=HighMapBuffer[bar+back];

               //----

               if(res && res<val)  HighMapBuffer[bar+back]=NULL;

              }

           }

        }

      //----

      if(high[bar]==val)

         HighMapBuffer[bar]=val;

      else

         HighMapBuffer[bar]=NULL;

     }

     

//---- final cutting 

   if(!whatlookfor)

     {

      lastlow=NULL;

      lasthigh=NULL;

     }

   else

     {

      lastlow=curlow;

      lasthigh=curhigh;

     }



//---- B>@>9 1>;LH>9 F8:; @0AGQB0 8=48:0B>@0

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      res=NULL;

      switch(whatlookfor)

        {

         // look for peak or lawn 

         case 0: if(!lastlow && !lasthigh)

           {

            if(HighMapBuffer[bar])

              {

               lasthigh=high[bar];

               lasthighpos = bar;

               whatlookfor = -1;

               ZigzagPeakBuffer[bar]=lasthigh;

               res=1;

              }

            if(LowMapBuffer[bar])

              {

               lastlow=low[bar];

               lastlowpos=bar;

               whatlookfor=1;

               ZigzagLawnBuffer[bar]=lastlow;

               res=1;

              }

           }

         break;

         // look for peak

         case 1: if(LowMapBuffer[bar] && LowMapBuffer[bar] < lastlow && !HighMapBuffer[bar])

           {

            ZigzagLawnBuffer[lastlowpos]=NULL;

            lastlowpos=bar;

            lastlow=LowMapBuffer[bar];

            ZigzagLawnBuffer[bar]=lastlow;

            res=1;

           }

         if(HighMapBuffer[bar] && !LowMapBuffer[bar])

           {

            lasthigh=HighMapBuffer[bar];

            lasthighpos=bar;

            ZigzagPeakBuffer[bar]=lasthigh;

            whatlookfor=-1;

            res=1;

           }

         break;

         // look for lawn

         case -1:  if(HighMapBuffer[bar] && HighMapBuffer[bar]>lasthigh && !LowMapBuffer[bar])

           {

            ZigzagPeakBuffer[lasthighpos]=NULL;

            lasthighpos=bar;

            lasthigh=HighMapBuffer[bar];

            ZigzagPeakBuffer[bar]=lasthigh;

           }

         if(LowMapBuffer[bar] && !HighMapBuffer[bar])

           {

            lastlow=LowMapBuffer[bar];

            lastlowpos=bar;

            ZigzagLawnBuffer[bar]=lastlow;

            whatlookfor=1;

           }

         break;

         default: return(rates_total);

        }

     }

//---- "@5B89 1>;LH>9 F8:; @0A:@0A:8 8=48:0B>@0

   for(bar=climit; bar>=0 && !IsStopped(); bar--)

     {

      Max=ZigzagPeakBuffer[bar];

      Min=ZigzagLawnBuffer[bar];

      

      if(!Max && !Min) ColorBuffer[bar]=ColorBuffer[bar+1];

      if( Max &&  Min)

        {

         if(ColorBuffer[bar+1]==0) ColorBuffer[bar]=1;

         else                      ColorBuffer[bar]=0;

        }



      if( Max && !Min) ColorBuffer[bar]=1;

      if(!Max &&  Min) ColorBuffer[bar]=0;

     }

//---- >A=>2=>9 F8:; @0AGQB0 8=48:0B>@0

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      //---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE 4;O ?>AB@>5=8O D81

      int bar1,bar2,sign;

      double price1,price2;

      //---- >AB@>5=85 $81>

      bar1=FindFirstExtremum(bar,rates_total,ZigzagPeakBuffer,ZigzagLawnBuffer,sign,price1);

      if(bar1<0) continue;

      bar1=FindSecondExtremum(sign,bar1,rates_total,ZigzagPeakBuffer,ZigzagLawnBuffer,sign,price1);

      if(bar1<0) continue;

      bar2=FindSecondExtremum(sign,bar1,rates_total,ZigzagPeakBuffer,ZigzagLawnBuffer,sign,price2);  

      if(bar2<0) continue;  

      double range=price1-price2;

      

      for(int numb=0; numb<int(FIBO_LINES_TOTAL_XN_FULL); numb++)

       for(int index=bar1; index>=bar && !IsStopped(); index--) Ind[numb].LineIndBuffer[index]=price2+range*Values[numb];

     }

//---   

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      for(int numb=0; numb<int(SIZE-2); numb++)

        {

         if(Ind[numb].LineIndBuffer[bar+1]!=Ind[numb].LineIndBuffer[bar]&&Ind[numb].LineIndBuffer[bar]!=EMPTY_VALUE)

           {

            Ind[numb].LineIndBuffer[bar+1]=EMPTY_VALUE;

           }

        }

     }

//----         

   return(rates_total);

  }

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

//| >8A: A0<>9 ?5@2>9 25@H8=K 837030 2 1CD5@0E B09<A5@8OE          |

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

int FindFirstExtremum(int &StartPos,int Rates_total,double &UpArray[],double &DnArray[],int &Sign,double &Extremum)

  {

//----

   if(StartPos>=Rates_total)StartPos=Rates_total-1;



   for(int bar=StartPos; bar<Rates_total; bar++)

     {

      if(UpArray[bar]!=0.0 && UpArray[bar]!=EMPTY_VALUE)

        {

         Sign=+1;

         Extremum=UpArray[bar];

         return(bar);

         break;

        }



      if(DnArray[bar]!=0.0 && DnArray[bar]!=EMPTY_VALUE)

        {

         Sign=-1;

         Extremum=DnArray[bar];

         return(bar);

         break;

        }

     }

//----

   return(-1);

  }

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

//| >8A: 2B>@>9 25@H8=K 837030 2 1CD5@0E B09<A5@8OE                |

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

int FindSecondExtremum(int Direct,int &StartPos,int Rates_total,double &UpArray[],double &DnArray[],int &Sign,double &Extremum)

  {

//----

   if(StartPos>=Rates_total) StartPos=Rates_total-1;



   if(Direct==-1)

      for(int bar=StartPos; bar<Rates_total; bar++)

        {

         if(UpArray[bar]!=0.0 && UpArray[bar]!=EMPTY_VALUE)

           {

            Sign=+1;

            Extremum=UpArray[bar];

            return(bar);

            break;

           }



        }



   if(Direct==+1)

      for(int bar=StartPos; bar<Rates_total; bar++)

        {

         if(DnArray[bar]!=0.0 && DnArray[bar]!=EMPTY_VALUE)

           {

            Sign=-1;

            Extremum=DnArray[bar];

            return(bar);

            break;

           }

        }

//----

   return(-1);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---