ZigZag_NK_Arrows

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

//|                                             ZigZag_NK_Arrows.mq5 |

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

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

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

/*                                                                   |

//Version: Final, November 01, 2008                                  |

Editing:   Nikolay Kositsin  farria@mail.redcom.ru                   |

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

-B>B 20@80=B 8=48:0B>@0 ZigZag, 2 >B;8G85 >B >@838=0;0, =0 :064>< B8:5 

?5@5AG8BK205BAO  B>;L:> =0  5IQ  =5?>AG8B0==KE 10@0E 8 ?>MB><C  A>2A5< 

=5 3@C78B :><?LNB5@.  ><8<> MB>3> 2 40==>< 8=48:0B>@5 >B@8A>2:0 ;8=88

?@>8AE>48B 2 AB8;5 D@0:B0;L=KE 7=0G:>2, 8 ?>MB><C  8=48:0B>@ :>@@5:B=> 

87>1@0605B >4=>2@5<5==> 425 A2>8E 25@I8=K(%09 8 >C) =0 >4=>< 8 B>< 65 

10@5!

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

Depth - MB>  <8=8<0;L=>5 :>;-2>  10@>2, =0 :>B>@><  =5  1C45B  2B>@>3> 

<0:A8<C<0  (<8=8<C<0)  <5=LH5  (1>;LH5)  =0  Deviation  ?8?A>2,    G5< 

?@54K4CI53>, B>  5ABL  @0AE>48BLAO  ZigZag  <>65B  2A5340,  0 AE>48BAO 

(;81> A428=CBLAO  F5;8:><) 1>;LH5,  G5<  =0  Deviation,  ZigZag  <>65B 

B>;L:> ?>A;5 Depth  10@>2. Backstep - MB> <8=8<0;L=>5 :>;8G5AB2> 10@>2 

<564C <0:A8<C<0<8 (<8=8<C<0<8).

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

=48:0B>@  83703     @O4 ;8=89 B@5=40, :>B>@K5 A>548=ONB ACI5AB25==K5

25@H8=K   8   >A=>20=8O  =0  F5=>2><  3@0D8:5.  0@0<5B@  <8=8<0;L=>3>

87<5=5=8O  F5= >?@545;O5B ?@>F5=B, =0 :>B>@K9 F5=0 4>;6=0 ?5@5<5AB8BL,

GB>1K  AD>@<8@>20BL  =>2CN  "83"  8;8  "03"  ;8=8N.  -B>B  8=48:0B>@

>BA58205B  87<5=5=8O =0 0=0;878@C5<>< 3@0D8:5, 25;8G8=0 :>B>@KE <5=LH5

7040==>9.   "0:8<   >1@07><,   783703   >B@0605B  B>;L:>  ACI5AB25==K5

87<5=5=8O.  83703  8A?>;L7C5BAO,  3;02=K<  >1@07><,  4;O >1;53G5==>3>

2>A?@8OB8O  3@0D8:>2,  B0:  :0: >= ?>:07K205B B>;L:> =081>;55 7=0G8<K5

87<5=5=8O  8  @072>@>BK.  "0:65  A  53>  ?><>ILN  <>6=> 2KO2;OBL >;=K

-;;8>B0  8  @07;8G=K5  D83C@K =0 3@0D8:5. 06=> CA2>8BL, GB> ?>A;54=89

>B@57>:   8=48:0B>@0   <>65B   <5=OBLAO  2  7028A8<>AB8  >B  87<5=5=89

0=0;878@C5<KE  40==KE.  -B>  >48=  87 =5<=>38E 8=48:0B>@>2, C :>B>@>3>

87<5=5=85  F5=K  1C<038  <>65B 2K720BL 87<5=5=85 ?@54K4CI53> 7=0G5=8O.

>4>1=0O  A?>A>1=>ABL  :>@@5:B8@>2:8  A2>8E  7=0G5=89  ?>  ?>A;54CNI8<

87<5=5=8O<  F5=K 45;05B 83703 ?@5:@0A=K< 8=AB@C<5=B>< 4;O 0=0;870 C65

?@>87>H54H8E  F5=>2KE  87<5=5=89.  >MB><C =5 A;54C5B ?KB0BLAO A>740BL

B>@3>2CN  A8AB5<C  =0  >A=>25  837030:  >= ;CGH5 ?>4E>48B 4;O 0=0;870

8AB>@8G5A:8E 40==KE, G5< 4;O ?@>3=>78@>20=8O.

 Copyright © 2005, MetaQuotes Software Corp.

 */

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

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

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

#property indicator_buffers 2

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

#property indicator_plots   2

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

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

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

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

#property indicator_type1   DRAW_ARROW

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

#property indicator_color1  clrMagenta

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

#property indicator_width1  4

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

#property indicator_label1  "Up ZigZag_NK_Arrows"

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

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

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

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

#property indicator_type2   DRAW_ARROW

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

#property indicator_color2  clrBlue

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

#property indicator_width2  4

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

#property indicator_label2 "Down ZigZag_NK_Arrows"

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

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

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

input uint ExtDepth=12;

input uint ExtDeviation=5;

input uint ExtBackstep =3;

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

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

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



//---- >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 HighestBuffer[];

double LowestBuffer[];



//---- 1JO2;5=85 ?5@5<5==KE ?0<OB8 4;O ?5@5AGQB0 8=48:0B>@0 B>;L:> =0 =5?>AG8B0==KE 10@0E

int LASTlowpos,LASThighpos;

double LASTlow0,LASTlow1,LASThigh0,LASThigh1,dExtDeviation;



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

int min_rates_total;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

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

   min_rates_total=int(ExtDepth+ExtBackstep);

   dExtDeviation=ExtDeviation*_Point;



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

   SetIndexBuffer(0,LowestBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,HighestBuffer,INDICATOR_DATA);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

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

   PlotIndexSetInteger(0,PLOT_ARROW,DnLable);

   PlotIndexSetInteger(1,PLOT_ARROW,UpLable);

//---- A>740=85 <5B>: 4;O >B>1@065=8O 2 :=5 40==KE

   PlotIndexSetString(0,PLOT_LABEL,"ZigZag Lowest");

   PlotIndexSetString(1,PLOT_LABEL,"ZigZag Highest");

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

   ArraySetAsSeries(LowestBuffer,true);

   ArraySetAsSeries(HighestBuffer,true);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(1,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,"ZigZag (ExtDepth=",

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

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//----   

  }

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

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

   int limit,bar,back,lasthighpos,lastlowpos;

   double curlow,curhigh,lasthigh0=NULL,lastlow0=NULL,lasthigh1,lastlow1,val,res;



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

      lastlow1=-1;

      lasthigh1=-1;

      lastlowpos=-1;

      lasthighpos=-1;

     }

   else

     {

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



      //---- 2>AAB0=02;8205< 7=0G5=8O ?5@5<5==KE

      lastlow0=LASTlow0;

      lasthigh0=LASThigh0;

      lastlow1=LASTlow1;

      lasthigh1=LASThigh1;     

      lastlowpos=LASTlowpos+limit;

      lasthighpos=LASThighpos+limit;

     }



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

     {

      //---- 70?><8=05< 7=0G5=8O ?5@5<5==KE ?5@54 ?@>3>=0<8 =0 B5:CI5< 10@5

      if(rates_total!=prev_calculated && bar==0)

        {

         LASTlow0=lastlow0;

         LASThigh0=lasthigh0;

        }



      //--- low

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

      if(val==lastlow0) val=NULL;

      else 

        { 

         lastlow0=val; 

         if(low[bar]-val>ExtDeviation*_Point) val=NULL;

         else

           {

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

              {

               res=LowestBuffer[bar+back];

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

              }

           }

        } 

      LowestBuffer[bar]=val;

      

      //--- high

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

      if(val==lasthigh0) val=NULL;

      else 

        {

         lasthigh0=val;

         if(val-high[bar]>ExtDeviation*_Point) val=NULL;

         else

           {

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

              {

               res=HighestBuffer[bar+back];

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

              } 

           }

        }

      HighestBuffer[bar]=val;

      

     }



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

   for(bar=limit; bar>=0; bar--)

     {

      //---- 70?><8=05< 7=0G5=8O ?5@5<5==KE ?5@54 ?@>3>=0<8 =0 B5:CI5< 10@5

      if(rates_total!=prev_calculated && !bar)

        {

         LASTlow1=lastlow1;

         LASThigh1=lasthigh1;  

         LASTlowpos=lastlowpos;

         LASThighpos=lasthighpos;

        }



      curlow=LowestBuffer[bar];

      curhigh=HighestBuffer[bar];

      //---

      if(!curlow && !curhigh) continue;

      //---

      if(curhigh)

        {

         if(lasthigh1>0) 

           {

            if(lasthigh1<curhigh) HighestBuffer[lasthighpos]=NULL;

            else HighestBuffer[bar]=NULL;

           }

         //---

         if(lasthigh1<curhigh || lasthigh1<0)

           {

            lasthigh1=curhigh;

            lasthighpos=bar;

           }

         lastlow1=-1;

        }

      //----

      if(curlow)

        {

         if(lastlow1>0)

           {

            if(lastlow1>curlow) LowestBuffer[lastlowpos]=NULL;

            else LowestBuffer[bar]=NULL;

           }

         //---

         if(curlow<lastlow1 || lastlow1<0)

           {

            lastlow1=curlow;

            lastlowpos=bar;

           } 

         lasthigh1=-1;

        }

     }

//----     

   return(rates_total);

  }

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

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