Author: © Tecciztecatl 2016
Price Data Components
Series array that contains the highest prices of each bar
0 Views
0 Downloads
0 Favorites
fibo_bar
ÿþ//+------------------------------------------------------------------+

//|                                                     Fibo_Bar.mq4 |

//|                                                  © Tecciztecatl  |

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

#property copyright     "© Tecciztecatl 2016"

#property link          "https://www.mql5.com/en/users/tecciztecatl"

#property version       "1.00"

#property description   "This indicator draws Fibo levels on the last bar."

#property strict

#property indicator_chart_window

#property indicator_plots 0



extern string comm0="";                      //-     -   -- ---- FIBO ---- --   -     -

extern ENUM_TIMEFRAMES Fibo_Bar=PERIOD_D1;   //Last Bar for Fibo

extern color  fibo_color1=SkyBlue;           //Upper color 

extern color  fibo_color0=LimeGreen;         //Main color 

extern color  fibo_color2=Orange;            //Lower color 

extern ENUM_LINE_STYLE fibo_style=STYLE_DOT; //Style lines

extern int    fibo_width=1;                  //Line Width



double FIBO_levels[];

double FIBO_prices[];

string fibo_txt[];

string fibo_levels0="0 23.6 38.2 50 61.8 76.4 100"; //7+18+24

string fibo_levels1="123.6 138.2 150 161.8 176.4 200 223.6 238.2 250 261.8 276.4 300 323.6 338.2 350 361.8 376.4 400";

string fibo_levels2="-23.6 -38.2 -50 -61.8 -76.4 -100 -123.6 -138.2 -150 -161.8 -176.4 -200 -223.6 -238.2 -250 -261.8 -276.4 -300 -323.6 -338.2 -350 -361.8 -376.4 -400";

string Label_prefix="Fibo_";

int    allBars;

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

   DeleteObjects();

  }

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   if(Fibo_Bar==PERIOD_CURRENT) Fibo_Bar=(ENUM_TIMEFRAMES)Period();

   return(INIT_SUCCEEDED);

  }

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

//| 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(allBars!=iBars(_Symbol,Fibo_Bar))

     {

      allBars=iBars(_Symbol,Fibo_Bar);

      BuildLevels();

     }



   return(rates_total);

  }

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





void BuildLevels()

  {



   double Maximum = iHigh(NULL,Fibo_Bar,1);

   double Minimum = iLow (NULL,Fibo_Bar,1);

   datetime time1 = iTime(NULL,Fibo_Bar,0);

   datetime time2 = iTime(NULL,Fibo_Bar,1);

   string   tf=TFtoStr(Fibo_Bar);



   MakeFibo(fibo_levels0);

   SetFibo(Label_prefix+"f0",time1,Maximum,time2,Minimum,fibo_color0,fibo_width,clrNONE);

   ObjectSetString(0,Label_prefix+"f0",OBJPROP_LEVELTEXT,6,"High last "+tf+" "+ObjectGetFiboDescription(Label_prefix+"f0",6));

   ObjectSetString(0,Label_prefix+"f0",OBJPROP_LEVELTEXT,0,"Low last "+tf+" "+ObjectGetFiboDescription(Label_prefix+"f0",0));



   MakeFibo(fibo_levels1);

   SetFibo(Label_prefix+"f1",time1,Maximum,time2,Minimum,fibo_color1,fibo_width,clrNONE);



   MakeFibo(fibo_levels2);

   SetFibo(Label_prefix+"f2",time1,Maximum,time2,Minimum,fibo_color2,fibo_width,clrNONE);

  }

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

//|                                                                  |

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

void SetFibo(const string   nname,

             datetime        time1,

             double          price1,

             datetime        time2,

             double          price2,

             color           cvet,

             int             wiDth,

             color           cvet_full)

  {

   int levels=ArraySize(FIBO_levels);

   if(ObjectFind(nname)<0)

     {

      ObjectCreate(0,nname,OBJ_FIBO,0,time1,price1,time2,price2);

      ObjectSetInteger(0,nname,OBJPROP_COLOR,cvet_full);

      ObjectSetInteger(0,nname,OBJPROP_STYLE,STYLE_DOT);

      ObjectSetInteger(0,nname,OBJPROP_WIDTH,1);

      ObjectSetInteger(0,nname,OBJPROP_SELECTABLE,false);

      ObjectSetInteger(0,nname,OBJPROP_SELECTED,false);

      ObjectSetInteger(0,nname,OBJPROP_BACK,true);

      ObjectSetInteger(0,nname,OBJPROP_RAY_RIGHT,false);

      ObjectSetInteger(0,nname,OBJPROP_HIDDEN,true);

     }

   else

     {

      ObjectSetInteger(0,nname,OBJPROP_TIME1,time1);

      ObjectSetDouble(0,nname,OBJPROP_PRICE1,price1);

      ObjectSetInteger(0,nname,OBJPROP_TIME2,time2);

      ObjectSetDouble(0,nname,OBJPROP_PRICE2,price2);

     }



   ObjectSetInteger(0,nname,OBJPROP_LEVELS,levels);

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

     {

      FIBO_prices[i]=NormalizeDouble((price1-price2)*FIBO_levels[i]+price2,_Digits);

      ObjectSetDouble(0,nname,OBJPROP_LEVELVALUE,i,FIBO_levels[i]);

      ObjectSetString(0,nname,OBJPROP_LEVELTEXT,i,"("+DoubleToString(100*FIBO_levels[i],1)+") "+DoubleToString(FIBO_prices[i],_Digits));

      ObjectSetInteger(0,nname,OBJPROP_LEVELCOLOR,i,cvet);

      ObjectSetInteger(0,nname,OBJPROP_LEVELWIDTH,i,wiDth);

      ObjectSetInteger(0,nname,OBJPROP_LEVELSTYLE,i,fibo_style);

     }

  }

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

//|                                                                  |

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

string TFtoStr(int p)

{

   if(p==0)p=ChartPeriod(0);

   switch(p)

     {

      case PERIOD_M1:  return ("M1");

      case         2:  return ("M2");

      case         3:  return ("M3");

      case         4:  return ("M4");

      case PERIOD_M5:  return ("M5");

      case         6:  return ("M6");

      case        10:  return ("M10");

      case        12:  return ("M12");

      case PERIOD_M15: return ("M15");

      case        20:  return ("M20");

      case PERIOD_M30: return ("M30");

      case PERIOD_H1:  return ("H1");

      case       120:  return ("H2");

      case       180:  return ("H3");

      case PERIOD_H4:  return ("H4");

      case       360:  return ("H6");

      case       480:  return ("H8");

      case       720:  return ("H12");

      case PERIOD_D1:  return ("D1");

      case PERIOD_W1:  return ("W1");

      case PERIOD_MN1: return ("MN1");

     }

   return(IntegerToString(p));

}

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

//|                                                                  |

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

void MakeFibo(string   text)

  {

   ushort u_sep=StringGetCharacter(" ",0);

   int num_levels=StringSplit(text,u_sep,fibo_txt);

   ArrayResize(FIBO_levels,num_levels);

   ArrayResize(FIBO_prices,num_levels);

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

      FIBO_levels[i]=NormalizeDouble(StrToDouble(fibo_txt[i])/100,3);

   ArraySort(FIBO_levels,WHOLE_ARRAY,0,MODE_ASCEND);

  }

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

//|                                                                  |

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

void DeleteObjects()

  {

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

     {

      string name=ObjectName(i);

      if(StringFind(name,"Fibo_",0)>=0)

         ObjectDelete(0,name);

     }

  }

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

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