//+------------------------------------------------------------------+
//|                                                   15minHiLow.mq4 |
//|                                           Inthe Name of Almighty |
//|                                          jain.ramzamma@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Inthe Name of Almighty"
#property link      "jain.ramzamma@gmail.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

const string short_name = "HiLo_Trade Levels";
const int NOSHIFT     = 0;
const int CHARTWINDOW = 0;

 extern bool Daily             = True;

extern ENUM_LINE_STYLE E_line_type = STYLE_DASH;
extern ENUM_LINE_STYLE TP_line_type = STYLE_DOT;

         double TodayHigh;
         double TodayLow;

  double Day_Price[][6];
  datetime dopen;
  double  Dh,Dl; 
   int timeshift = 0, timeshifts = 0, beginner = 0;
   int periods ;

   
enum ANCHOR_POINTS {ANCHOR_POINT_ZERO, ANCHOR_POINT_ONE};
enum PIVOT_IDX { DAY_PIVOT, END_PIVOT_IDX};
ENUM_TIMEFRAMES pivotTF[END_PIVOT_IDX] = {PERIOD_M15};
//-------------------------------------------------------- 
int OnInit()
 {
   IndicatorShortName(short_name);
   return(INIT_SUCCEEDED);
 }
  
//-------------------------------------------------------- 
void OnDeinit(const int reason)
 {
//----
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
      ObjectDelete(ObjectName(i));
      
   Comment(" ");
 }

//--------------------------------------------------------- 
bool NewBar(PIVOT_IDX indexToCheck)
{
   static datetime ary_BarZeroValues[END_PIVOT_IDX];
   bool isNewBar = false;
   datetime barZeroTime = iTime(Symbol(),pivotTF[indexToCheck],NOSHIFT);
   datetime lastBarZeroTime = ary_BarZeroValues[indexToCheck];
   if(lastBarZeroTime!=barZeroTime)
   {
      ary_BarZeroValues[indexToCheck] = barZeroTime;
      isNewBar = true;
   }
   return(isNewBar);
}    
//

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[] )
{
   MainRun(rates_total - prev_calculated);
   return(rates_total);
}
void MainRun(int lastbar)
{   
   if(NewBar(DAY_PIVOT))
   {
      DoDailyRates();
   }
   DoDailyLines();
 
}
//=============================GOOD LUCK========================

//==============================================================
void DoDailyRates(void)
{
   dopen=iTime(Symbol(),PERIOD_M15,NOSHIFT);
   ArrayCopyRates(Day_Price,(Symbol()), PERIOD_M15);
     
   TodayHigh = iHigh(Symbol(), PERIOD_M15, 49); //Day_Price[0][3];
   TodayLow =  iLow(Symbol(), PERIOD_M15, 49); //Day_Price[0][2];
   
        Dh = TodayHigh ;
        Dl = TodayLow ; 
     
  
}
void ManageLine(string lName, datetime startTime, double lPrice, datetime endTime,color lColor, ENUM_LINE_STYLE lStyle, int lWidth)
{
   if (ObjectFind(lName) < 0 )
   {
         ObjectCreate(lName, OBJ_TREND, CHARTWINDOW,startTime,lPrice, endTime,lPrice);
         ObjectSet(lName, OBJPROP_COLOR, lColor);
         ObjectSet(lName, OBJPROP_STYLE, lStyle);
         ObjectSet(lName, OBJPROP_WIDTH, lWidth);
         ObjectSet(lName, OBJPROP_RAY,false);
    } else
    {
      ObjectMove(lName,ANCHOR_POINT_ZERO,startTime,lPrice);
      ObjectMove(lName,ANCHOR_POINT_ONE,endTime,lPrice); 
    }
}
void ManageLabel(string lName, string lText, datetime lTime, double lPrice, color lColor)
{
   if(ObjectFind(lName) < 0)
   {
      ObjectCreate(lName, OBJ_TEXT,CHARTWINDOW, lTime, lPrice);
   } else
   {
      ObjectMove(lName, ANCHOR_POINT_ZERO, lTime, lPrice);
   }
   ObjectSetText(lName, lText, 7, "Century Gothic", lColor);
}
void DoDailyLines(void)
{
   if (Daily==true)
   {
      dopen=iTime(Symbol(),PERIOD_D1,0);
      datetime timeTime       = Time[0]+(Time[0]-Time[7]);
      datetime labelTime      = (Time[0]  - (60*60*4) );   //Time[0]+(Time[0]-Time[1])+(240*60)*D_label_pos + timeshift;
                 
         ManageLine("Dh_Line", dopen, Dh,timeTime ,clrGreen,TP_line_type,1);
         ManageLabel("DhLabel",("Dh -Buy:  ")+ DoubleToStr(Dh,2),labelTime, Dh,clrGreen); 
         ManageLine("Dl_Line", dopen, Dl,timeTime ,clrRed,TP_line_type,1);
         ManageLabel("DlLabel",("Dl -Sell:  ")+ DoubleToStr(Dl,2),labelTime, Dl, clrRed);
}

}



