//+------------------------------------------------------------------+
//|                                                 pastDaysHiLo.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//--- input parameters
input color    hiClr = clrBlue;
input color    loClr = clrRed;
input int whichDay = 10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
double hiV = iHigh(_Symbol,PERIOD_D1,whichDay),
       loV = iLow(_Symbol,PERIOD_D1,whichDay);
string hiS = "past " + IntegerToString(whichDay) +"th days HIGH",
       loS = "past " + IntegerToString(whichDay) +"th days LOW";
int OnInit()
  {
ObjectDelete(0,"x");
       ObjectCreate(0, "x", OBJ_HLINE, 0, 0, hiV);
       ObjectSetInteger(0, "x", OBJPROP_COLOR, hiClr);
       ObjectSetInteger(0, "x", OBJPROP_SELECTABLE, false);
       
       ObjectDelete(0, "x1");
       ObjectCreate(0, "x1", OBJ_TEXT, 0, 0, 0);
       ObjectSetString(0, "x1", OBJPROP_TEXT, hiS);
       ObjectSetInteger(0, "x1", OBJPROP_COLOR, hiClr);
       ObjectSetInteger(0, "x1", OBJPROP_SELECTABLE, false);
       
       ObjectDelete(0,"y");
       ObjectCreate(0, "y", OBJ_HLINE, 0, 0, loV);
       ObjectSetInteger(0, "y", OBJPROP_COLOR, loClr);
       ObjectSetInteger(0, "y", OBJPROP_SELECTABLE, false);
   
       ObjectDelete(0, "y1");
       ObjectCreate(0, "y1", OBJ_TEXT, 0, 0, 0);
       ObjectSetString(0, "y1", OBJPROP_TEXT, loS);
       ObjectSetInteger(0, "y1", OBJPROP_COLOR, loClr);
       ObjectSetInteger(0, "y1", OBJPROP_SELECTABLE, false);
   return(INIT_SUCCEEDED);
  }
void OnDeinit(int const reason){
   ObjectsDeleteAll(0, 0, -1);
}
//+------------------------------------------------------------------+
//| 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[])
  {
ObjectMove(0, "x1", 0, Time[0], hiV);
ObjectMove(0, "y1", 0, Time[0], loV);    
//ObjectSetDouble(0, "x1", OBJPROP_PRICE1, hiV);
//ObjectSetInteger(0, "x1", OBJPROP_TIME1, Time[0]);   
   return(rates_total);
  }
//+------------------------------------------------------------------+
