ZigZag_NK_Color_Price

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

//|                                        ZigZag_NK_Color_Price.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 8<5==> 2 AB8;5 ZIGZAG,    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!

8:>;09 >A8F8=

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

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.

 */

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

//---- 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.10"

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

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

#property indicator_plots   1

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

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

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

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

#property indicator_type1   DRAW_COLOR_ZIGZAG

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

#property indicator_label1  "ZigZag"

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

#property indicator_color1 clrMagenta,clrBlueViolet

//---- ;8=8O 8=48:0B>@0 - 4;8==K9 ?C=:B8@

#property indicator_style1  STYLE_DASH

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

#property indicator_width1  2

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

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

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

input string  SirName="ZigZag_NK_Color_Price";//5@20O G0ABL 8<5=8 3@0D8G5A:8E >1J5:B>2

input int ExtDepth=12;

input int ExtDeviation=5;

input int ExtBackstep=3;

input bool ShowPrice=true;

input uint nSize=1;

input color UpColor=clrTeal;

input color DnColor=clrRed;

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

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

double HighestBuffer[];

double ColorBuffer[];



//---- 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,LASTColor;

double LASTlow0,LASTlow1,LASThigh0,LASThigh1;

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

int min_rates_total;

string UpLable_,DnLable_;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

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

   min_rates_total=ExtDepth+ExtBackstep;

   UpLable_=SirName+"_Up_";

   DnLable_=SirName+"_Dn_";



//---- ?@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);

   SetIndexBuffer(2,ColorBuffer,INDICATOR_COLOR_INDEX);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);

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

   PlotIndexSetString(0,PLOT_LABEL,"ZigZag_NK_Color");

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

   ArraySetAsSeries(LowestBuffer,true);

   ArraySetAsSeries(HighestBuffer,true);

   ArraySetAsSeries(ColorBuffer,true);

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

   PlotIndexSetInteger(0,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_NK_Color(ExtDepth=",ExtDepth,"ExtDeviation = ",ExtDeviation,"ExtBackstep = ",ExtBackstep,")");

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//----   

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectsDeleteAll(0,SirName,0,OBJ_ARROW_RIGHT_PRICE);

//----

   ChartRedraw(0);

  }

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

//| 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,climit,bar,back,lasthighpos,lastlowpos;

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

   bool Max,Min;

   string stime;



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



      lastlow1=-1;

      lasthigh1=-1;

      lastlowpos=-1;

      lasthighpos=-1;

     }

   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



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

   ArraySetAsSeries(time,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)

        {

         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<=ExtBackstep; back++)

              {

               res=LowestBuffer[bar+back];

               if(res && res>val)

                 {

                  LowestBuffer[bar+back]=NULL;

                  stime=TimeToString(time[bar+back],TIME_DATE|TIME_MINUTES);

                  ObjectDelete(0,DnLable_+stime);

                 }

              }

           }

        }

      LowestBuffer[bar]=val;

      if(val)

        {

         stime=TimeToString(time[bar],TIME_DATE|TIME_MINUTES);

         CreateArrowRightPrice(0,DnLable_+stime,0,time[bar],val,DnColor,nSize);

        }



      //--- 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<=ExtBackstep; back++)

              {

               res=HighestBuffer[bar+back];

               if(res && res<val)

                 {

                  HighestBuffer[bar+back]=NULL;

                  stime=TimeToString(time[bar+back],TIME_DATE|TIME_MINUTES);

                  ObjectDelete(0,UpLable_+stime);

                 }

              }

           }

        }

      HighestBuffer[bar]=val;

      if(val)

        {

         stime=TimeToString(time[bar],TIME_DATE|TIME_MINUTES);

         CreateArrowRightPrice(0,UpLable_+stime,0,time[bar],val,UpColor,nSize);

        }

     }



//---- B>@>9 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)

        {

         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;

               stime=TimeToString(time[lasthighpos],TIME_DATE|TIME_MINUTES);

               ObjectDelete(0,UpLable_+stime);

              }

            else

              {

               HighestBuffer[bar]=NULL;

               stime=TimeToString(time[bar],TIME_DATE|TIME_MINUTES);

               ObjectDelete(0,UpLable_+stime);

              }

           }

         //---

         if(lasthigh1<curhigh || lasthigh1<0)

           {

            lasthigh1=curhigh;

            lasthighpos=bar;

           }

         lastlow1=-1;

        }

      //----

      if(curlow)

        {

         if(lastlow1>0)

           {

            if(lastlow1>curlow)

              {

               LowestBuffer[lastlowpos]=NULL;

               stime=TimeToString(time[lastlowpos],TIME_DATE|TIME_MINUTES);

               ObjectDelete(0,DnLable_+stime);

              }

            else

              {

               LowestBuffer[bar]=NULL;

               stime=TimeToString(time[bar],TIME_DATE|TIME_MINUTES);

               ObjectDelete(0,DnLable_+stime);

              }

           }

         //---

         if(curlow<lastlow1 || lastlow1<0)

           {

            lastlow1=curlow;

            lastlowpos=bar;

           }

         lasthigh1=-1;

        }

     }



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

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

     {

      Max=HighestBuffer[bar];

      Min=LowestBuffer[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;

     }

//---- 

   ChartRedraw(0);

   return(rates_total);

  }

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

//|  !>740=85 B5:AB>2>9 ;591K                                        |

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

void CreateArrowRightPrice //CreateArrowRightPrice(0,"",0,Time,Price,Color,3)

(

 long   chart_id,         // 845=B8D8:0B>@ 3@0D8:0

 string name,             // 8<O >1J5:B0

 int    nwin,             // 8=45:A >:=0

 datetime Time,           // ?>;>65=85 F5=>2>9 <5B:8 ?> 2@5<5=8

 double Price,            // ?>;>65=85 F5=>2>9 <5B:8 ?> 25@B8:0;8

 color  Color,            // F25B B5:AB0

 uint    Size             // @07<5@ H@8DB0

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_ARROW_RIGHT_PRICE,nwin,Time,Price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,Size);

//ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

//----

  }

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

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