Author: Yuriy Tokman (YTG)
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
2 Views
0 Downloads
0 Favorites
FiboGrid
ÿþ//+------------------------------------------------------------------+

//|                                                     FiboGrid.mq4 |

//|                                               Yuriy Tokman (YTG) |

//|                       https://www.mql5.com/ru/users/satop/seller |

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

#property copyright "Yuriy Tokman (YTG)"

#property link      "https://www.mql5.com/ru/users/satop/seller"

#property version   "1.00"

#property strict

#property indicator_chart_window



input ENUM_TIMEFRAMES TF = PERIOD_H4;

input int Bar_Count = 50;

input bool Rectangle = true;

input color clrRec = clrAliceBlue;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping



//---

   return(INIT_SUCCEEDED);

  }

void OnDeinit(const int reason) {GetDellName();}

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

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

  {

//---

   double values[7] = {0,1,0.5,0.618,0.382,1.618,-0.618};// 7=0G5=8O ;8=89 C@>2=O

//---

   Comment(TF);

   datetime t_start=0,t_stop=0;

   double center =0,h=0,l=0;

   int ber =0;

   string name_obj = "";

//---

   int limit=rates_total-prev_calculated;

   if(prev_calculated==0)

      limit--;

   else

      limit++;

   if(limit>Bar_Count)

      limit=Bar_Count;

   if(Period() >= TF)

      return 0;



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

     {

      t_start = iTime(Symbol(),TF,i);

      t_stop = t_start + TF*60;

      ber = iBarShift(Symbol(),TF,t_start);

      h = iHigh(Symbol(),TF,ber);

      l = iLow(Symbol(),TF,ber);

      center = l + (h - l)/2 ;



      name_obj = "ytg " + TimeToString(t_start);



      if(NewBar(TF,i))

        {

         if(Rectangle)

            RectangleCreate(0,name_obj,0,t_start,h,t_stop-Period()*60,l,clrRec);

         if(i>0)FiboLevelsCreate(0,name_obj+"Fibo",0,t_stop,h,t_stop-Period()*60,l);

         FiboLevelsSet(7,values,clrRed,STYLE_DOT,1,0,name_obj+"Fibo") ;

        }



     }

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

   return(rates_total);

  }

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

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

//| 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=true,        // 70;82:0 ?@O<>C3>;L=8:0 F25B><

                     const bool            back=true,        // =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(chart_ID,name)!=-1)

      ObjectDelete(chart_ID,name);

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

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< 70;82:8 ?@O<>C3>;L=8:0

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill);

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

  }

//----

//----

void GetDellName(string name_n = "ytg")

  {

   string vName;

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

     {

      vName = ObjectName(i);

      if(StringFind(vName,name_n) !=-1)

         ObjectDelete(vName);

     }

  }

//----+

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

bool NewBar(ENUM_TIMEFRAMES _TF = 0, int i =0)

  {

   static datetime NewTime=0;

   if(NewTime!=iTime(Symbol(),_TF,i))

     {

      NewTime=iTime(Symbol(),_TF,i);

      return(true);

     }

   return(false);

  }

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

//| C>7405B "#@>2=8 $81>=0GG8" ?> 7040==K< :>>@48=0B0<               |

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

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

                      const string          name="FiboLevels", // 8<O >1J5:B0

                      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=clrNONE,        // F25B >1J5:B0

                      const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88 >1J5:B0

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

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

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

                      const bool            ray_right=false,   // ?@>4>;65=85 >1J5:B0 2?@02>

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

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

  {

//--- CAB0=>28< :>>@48=0BK B>G5: ?@82O7:8, 5A;8 >=8 =5 7040=K

   if(ObjectFind(chart_ID,name)!=-1)

      ObjectDelete(chart_ID,name);

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

   ResetLastError();

//--- A>74048< "#@>2=8 $81>=0GG8" ?> 7040==K< :>>@48=0B0<

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

     {

      Print(__FUNCTION__,

            ": =5 C40;>AL A>740BL \"#@>2=8 $81>=0GG8\"! >4 >H81:8 = ",GetLastError());

      return(false);

     }

//--- CAB0=>28< F25B

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- CAB0=>28< AB8;L ;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< 2K45;5=8O >1J5:B0 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);

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?@>4>;65=8O >B>1@065=8O >1J5:B0 2?@02>

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);

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

  }

//----

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

//| 0405B :>;8G5AB2> C@>2=59 8 8E ?0@0<5B@K                         |

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

bool FiboLevelsSet(int             levels,            // :>;8G5AB2> ;8=89 C@>2=O

                   double          &values[],         // 7=0G5=8O ;8=89 C@>2=O

                   color           colors,         // F25B ;8=89 C@>2=O

                   ENUM_LINE_STYLE styles,         // AB8;L ;8=89 C@>2=O

                   int             widths,         // B>;I8=0 ;8=89 C@>2=O

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

                   const string    name="FiboLevels") // 8<O >1J5:B0

  {

//--- ?@>25@8< @07<5@K <0AA82>2

   if(levels!=ArraySize(values))

     {

      Print(__FUNCTION__,": 4;8=0 <0AA820 =5 A>>B25BAB2C5B :>;8G5AB2C C@>2=59, >H81:0!");

      return(false);

     }

//--- CAB0=>28< :>;8G5AB2> C@>2=59

   ObjectSetInteger(chart_ID,name,OBJPROP_LEVELS,levels);

//--- F25B C@>2=O

   ObjectSetInteger(chart_ID,name,OBJPROP_LEVELCOLOR,colors);

//--- AB8;L C@>2=O

   ObjectSetInteger(chart_ID,name,OBJPROP_LEVELSTYLE,styles);

//--- B>;I8=0 C@>2=O

   ObjectSetInteger(chart_ID,name,OBJPROP_LEVELWIDTH,widths);

//--- CAB0=>28< A2>9AB20 C@>2=59 2 F8:;5

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

     {

      //--- 7=0G5=85 C@>2=O

      ObjectSetDouble(chart_ID,name,OBJPROP_LEVELVALUE,i,values[i]);

      //--- >?8A0=85 C@>2=O

      ObjectSetString(chart_ID,name,OBJPROP_LEVELTEXT,i,DoubleToString(100*MathAbs(values[i]),0)+"%");

     }

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