//+------------------------------------------------------------------+
//|                                                         1455.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//| http://www.forexfactory.com/sayedtaha                            |
//+------------------------------------------------------------------+
#property copyright "sayedtaha"
#property link      "http://www.forexfactory.com/sayedtaha"
#property version   "1.00"
#property strict
#property indicator_chart_window
extern ENUM_TIMEFRAMES  drawingPeriod = PERIOD_D1; // period in minuts
extern int barsToSearch = 5; // How many bars back to look for a high bar
extern color  levelslinecolor = DodgerBlue; // levels line color for support
extern ENUM_LINE_STYLE levelslinetype = STYLE_DOT ; // levels line type
extern int levels_line_width=1;//levels line width
const int ZEROSTART   = 0;
const int NOSHIFT     = 0;
const int CHARTWINDOW = 0;
const int NOTIME      = 0;
const string indicatorHighLineName = "IndicatorHighLineName";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
 {
   //--- indicator buffers mapping
   if( thereIsANewBar(drawingPeriod) ) // set the current bar zero time
    {
      int highBar = iHighest(Symbol(),drawingPeriod,MODE_HIGH,barsToSearch,ZEROSTART);  // find the high bar
      double highPrice = iHigh(Symbol(),drawingPeriod,highBar);
      drawLine(indicatorHighLineName, highPrice);  // draw the horizontal line
      Print("High Price = ", DoubleToStr(highPrice,Digits));
    }
   //---
   return(INIT_SUCCEEDED);
 }
void OnDeinit(const int reason)
 {
   //---- TODO
   ObjectDelete(indicatorHighLineName);
   //----
 }
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( thereIsANewBar(drawingPeriod) )  // set the current bar zero time
    {
      int highBar = iHighest(Symbol(),drawingPeriod,MODE_HIGH,barsToSearch,ZEROSTART);  // find the high bar
      double highPrice = iHigh(Symbol(),drawingPeriod,highBar);  // Find the high bar's high price
      drawLine(indicatorHighLineName, highPrice);  // draw the horizontal line
    }
   return(rates_total);
 }
bool thereIsANewBar(ENUM_TIMEFRAMES workingPeriod)
 {
   static datetime barZeroTime = 0;
   bool newBar = false;
   if (barZeroTime != iTime(Symbol(),workingPeriod, NOSHIFT))
    {
      newBar = true;
      barZeroTime = iTime(Symbol(),workingPeriod, NOSHIFT);
    }
   return(newBar);
 }
void drawLine( string objName, double highPrice)
 {
   long chartID = ChartID();
   ObjectCreate(chartID,objName,OBJ_HLINE,CHARTWINDOW,NOTIME,highPrice);
   ObjectSetInteger(chartID,objName,OBJPROP_COLOR,levelslinecolor);
   ObjectSetInteger(chartID,objName,OBJPROP_STYLE,levelslinetype);
   ObjectSetInteger(chartID,objName,OBJPROP_WIDTH,levels_line_width);
   ObjectSetInteger(chartID,objName,OBJPROP_BACK,true);
   ObjectSetInteger(chartID,objName,OBJPROP_SELECTABLE,true);
   ObjectSetInteger(chartID,objName,OBJPROP_HIDDEN,false);
 }