AlexSTAL_ZigZagProf_channel

Author: Copyright 2011, AlexSTAL
0 Views
0 Downloads
0 Favorites
AlexSTAL_ZigZagProf_channel
ÿþ//+------------------------------------------------------------------+

//|                                  AlexSTAL_ZigZagProf_channel.mq5 |

//|                                         Copyright 2011, AlexSTAL |

//|                                           http://www.alexstal.ru |

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

#property copyright "Copyright 2011, AlexSTAL"

#property link      "http://www.alexstal.ru"

#property version   "1.00"

#property indicator_chart_window

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

#property indicator_buffers 9

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

#property indicator_plots   5

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color1  clrLavender

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

#property indicator_label1  " AlexSTAL_ZigZagProf Cloud"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 2 2 2845 <=>3>F25B=>9 ;8=88

#property indicator_type2   DRAW_COLOR_LINE

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

#property indicator_color2  clrMediumSpringGreen,clrOrange

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

#property indicator_width2  2

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

#property indicator_label2  "Up  AlexSTAL_ZigZagProf"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 3 2 2845 <=>3>F25B=>9 ;8=88

#property indicator_type3   DRAW_COLOR_LINE

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

#property indicator_color3  clrMediumSpringGreen,clrOrange

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

#property indicator_width3  2

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

#property indicator_label3 "Down  AlexSTAL_ZigZagProf"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 4 2 2845 A8<2>;0

#property indicator_type4   DRAW_ARROW

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

#property indicator_color4  clrBlue

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

#property indicator_width4  2

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

#property indicator_label4  "Up AlexSTAL_ZigZagProf_Arrows"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 5 2 2845 A8<2>;0

#property indicator_type5   DRAW_ARROW

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

#property indicator_color5  clrDeepPink

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

#property indicator_width5  2

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

#property indicator_label5 "Down AlexSTAL_ZigZagProf_Arrows"

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



#include <AlexSTAL_OutsideBar.mqh>

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

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

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

// >;8G5AB2> 10@>2 4;O @0AG5B0 M:AB@5<C<>2

// =5 <>65B 1KBL <5=LH5 2

input uchar iExtPeriod=12;

// 8=8<0;L=>5 @0AAB>O=85 F5=K <564C A>A54=8<8 ?8:>< 8 2?048=>9 (8=0G5 =5 @538AB@8@C5BAO)

input uchar iMinAmplitude=10;

// 8=8<0;L=>5 42865=85 F5=K 2 ?C=:B0E =0 =C;52>< 10@5 4;O ?5@5@0AG5B0 8=48:0B>@0

input uchar iMinMotion=0;

// A?>;L7>20BL 1>;55 B>G=K9 0;3>@8B< 2KG8A;5=8O ?>@O4:0 D>@<8@>20=8O High/Low 10@0

input bool iUseSmallerTFforEB=true;

input uint  UpLable=159;//;5910 25@E=53> D@0:B0;0

input uint  DnLable=159;//;5910 =86=53> D@0:B0;0

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

uchar ExtPeriod,MinAmplitude,MinMotion;



//---- >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 UpBuffer[],DnBuffer[];

double UpperBuffer[],LowerBuffer[];

double ColorUpperBuffer[],ColorLowerBuffer[];

double HighestBuffer[],LowestBuffer[];



// CD5@ 4;O :MH8@>20=8O 2=5H=53> 10@0

double OBBuffer[];



// @5<O >B:@KB8O ?>A;54=53> >1AG8B0==>3> 10@0

datetime LastBarTime;

// 0I8B0 >B 4>:0G:8 8AB>@88

//int LastBarNum;

// ;O >?B8<870F88 @0AG5B>2

double LastBarLastHigh,LastBarLastLow;

// @5<O ?5@2>3> M:AB@5<C<0 (=5>1E>48<> 4;O 0;3>@8B<0 2=5H=53> 10@0)

datetime TimeFirstExtBar;



// !B0B8G5A:85 ?5@5<5==K5 4;O CA:>@5=8O @0AG5B>2

double MP,MM;



// A?><>30B5;L=0O ?5@5<5==0O

bool DownloadHistory;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   if(iExtPeriod>=2)

      ExtPeriod=iExtPeriod;

   else

      ExtPeriod=2;



   if(iMinAmplitude>=0)

      MinAmplitude=iMinAmplitude;

   else

      MinAmplitude=0;

   MP=NormalizeDouble(MinAmplitude*_Point,_Digits);



   if(iMinMotion>=1)

      MinMotion=iMinMotion;

   else

      MinMotion=1;

   MM=NormalizeDouble(MinMotion*_Point,_Digits);



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

   SetIndexBuffer(0,UpBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,DnBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,UpperBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,ColorUpperBuffer,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(4,LowerBuffer,INDICATOR_DATA);

   SetIndexBuffer(5,ColorLowerBuffer,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(6,HighestBuffer,INDICATOR_DATA);

   SetIndexBuffer(7,LowestBuffer,INDICATOR_DATA);

   SetIndexBuffer(8,OBBuffer,INDICATOR_CALCULATIONS);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,NULL);

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);

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

   ArraySetAsSeries(UpBuffer,true);

   ArraySetAsSeries(DnBuffer,true);

   ArraySetAsSeries(UpperBuffer,true);

   ArraySetAsSeries(LowerBuffer,true);

   ArraySetAsSeries(ColorUpperBuffer,true);

   ArraySetAsSeries(ColorLowerBuffer,true);

   ArraySetAsSeries(LowestBuffer,true);

   ArraySetAsSeries(HighestBuffer,true);

   ArraySetAsSeries(OBBuffer,true);

//---- A8<2>;K 4;O 8=48:0B>@0

   PlotIndexSetInteger(3,PLOT_ARROW,DnLable);

   PlotIndexSetInteger(4,PLOT_ARROW,UpLable);

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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//--- set short name and digits   

   PlotIndexSetString(0,PLOT_LABEL,"ZigZag("+(string)ExtPeriod+","+(string)MinAmplitude+","+(string)MinMotion+","+(string)iUseSmallerTFforEB+")");

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);



   DownloadHistory=true;



//---

   return(0);

  }

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

//|  searching index of the highest bar                              |

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

int iHighest(const double &array[],int depth,int startPos)

  {

   int index=startPos;

   int MaxBar=ArraySize(array)-1;

//--- start index validation

   if((startPos<0) || (startPos>MaxBar))

     {

      Print("Invalid parameter in the function iHighest, startPos =",startPos);

      return -1;

     }

   double max=array[startPos];



//--- start searching

   for(int i=MathMin(startPos+depth-1,MaxBar); i>=startPos; i--)

     {

      if(array[i]>max)

        {

         index=i;

         max=array[i];

        }

     }

//--- return index of the highest bar

   return(index);

  }

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

//|  searching index of the lowest bar                               |

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

int iLowest(const double &array[],int depth,int startPos)

  {

   int index=startPos;

   int MaxBar=ArraySize(array)-1;

//--- start index validation

   if((startPos<0) || (startPos>MaxBar))

     {

      Print("Invalid parameter in the function iLowest, startPos =",startPos);

      return -1;

     }

   double min=array[startPos];



//--- start searching

   for(int i=MathMin(startPos+depth-1,MaxBar); i>=startPos; i--)

     {

      if(array[i]<min)

        {

         index=i;

         min=array[i];

        }

     }

//--- return index of the lowest bar

   return(index);

  }

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

//| 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[])

  {

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   int i;

   for(i=(rates_total-prev_calculated-1); i>=0; i--)

     {

      HighestBuffer[i]= EMPTY_VALUE;

      LowestBuffer[i] = EMPTY_VALUE;

      OBBuffer[i]=EMPTY_VALUE;

     }



//---

// ;>: ?>;=>9 8=8F80;870F88 ?@8 ?>4:0G:5 8AB>@88

// ----------------------------------------------

   int counted_bars=prev_calculated;



// IndicatorCounted() <>65B >1=C;8BAO ?@8 2>AAB0=>2;5=88 A2O78

   if(counted_bars==0)

      DownloadHistory=true;



// 0I8B0 >B 4>:0G:8 ?@>?CI5==>9 8AB>@88 2=CB@L @0AG5B0

/*if ( (counted_bars != 0) && (LastBarNum != 0) )

      if ( (rates_total - iBarShift(NULL, 0, LastBarTime, true)) != LastBarNum )

         DownloadHistory = true;*/



// >;=0O 8=8F80;870F8O

   if(DownloadHistory)

     {

      ArrayInitialize(HighestBuffer,EMPTY_VALUE);

      ArrayInitialize(LowestBuffer,EMPTY_VALUE);

      ArrayInitialize(OBBuffer,EMPTY_VALUE);

      TimeFirstExtBar=0;

      counted_bars= 0;

      LastBarTime = 0;

      //LastBarNum = 0;

      DownloadHistory=false;

     }



// ;>: >?@545;5=8O D>@<8@>20=8O =>2>3> 10@0 (?5@2K9 4>H54H89 B8:)

   bool NewBar=false;

   if(LastBarTime!=time[0])

     {

      NewBar=true;

      LastBarTime=time[0];

      //LastBarNum = rates_total;

      // =>2K9 10@ - >1=C;8< ?5@5<5==K5 4;O >?B8<870F88 @0AG5B>2

      LastBarLastHigh= high[0];

      LastBarLastLow = low[0];

     }



// KG8A;8< =5>1E>48<>5 :>;8G5AB2> 10@>2 4;O ?5@5AG5B0

   int BarsForRecalculation;

   if(counted_bars!=0)

     {

      BarsForRecalculation=rates_total-counted_bars;

      // ;>: >?B8<870F88 @0AG5B>2

      if(!NewBar)

        {

         if((NormalizeDouble(high[0]-LastBarLastHigh,_Digits)>=MM) || (NormalizeDouble(LastBarLastLow-low[0],_Digits)>=MM))

           {

            LastBarLastHigh= high[0];

            LastBarLastLow = low[0];

              } else {

            // 0 40==>< B8:5 @0AG5B ?@>872>48BL =5 1C45<, B0: :0: F5=0 87<5=O;0AL 2=CB@8

            // =C;52>3> 10@0 8;8 65 5Q 87<5=5=8O =5 1K;8 1>;LH5 <8=8<0;L=>3> ?>@>30,

            // 7040==>3> 2 ?5@5<5==>9 MinMotion

            return(rates_total);

           }

        }

        } else {

      BarsForRecalculation=rates_total-ExtPeriod;

     }



//======================================================

//======== >A=>2=>9 F8:; ===============================

//======================================================

   int LET;

   double H,L,Fup,Fdn;

   int lastHighestBufferbar,lastLowestBufferbar;

   double lastHighestBuffer,lastLowestBuffer;

   int m,n; // ;O ?>8A:0 ?>A;54=53> M:AB@5<C<0

   for(i=BarsForRecalculation; i>=0; i--)

     {

      // >8A: ?>A;54=53> M:AB@5<C<0

      // ---------------------------

      lastHighestBuffer= 0;

      lastLowestBuffer = 0;

      lastHighestBufferbar= i;

      lastLowestBufferbar = i;

      LET=0;

      m=0; n=0;

      while(HighestBuffer[lastHighestBufferbar]==EMPTY_VALUE)

        {

         if(lastHighestBufferbar>(rates_total-ExtPeriod))

            break;

         lastHighestBufferbar++;

        }

      lastHighestBuffer=HighestBuffer[lastHighestBufferbar]; //2>7<>6=> =0H;8 ?>A;54=89 ?8:

      while(LowestBuffer[lastLowestBufferbar]==EMPTY_VALUE)

        {

         if(lastLowestBufferbar>(rates_total-ExtPeriod))

            break;

         lastLowestBufferbar++;

        }

      lastLowestBuffer=LowestBuffer[lastLowestBufferbar]; //2>7<>6=> =0H;8 ?>A;54=NN 2?048=C



      if(lastHighestBufferbar<lastLowestBufferbar)

         LET=1;

      if(lastHighestBufferbar>lastLowestBufferbar)

         LET=-1;

      if(lastHighestBufferbar==lastLowestBufferbar)

        {

         //lastHighestBufferbar==lastLowestBufferbar =04> C7=0BL, :0:>9 >48=>G=K9 M:AB@5<C< 1K; ?>A;54=8<:

         m = lastHighestBufferbar;

         n = m;

         while(m==n)

           {

            m++; n++;

            while(HighestBuffer[m]==EMPTY_VALUE)

              {

               if(m>(rates_total-ExtPeriod))

                  break;

               m++;

              } //2>7<>6=> =0H;8 ?>A;54=89 ?8:

            while(LowestBuffer[n]==EMPTY_VALUE)

              {

               if(n>(rates_total-ExtPeriod))

                  break;

               n++;

              } //2>7<>6=> =0H;8 ?>A;54=NN 2?048=C

            if(MathMax(m,n)>(rates_total-ExtPeriod))

               break;

           }

         if(m<n)

            LET=1;       //107>2K9 >BAG5B - ?8:

         else

         if(m>n)

            LET=-1; //107>2K9 >BAG5B - 2?048=0

        }

      // 5A;8 LET==0 - 7=0G8B MB> =0G0;> >BAG5B0 8;8 2 A0<>< =0G0;5 70D8:A8@>20= 2=5H=89 10@ A 2 M:AB@5<C<0<8

      // >=5F ?>8A:0 ?>A;54=53> M:AB@5<C<0

      // ----------------------------------



      //---- @0AA<>B@8< F5=>2K5 M:AB@5<C<K 70 @0AG5B=K9 ?5@8>4:       

      H = high[iHighest(high, ExtPeriod, i)];

      L = low[iLowest(low, ExtPeriod, i)];

      Fup = high[i];

      Fdn = low[i];



      //---- ?@>0=0;878@C5< A8BC0F8N 8 @0AA<>B@8< 2>7<>6=>ABL @538AB@0F88 =>2KE M:AB@5<C<>2: 

      switch(Comb(i,H,L,Fup,Fdn))

        {

         //---- =0 @0AG5B=>< 10@5 ?>B5=F80;L=K9 ?8: (Comb)      

         case 1 :

            switch(LET)

              {

               case 1 :

                  //?@54K4CI89 M:AB@5<C< B>65 ?8:, 2K18@05< 1>;LH89:

                  if(lastHighestBuffer<Fup)

                    {

                     HighestBuffer[lastHighestBufferbar]=EMPTY_VALUE;

                     HighestBuffer[i]=Fup;

                    }

                  break;

               case -1 :

                  if((Fup-lastLowestBuffer)>MP) //?@54K4CI89 M:AB@5<C< - 2?048=0

                  HighestBuffer[i]=Fup;

                  break;

               default :

                  HighestBuffer[i]=Fup;

                  TimeFirstExtBar=time[i]; //0 - 7=0G8B MB> =0G0;> @0AG5B0 

                  break;

              }

            break;



            //---- =0 @0AG5B=>< 10@5 ?>B5=F80;L=0O 2?048=0  (Comb)          

         case -1 :

            switch(LET)

              {

               case 1 :

                  if((lastHighestBuffer-Fdn)>MP) //?@54K4CI89 M:AB@5<C< - ?8:

                  LowestBuffer[i]=Fdn;

                  break;

               case -1 :

                  //?@54K4CI89 M:AB@5<C< B>65 2?048=0, 2K18@05< <5=LHCN:

                  if(lastLowestBuffer>Fdn)

                    {

                     LowestBuffer[lastLowestBufferbar]=EMPTY_VALUE;

                     LowestBuffer[i]=Fdn;

                    }

                  break;

               default :

                  LowestBuffer[i]=Fdn;

                  TimeFirstExtBar=time[i]; //0 - 7=0G8B MB> =0G0;> @0AG5B0 

                  break;

              }

            break;



            //---- =0 @0AG5B=>< 10@5 ?>B5=F80;L=K9 ?8: 8 ?>B5=F80;L=0O 2?048=0 (Comb)        

         case 2 : //?@54?>;>68B5;L=> A=0G0;0 AD>@<8@>20;AO LOW ?>B>< HIGH (1KG89 10@)

            switch(LET)

              {

               case 1 : //?@54K4CI89 M:AB@5<C< - ?8:

                  if((Fup-Fdn)>MP)

                    {

                     if((lastHighestBuffer-Fdn)>MP)

                       {

                        HighestBuffer[i]= Fup;

                        LowestBuffer[i] = Fdn;

                          } else {

                        if(lastHighestBuffer<Fup)

                          {

                           HighestBuffer[lastHighestBufferbar]=EMPTY_VALUE;

                           HighestBuffer[i]=Fup;

                          }

                       }

                       } else {

                     if((lastHighestBuffer-Fdn)>MP)

                        LowestBuffer[i]=Fdn;

                     else 

                       {

                        if(lastHighestBuffer<Fup)

                          {

                           HighestBuffer[lastHighestBufferbar]=EMPTY_VALUE;

                           HighestBuffer[i]=Fup;

                          }

                       }

                    }

                  break;

               case -1 : //?@54K4CI89 M:AB@5<C< - 2?048=0

                  if((Fup-Fdn)>MP)

                    {

                     HighestBuffer[i]=Fup;

                     if((Fdn<lastLowestBuffer) && (time[lastLowestBufferbar]>TimeFirstExtBar))

                       {

                        LowestBuffer[lastLowestBufferbar]=EMPTY_VALUE;

                        LowestBuffer[i]=Fdn;

                       }

                       } else {

                     if((Fup-lastLowestBuffer)>MP)

                        HighestBuffer[i]=Fup;

                     else 

                       {

                        if(lastLowestBuffer>Fdn)

                          {

                           LowestBuffer[lastLowestBufferbar]=EMPTY_VALUE;

                           LowestBuffer[i]=Fdn;

                          }

                       }

                    }

                  break;

               default: break;

              } //switch LET

            break;



            //---- =0 @0AG5B=>< 10@5 ?>B5=F80;L=K9 ?8: 8 ?>B5=F80;L=0O 2?048=0 (Comb)        

         case -2 : //?@54?>;>68B5;L=> A=0G0;0 AD>@<8@>20;AO HIGH ?>B>< LOW (<5425689 10@)

            switch(LET)

              {

               case 1 : //?@54K4CI89 M:AB@5<C< - ?8:

                  if((Fup-Fdn)>MP)

                    {

                     LowestBuffer[i]=Fdn;

                     if((lastHighestBuffer<Fup) && (time[lastHighestBufferbar]>TimeFirstExtBar))

                       {

                        HighestBuffer[lastHighestBufferbar]=EMPTY_VALUE;

                        HighestBuffer[i]=Fup;

                       }

                       } else {

                     if((lastHighestBuffer-Fdn)>MP)

                        LowestBuffer[i]=Fdn;

                     else 

                       {

                        if(lastHighestBuffer<Fup)

                          {

                           HighestBuffer[lastHighestBufferbar]=EMPTY_VALUE;

                           HighestBuffer[i]=Fup;

                          }

                       }

                    }

                  break;

               case -1 : //?@54K4CI89 M:AB@5<C< - 2?048=0

                  if((Fup-Fdn)>MP)

                    {

                     if((Fup-lastLowestBuffer)>MP)

                       {

                        HighestBuffer[i]= Fup;

                        LowestBuffer[i] = Fdn;

                          } else {

                        if(lastLowestBuffer>Fdn)

                          {

                           LowestBuffer[lastLowestBufferbar]=EMPTY_VALUE;

                           LowestBuffer[i]=Fdn;

                          }

                       }

                       } else {

                     if((Fup-lastLowestBuffer)>MP)

                        HighestBuffer[i]=Fup;

                     else 

                       {

                        if(lastLowestBuffer>Fdn)

                          {

                           LowestBuffer[lastLowestBufferbar]=EMPTY_VALUE;

                           LowestBuffer[i]=Fdn;

                          }

                       }

                    }

                  break;

               default: break;

              } //switch LET

            break;



         default: break;

        } // switch (3;02=K9)

     } // for (3;02=K9)

     

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

   int limit,bar,barHH,barHH1,barLL,barLL1;

   double HH,LL,HH1,LL1;



//---- @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-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2



      for(int index=rates_total-1; index>=0 && !IsStopped(); index--)

        {

         UpBuffer[index]=NULL;

         UpperBuffer[index]=NULL;

         //HighestBuffer[index]=NULL;

         

         DnBuffer[index]=NULL;

         LowerBuffer[index]=NULL;

         //LowestBuffer[index]=NULL;

        }

     }

   else

     {

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

     }

     

//---- &8:; @0AGQB0 :0=0;0

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

     {

      barHH=FindFirstExtremum(bar,rates_total,HighestBuffer,HH);

      barHH1=FindFirstExtremum(barHH+1,rates_total,HighestBuffer,HH1);

      

      if(barHH>=0 && barHH1>=0)

        {

         for(int index=barHH1-1; index>barHH && !IsStopped(); index--)

           {

            UpBuffer[index]=HH1;

            UpperBuffer[index]=HH1;

            ColorUpperBuffer[index]=ColorUpperBuffer[index+1];

           }

           

         for(int index=barHH; index>=bar && !IsStopped(); index--)

           {

            UpBuffer[index]=HH;

            UpperBuffer[index]=HH;

            if(HH>HH1) ColorUpperBuffer[index]=0;

            else if(HH<HH1) ColorUpperBuffer[index]=1;

            else ColorUpperBuffer[index]=ColorUpperBuffer[index+1];

           }

        }

        

      barLL=FindFirstExtremum(bar,rates_total,LowestBuffer,LL);

      barLL1=FindFirstExtremum(barLL+1,rates_total,LowestBuffer,LL1);     



      if(barLL>=0 && barLL1>=0)

        {

         for(int index=barLL1-1; index>barLL && !IsStopped(); index--)

           {

            DnBuffer[index]=LL1;

            LowerBuffer[index]=LL1;

            ColorLowerBuffer[index]=ColorLowerBuffer[index+1];

           }

           

         for(int index=barLL; index>=bar && !IsStopped(); index--)

           {

            DnBuffer[index]=LL;

            LowerBuffer[index]=LL;

            if(LL>LL1) ColorLowerBuffer[index]=0;

            else if(LL<LL1) ColorLowerBuffer[index]=1;

            else ColorLowerBuffer[index]=ColorLowerBuffer[index+1];

           }

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

//| DC=:F8O 0=0;870 B5:CI59 A8BC0F88                                 |

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

int Comb(int i,double H,double L,double Fup,double Fdn)

  {

//----

   if(Fup==H && (Fdn==0 || (Fdn>0 && Fdn>L))) return(1);  //=0 @0AG5B=>< 10@5 ?>B5=F80;L=K9 ?8:

   if(Fdn==L && (Fup==0 || (Fup>0 && Fup<H))) return(-1); //=0 @0AG5B=>< 10@5 ?>B5=F80;L=0O 2?048=0

   if(Fdn==L && Fup==H)                                   //=0 @0AG5B=>< 10@5 ?>B5=F80;L=K9 ?8: 8 ?>B5=F80;L=0O 2?048=0 

     {

      OrderFormationBarHighLow OrderFormationHL=OFBError;

      // >?KB:0 =09B8 :5H8@>20==K5 40==K5 2 1CD5@5 OBBuffer[]

      if(OBBuffer[i]==EMPTY_VALUE)

         OrderFormationHL=GetOrderFormationBarHighLow(Symbol(),Period(),i,iUseSmallerTFforEB);

      if(OrderFormationHL!=OFBError)

         OBBuffer[i]=OrderFormationHL;

      else

         OrderFormationHL=(OrderFormationBarHighLow)OBBuffer[i];



      switch(OrderFormationHL)

        {

         case OFBLowHigh:       //?@54?>;>68B5;L=> A=0G0;0 AD>@<8@>20;AO LOW ?>B>< HIGH (1KG89 10@)

            return(2);

            break;

         case OFBHighLow:       //?@54?>;>68B5;L=> A=0G0;0 AD>@<8@>20;AO HIGH ?>B>< LOW (<5425689 10@)

            return(-2);

            break;

        }

     }

//----  

   return(0);           //=0 @0AG5B=>< 10@5 ?CAB>...

  }

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

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

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

int FindFirstExtremum(int StartPos,int Rates_total,double &Array[],double &Extremum)

  {

//----

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

     {

      if(Array[bar] && Array[bar]!=EMPTY_VALUE)

        {

         Extremum=Array[bar];

         return(bar);

         break;

        }

     }

//----

   Extremum=NULL;

   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 ---