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
0 Views
0 Downloads
0 Favorites
Fibo Box
ÿþ//+------------------------------------------------------------------+

//|                                                     Fibo Box.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 count_bars= 100;

input double percent_1 = 23.6;

input double percent_2 = 38.2;

input double percent_3 = 50.0;

input double percent_4 = 61.8;



input color           color_0 = clrAquamarine;

input ENUM_LINE_STYLE style_0 = 1;

input int             width_0 = 1;

input bool            fill_0  = true;

input bool            back_0  = true;



input bool Level_1 = true;

input color color_1= clrLightGreen;

input ENUM_LINE_STYLE style_1 = 1;

input int width_1=1;

input bool fill_1 = true;

input bool back_1 = true;



input bool Level_2 = true;

input color color_2= clrLightPink;

input ENUM_LINE_STYLE style_2 = 1;

input int width_2=1;

input bool fill_2 = true;

input bool back_2 = true;



input bool Level_3 = true;

input color color_3= clrLightBlue;

input ENUM_LINE_STYLE style_3 = 1;

input int width_3=1;

input bool fill_3 = true;

input bool back_3 = true;



input bool Level_4 = true;

input color color_4= clrLightGray;

input ENUM_LINE_STYLE style_4 = 1;

input int width_4=1;

input bool fill_4 = true;

input bool back_4 = true;



input color color_5=clrRed;

input ENUM_LINE_STYLE style_5=0;

input int width_5=1;

input bool fill_5=true;



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

  {

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

//|                                                                  |

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

      //---

      datetime time_start=iTime(Symbol(),0,count_bars);

      datetime time_end=iTime(Symbol(),0,0);

      

      double hi = iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,count_bars+1,0));

      double lo = iLow(Symbol(),0,iLowest(Symbol(),0,MODE_LOW,count_bars+1,0));

      

      double level_1 = ((hi-lo)/100)*percent_1;

      double level_2 = ((hi-lo)/100)*percent_2;

      double level_3 = ((hi-lo)/100)*percent_3;

      double level_4 = ((hi-lo)/100)*percent_4;

      

      

      RectangleCreate(0,_name+" 0",0,time_start,hi,time_end,lo,color_0,style_0,width_0,fill_0,back_0);

      ArrowRightPriceCreate(0,_name+" 01",0,time_end,hi,color_5,style_5,width_5,fill_5);

      ArrowRightPriceCreate(0,_name+" 02",0,time_end,lo,color_5,style_5,width_5,fill_5);      



      if(Level_1){

       RectangleCreate(0,_name+" 1",0,time_start,hi,time_end,hi-level_1,color_1,style_1,width_1,fill_1,back_1);

       ArrowRightPriceCreate(0,_name+" 11",0,time_end,hi-level_1,color_5,style_5,width_5,fill_5);      

      }      



      if(Level_2){

       RectangleCreate(0,_name+" 2",0,time_start,hi,time_end,hi-level_2,color_2,style_2,width_2,fill_2,back_2);

       ArrowRightPriceCreate(0,_name+" 22",0,time_end,hi-level_2,color_5,style_5,width_5,fill_5);      

      } 

      

      if(Level_3){

       RectangleCreate(0,_name+" 3",0,time_start,hi,time_end,hi-level_3,color_3,style_3,width_3,fill_3,back_3);

       ArrowRightPriceCreate(0,_name+" 33",0,time_end,hi-level_3,color_5,style_5,width_5,fill_5);      

      }      



      if(Level_4){

       RectangleCreate(0,_name+" 4",0,time_start,lo,time_end,hi-level_4,color_4,style_4,width_4,fill_4,back_4);

       ArrowRightPriceCreate(0,_name+" 44",0,time_end,hi-level_4,color_5,style_5,width_5,fill_5);      

      }        

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

//|                                                                  |

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

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

  }

//----

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

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

  }

//+----

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

     }

  }

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

//| !>7405B ?@02CN F5=>2CN <5B:C                                     | 

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

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

                           const string          name="RightPrice", // 8<O F5=>2>9 <5B:8 

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

                           datetime              time=0,            // 2@5<O B>G:8 ?@82O7:8 

                           double                price=0,           // F5=0 B>G:8 ?@82O7:8 

                           const color           clr=clrRed,        // F25B F5=>2>9 <5B:8 

                           const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L >:09<;ONI59 ;8=88 

                           const int             width=1,           // @07<5@ F5=>2>9 <5B:8 

                           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< F5=>2CN <5B:C 

   if(!ObjectCreate(chart_ID,name,OBJ_ARROW_RIGHT_PRICE,sub_window,time,price))

     {

      Print(__FUNCTION__,

            ": =5 C40;>AL A>740BL ?@02CN F5=>2CN <5B:C! >4 >H81:8 = ",GetLastError());

      return(false);

     }

//--- CAB0=>28< F25B <5B:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- CAB0=>28< AB8;L >:09<;ONI59 ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- CAB0=>28< @07<5@ <5B:8 

   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 <5B:8 <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);

  }

//----



Comments