Author: Yuriy Tokman (YTG)
0 Views
0 Downloads
0 Favorites
Levels_v2
ÿþ//+------------------------------------------------------------------+

//|                                                          LEV.mq4 |

//|                                               Yuriy Tokman (YTG) |

//|                                               https://ytg.com.ua |

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

#property copyright "Yuriy Tokman (YTG)"

#property link      "https://ytg.com.ua"

#property version   "1.00"

#property strict

#property indicator_chart_window



input int steps = 50;

input int count_line = 21;

input double zone_pip = 5;



input color color1 = clrAqua;

input ENUM_LINE_STYLE style1 =0;

input int width1 = 2;



input color color2 = clrLime;

input ENUM_LINE_STYLE style2 =0;

input int width2 = 1;



input color color3 = clrRed;

input ENUM_LINE_STYLE style3 =0;

input int width3 = 1;



input color color4 = clrBeige;

input ENUM_LINE_STYLE style4 =0;

input int width4 = 1;



input color color5 = clrLime;

input ENUM_LINE_STYLE style5 =0;

input int width5 = 1;



input color color6 = clrRed;

input ENUM_LINE_STYLE style6 =0;

input int width6 = 1;



input color color7 = clrBeige;

input ENUM_LINE_STYLE style7 =0;

input int width7 = 1;



input color color11 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style11 = 1;

input int width11 = 1;

input bool fill11 = true;

input bool back11 = true;



input color color22 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style22 = 1;

input int width22 = 1;

input bool fill22 = true;

input bool back22 = true;



input color color33 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style33 = 1;

input int width33 = 1;

input bool fill33 = true;

input bool back33 = true;



input color color44 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style44 = 1;

input int width44 = 1;

input bool fill44 = true;

input bool back44 = true;



input color color55 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style55= 1;

input int width55 = 1;

input bool fill55 = true;

input bool back55 = true;



input color color66 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style66= 1;

input int width66 = 1;

input bool fill66 = true;

input bool back66 = true;



input color color77 = clrPaleGoldenrod;

input ENUM_LINE_STYLE style77= 1;

input int width77 = 1;

input bool fill77 = true;

input bool back77 = true;





double wrowen = 0;

double next1 =0,next2 =0,next3 =0,next4 =0,next5 =0,next6 =0;

string _name ="";

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   _name =WindowExpertName()+" "+Symbol()+" "+GetNameTF();   

//---

   return(INIT_SUCCEEDED);

  }

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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

//---

   GetDell(_name);

   Comment("");   

  }

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

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

  {

//---

  if(NewBar())

   {

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

//|                                                                  |

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

 datetime time_start = Time[Bars-1];

 datetime time_end = Time[0]+Period()*60*100;



    while(wrowen<Bid)

    wrowen += NormalizeDouble(steps*GetPoint(),Digits);

    

    int cel = count_line/3;

    

    for(int i=0;i<=cel;i++)

     {

      if(i==0){

      HLineCreate(0,_name+"s"+DoubleToStr(i,0),0,NormalizeDouble(wrowen,Digits),color1,style1,width1);

      RectangleCreate(0,_name+"sS"+DoubleToStr(i,0),0,time_start,NormalizeDouble(wrowen+zone_pip*GetPoint(),Digits),

      time_end,NormalizeDouble(wrowen-zone_pip*GetPoint(),Digits),color11,style11,width11,fill11,back11);}      

      

      else

       {

        next1 = wrowen + steps*GetPoint() + steps*3*(i-1)*GetPoint();

        HLineCreate(0,_name+"a"+DoubleToStr(i,0),0,NormalizeDouble(next1,Digits),color2,style2,width2);

        RectangleCreate(0,_name+"aA"+DoubleToStr(i,0),0,time_start,NormalizeDouble(next1+zone_pip*GetPoint(),Digits),time_end,NormalizeDouble(next1-zone_pip*GetPoint(),Digits),color22,style22,width22,fill22,back22);

        

        next2 = wrowen + steps*2*GetPoint() + steps*3*(i-1)*GetPoint();

        HLineCreate(0,_name+"d"+DoubleToStr(i,0),0,NormalizeDouble(next2,Digits),color3,style3,width3);

        RectangleCreate(0,_name+"dD"+DoubleToStr(i,0),0,time_start,NormalizeDouble(next2+zone_pip*GetPoint(),Digits),

        time_end,NormalizeDouble(next2-zone_pip*GetPoint(),Digits),color33,style33,width33,fill33,back33);

        

        next3 = wrowen + steps*3*i*GetPoint();

        HLineCreate(0,_name+"z"+DoubleToStr(i,0),0,NormalizeDouble(next3,Digits),color4,style4,width4);

        RectangleCreate(0,_name+"zZ"+DoubleToStr(i,0),0,time_start,NormalizeDouble(next3+zone_pip*GetPoint(),Digits),

        time_end,NormalizeDouble(next3-zone_pip*GetPoint(),Digits),color44,style44,width44,fill44,back44);

        //----

        next4 = wrowen - steps*GetPoint() - steps*3*(i-1)*GetPoint();

        HLineCreate(0,_name+"v"+DoubleToStr(i,0),0,NormalizeDouble(next4,Digits),color5,style5,width5);

        RectangleCreate(0,_name+"vV"+DoubleToStr(i,0),0,time_start,NormalizeDouble(next4+zone_pip*GetPoint(),Digits),

        time_end,NormalizeDouble(next4-zone_pip*GetPoint(),Digits),color33,style55,width55,fill55,back55);        

        

        next5 = wrowen - steps*2*GetPoint() - steps*3*(i-1)*GetPoint();

        HLineCreate(0,_name+"b"+DoubleToStr(i,0),0,NormalizeDouble(next5,Digits),color6,style6,width6);

        RectangleCreate(0,_name+"bB"+DoubleToStr(i,0),0,time_start,NormalizeDouble(next5+zone_pip*GetPoint(),Digits),

        time_end,NormalizeDouble(next5-zone_pip*GetPoint(),Digits),color66,style66,width66,fill66,back66);        

        

        next6 = wrowen - steps*3*i*GetPoint();

        HLineCreate(0,_name+"n"+DoubleToStr(i,0),0,NormalizeDouble(next6,Digits),color7,style7,width7);

        RectangleCreate(0,_name+"nN"+DoubleToStr(i,0),0,time_start,NormalizeDouble(next6+zone_pip*GetPoint(),Digits),

        time_end,NormalizeDouble(next6-zone_pip*GetPoint(),Digits),color77,style77,width77,fill77,back77);                        

       }

      

      

     }

    

    //Comment(wrowen,"  ",cel);

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

//|                                                                  |

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

    

   }  

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

   return(rates_total);

  }

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

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

bool NewBar(int TF = 0)

  {

   static datetime NewTime=0;

   if(NewTime!=iTime(Symbol(),TF,0))

    {      

     NewTime=iTime(Symbol(),TF,0);

     return(true);

    }

   return(false);     

  }

//----

//----

double GetPoint()

{

 int vres = StringFind(Symbol(),"JPY");

 if (vres == -1) return(0.0001);

 return(0.01);

}

//----

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

//| !>7405B 3>@87>=B0;L=CN ;8=8N                                     | 

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

bool HLineCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                 const string          name="HLine",      // 8<O ;8=88 

                 const int             sub_window=0,      // =><5@ ?>4>:=0 

                 double                price=0,           // F5=0 ;8=88 

                 const color           clr=clrRed,        // F25B ;8=88 

                 const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88 

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

                 const bool            back=false,        // =0 704=5< ?;0=5 

                 const bool            selection=false,    // 2K45;8BL 4;O ?5@5<5I5=89 

                 const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                 const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

 if(ObjectFind(name)>=0)ObjectDelete(name);//5A;8 text C65 A>740= C40;O5< 53>, 2284C A;CG09=>3> ?5@5B0A:820=8O <KHLN

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError(); 

//--- A>74048< 3>@87>=B0;L=CN ;8=8N 

   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL 3>@87>=B0;L=CN ;8=8N! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< F25B ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< AB8;L >B>1@065=8O ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

//--- CAB0=>28< B>;I8=C ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O ;8=88 <KHLN 

//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B 

//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection 

//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

//--- CA?5H=>5 2K?>;=5=85 

   return(true); 

  } 

//---

//+----

void GetDell( string name = "ytg.com.ua")

 {

  string vName;

  for(int i=ObjectsTotal()-1; i>=0;i--)

   {

    vName = ObjectName(i);

    if (StringFind(vName,name) !=-1) ObjectDelete(vName);

   }

 }

//----

string GetNameTF(int TimeFrame=0) {

  if (TimeFrame==0) TimeFrame=Period();

  switch (TimeFrame) {

    case PERIOD_M1:  return("M1");

    case PERIOD_M5:  return("M5");

    case PERIOD_M15: return("M15");

    case PERIOD_M30: return("M30");

    case PERIOD_H1:  return("H1");

    case PERIOD_H4:  return("H4");

    case PERIOD_D1:  return("Daily");

    case PERIOD_W1:  return("Weekly");

    case PERIOD_MN1: return("Monthly");

    default:         return("UnknownPeriod");

  }

}

//---

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

//| C>7405B ?@O<>C3>;L=8: ?> 7040==K< :>>@48=0B0<                    | 

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

bool RectangleCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                     const string          name="Rectangle",  // 8<O ?@O<>C3>;L=8:0 

                     const int             sub_window=0,      // =><5@ ?>4>:=0  

                     datetime              time1=0,           // 2@5<O ?5@2>9 B>G:8 

                     double                price1=0,          // F5=0 ?5@2>9 B>G:8 

                     datetime              time2=0,           // 2@5<O 2B>@>9 B>G:8 

                     double                price2=0,          // F5=0 2B>@>9 B>G:8 

                     const color           clr=clrRed,        // F25B ?@O<>C3>;L=8:0 

                     const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=89 ?@O<>C3>;L=8:0 

                     const int             width=1,           // B>;I8=0 ;8=89 ?@O<>C3>;L=8:0 

                     const bool            fill=false,        // 70;82:0 ?@O<>C3>;L=8:0 F25B>< 

                     const bool            back=false,        // =0 704=5< ?;0=5 

                     const bool            selection=false,    // 2K45;8BL 4;O ?5@5<5I5=89 

                     const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                     const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

 if(ObjectFind(name)>=0)ObjectDelete(name);//5A;8 text C65 A>740= C40;O5< 53>, 2284C A;CG09=>3> ?5@5B0A:820=8O <KHLN

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError(); 

//--- A>74048< ?@O<>C3>;L=8: ?> 7040==K< :>>@48=0B0< 

   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL ?@O<>C3>;L=8:! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< F25B ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< AB8;L ;8=89 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

//--- CAB0=>28< B>;I8=C ;8=89 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< 2K45;5=8O ?@O<>C3>;L=8:0 4;O ?5@5<5I5=89 

//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B 

//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection 

//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

//--- CA?5H=>5 2K?>;=5=85 

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