Round_Levels_XN

Author: Copyright © 2007, Martes
0 Views
0 Downloads
0 Favorites
Round_Levels_XN
ÿþ//+------------------------------------------------------------------+

//|                                              Round_Levels_XN.mq5 |

//|                                         Copyright © 2007, Martes |

//|               http://championship.mql4.com/2007/ru/users/Martes/ |

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

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

#property copyright "Copyright © 2007, Martes"

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

#property link      "http://championship.mql4.com/2007/ru/users/Martes/"



#property description "This code draws 4 horizontal lines with 00 at the end of"

#property description "the vertical coordinate (price). This 4 horizontal lines with"

#property description "this property are closest to current price."



//---- >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=> =>;L 1CD5@>2

#property indicator_buffers 0

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

#property indicator_plots   0

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

//| 5@5G8A;5=85 4;O B>;I8=K C@>2=O                |

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

enum ENUM_WIDTH //"8? :>=AB0=BK

  {

   w_1 = 1,   //1

   w_2,       //2

   w_3,       //3

   w_4,       //4

   w_5        //5

  };

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

//| 5@5G8A;5=85 4;O AB8;O ;8=88 C@>2=O            |

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

enum STYLE

  {

   SOLID_,//!?;>H=0O ;8=8O

   DASH_,//(B@8E>20O ;8=8O

   DOT_,//C=:B8@=0O ;8=8O

   DASHDOT_,//(B@8E-?C=:B8@=0O ;8=8O

   DASHDOTDOT_   //(B@8E-?C=:B8@=0O ;8=8O A 42>9=K<8 B>G:0<8

  };

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

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

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

input uint ZeroCount=2;                      //:>;8G5AB2> =C;59 4;O >:@C3;5=8O

input string levels_sirname="Price_Level_1"; //;5910 C@>2=59

input uint XNCount=3;                        //:>;8G5AB2> ?>2B>@>2 2A53> =01>@0 ;8=89

//----

input color Up_level_color2=clrBlue;    //F25B 2B>@>3> 25@E=53> C@>2=O

input STYLE Up_level_style2=SOLID_;     //AB8;L 2B>@>3> 25@E=53> C@>2=O

input ENUM_WIDTH Up_level_width2=w_3;   //B>;I8=0 2B>@>3> 25@E=53> C@>2=O

//----

input color Up_level_color1=clrLime;    //F25B ?5@2>3> 25@E=53> C@>2=O

input STYLE Up_level_style1=SOLID_;     //AB8;L ?5@2>3> 25@E=53> C@>2=O

input ENUM_WIDTH Up_level_width1=w_3;   //B>;I8=0 ?5@2>3> 25@E=53> C@>2=O

//----

input color Dn_level_color1=clrRed;     //F25B ?5@2>3> =86=53> C@>2=O

input STYLE Dn_level_style1=SOLID_;     //AB8;L ?5@2>3> =86=53> C@>2=O

input ENUM_WIDTH Dn_level_width1=w_3;   //B>;I8=0 ?5@2>3> =86=53> C@>2=O

//----

input color Dn_level_color2=clrMagenta; //F25B 2B>@>3> =86=53> C@>2=O

input STYLE Dn_level_style2=SOLID_;     //AB8;L 2B>@>3> =86=53> C@>2=O

input ENUM_WIDTH Dn_level_width2=w_3;   //B>;I8=0 2B>@>3> =86=53> C@>2=O

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

double VShift;

int Normalize;

string UpName2[],UpName1[],DnName1[],DnName2[];

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

//|  !>740=85 3>@87>=B0;L=>9 ;8=88                                   |

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

void CreateHline

(

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

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

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

 double   price,         // F5=0 3>@87>=B0;L=>3> C@>2=O

 color    Color,         // F25B ;8=88

 int      style,         // AB8;L ;8=88

 int      width,         // B>;I8=0 ;8=88

 bool     background,// D>=>2>5 >B>1@065=85 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_HLINE,nwin,0,price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,background);

   ObjectSetInteger(chart_id,name,OBJPROP_RAY,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true);

   ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true);

//----

  }

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

//|  5@5CAB0=>2:0 3>@87>=B0;L=>9 ;8=88                              |

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

void SetHline

(

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

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

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

 double   price,         // F5=0 3>@87>=B0;L=>3> C@>2=O

 color    Color,         // F25B ;8=88

 int      style,         // AB8;L ;8=88

 int      width,         // B>;I8=0 ;8=88

 bool     background,// D>=>2>5 >B>1@065=85 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateHline(chart_id,name,nwin,price,Color,style,width,background,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,0,price);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

     }

//----

  }

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//----

//---- @0A?@545;5=85 ?0<OB8 ?>4 <0AA82K ?5@5<5==KE  

   ArrayResize(UpName2,XNCount+1);

   ArrayResize(UpName1,XNCount+1);

   ArrayResize(DnName1,XNCount+1);

   ArrayResize(DnName2,XNCount+1);

   for(int count=0;  count<int(XNCount+1); count++)

     {

      UpName2[count]=levels_sirname+"_UpName2."+string(count);

      UpName1[count]=levels_sirname+"_UpName1."+string(count);

      DnName1[count]=levels_sirname+"_DnName1."+string(count);

      DnName2[count]=levels_sirname+"_DnName2."+string(count);

     }

   Normalize=_Digits-int(ZeroCount);

   VShift=_Point*MathPow(10,ZeroCount);

//----

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//---- C40;O5< C@>25=8

   for(int count=0;  count<int(XNCount+1); count++)

     {

      ObjectDelete(0,UpName2[count]);

      ObjectDelete(0,UpName1[count]);

      ObjectDelete(0,DnName1[count]);

      ObjectDelete(0,DnName2[count]);

     }

//----

   ChartRedraw(0);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(

                const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                const datetime &time[],

                const double &open[],

                const double& high[],     // F5=>2>9 <0AA82 <0:A8<C<>2 F5=K 4;O @0AGQB0 8=48:0B>@0

                const double& low[],      // F5=>2>9 <0AA82 <8=8<C<>2 F5=K  4;O @0AGQB0 8=48:0B>@0

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[]

                )

  {

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

   double UpLevel2,UpLevel1,DnLevel2;

   static double DnLevel1;

//----

   DnLevel1=NormalizeDouble(close[rates_total-1],_Digits-ZeroCount);   

   UpLevel1=DnLevel1+VShift;

   UpLevel2=UpLevel1+VShift;

   DnLevel2=DnLevel1-VShift;



   for(int count=0;  count<int(XNCount+1); count++)

     {

      SetHline(0,UpName2[count],0,UpLevel2+2*count*VShift,Up_level_color2,Up_level_style2,Up_level_width2,false,UpName1[count]);

      SetHline(0,UpName1[count],0,UpLevel1+2*count*VShift,Up_level_color1,Up_level_style1,Up_level_width1,false,UpName1[count]);

      SetHline(0,DnName1[count],0,DnLevel1-2*count*VShift,Dn_level_color1,Dn_level_style1,Dn_level_width1,false,DnName1[count]);

      SetHline(0,DnName2[count],0,DnLevel2-2*count*VShift,Dn_level_color2,Dn_level_style2,Dn_level_width2,false,DnName2[count]);

     }

//----

   ChartRedraw(0);

   return(rates_total);

  }

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

Comments