Previous Day High

 

I want to find the previous day open, high, low, close. (PERIOD_D1)

I used the code

   datetime open_time = StrToTime("00:00:);
   double shift1 = iBarShift(Symbol(),PERIOD_D1,open_time);
   double open = iOpen(Symbol(),PERIOD_D1,shift1);
   double close = iClose(Symbol(),PERIOD_D1,shift1);
   double high = iHigh(Symbol(),PERIOD_D1,shift1);
   double low = iLow(Symbol(),PERIOD_D1,shift1);
   Print("O: ",open,", H: ",high,", L: ",low,", C: ",close);

 But it returns the very first candle available in the history. How can I get the exact value. I think I'm little bit confused on Shift value.

 
  1. Why use StrToTime
     datetime open_time = TimeCurrent(); // Or Time[0]
    Shift is always an int
    double shift1 = iBarShift(Symbol(),PERIOD_D1,open_time);


  2. Play video
    Please edit your post.
    For large amounts of code, attach it.

  3. Your question is about the previous day. Shift1 will ALWAYS be zero (except on weekly/Monthly charts) So your code
    double open = iOpen(Symbol(),PERIOD_D1,shift1);
    ALWAYS returns TODAY's OHLC, not 'first candle in history.' How to get a time of High/Low of previous day? - MQL4 forum 
Reason: