high and low of yesterday and their opening time

 

Hello guys. I am quite bad with date and time.

Basically I need to know if yesterday the high was made before the low of the day and the other way round.

From the actual day I need to jump back to yesterday and retrieve the high with its bar shift and low of the day with its bar shift and compare them.

For instance in an uptrend I want to know if the high formed after the low of the day and for a downtrend I want to check if the low of the day formed after the high of the day.

I would really appreciate a little help to get me on track.

 
zen4x:

Hello guys. I am quite bad with date and time.

Basically I need to know if yesterday the high was made before the low of the day and the other way round.

From the actual day I need to jump back to yesterday and retrieve the high with its bar shift and low of the day with its bar shift and compare them.

For instance in an uptrend I want to know if the high formed after the low of the day and for a downtrend I want to check if the low of the day formed after the high of the day.

I would really appreciate a little help to get me on track.


so far I have tried to write this function but to get the first candle of the day in order to go back of N candles (96 candles on M15 to go at the beginning of the previous day)

double getHighAndLow() {

  
   datetime val;
   int h, m, shift;
   int totBars;
   totBars = 200;
   bool found = false;
   for (int i = 0; i <= totBars; i--) {
      val = iTime(Symbol(), Period(), i);
      h = TimeHour(val);
      m = TimeMinute(val);
      //Print("i: " + i + " h: " + h + " m: " + m);
      if (h == 0 && m == 0) {
         //Print("h: " + h + "m: " + m);
         val = iTime(Symbol(), Period(), i);
         h = TimeHour(val);
         m = TimeMinute(val);
         Print("h: " + h + " m: " + m);
         Print(iBarShift(Symbol(), Period(), iTime(Symbol(), Period(), i), false));
         Print(iBars(Symbol(), Period()) );
         break;
      }
   }
   
}

Unfortunately the function does not work. I tried in this way but it seems it's not the right way. How can I determine the bar shift of the first candle of the day and move me back 96 candles to go through the previous day ?
 
Please use this to post code . . . it makes it easier to read.

https://www.mql5.com/en/forum/140334

 
Anything that you do like this is going to cause you headaches when you look back to the weekend . . . yesterday was Sunday, how many bars do you have for Sunday ?
 
 

RaptorUK:
Anything that you do like this is going to cause you headaches when you look back to the weekend . . . yesterday was Sunday, how many bars do you have for Sunday ?

Hei Raptork thank you for answering. You make me think about that problem as well. At the moment the only things that comes to my mind is to use a parameter with a defined value to use for iHighest and iLowest().

I am on the 15m and I usually have 96 candles in a day I cause about 200 candles as lookpback period. I do not have a better solution so far.

 

You can start at midnight and look back until the TimeDayOfWeek() changes . . .

This is midnight: datetime for midnight

 
I am on the 15m and I usually have 96 candles in a day
Don't Assume
datetime yesterdayBeg = iTime(NULL, PERIOD_D1, 1),   // Last trading day
         yesterdayEnd = iTime(NULL, PERIOD_D1, 0)-1; // Or Time[0] - Time[0] % 86400 - 1
int iYestBeg = iBarShift(NULL,0, yesterdayBeg),
    iYestEnd = iBarShift(NULL,0, yesterdayEnd),
    nBarsYest= iYestBeg - iYestEnd + 1,
    iYestHi  = Highest(NULL,0, MODE_HIGH, nBarsYest, iYestEnd),
    iYestLo  =  Lowest(NULL,0, MODE_LOW,  nBarsYest, iYestEnd),
bool HighBeforeLow = iYestHi > iYestLo;
 
WHRoeder:
Don't Assume

Thank you for the code both of you guys. Very nice piece of code, I will keep it.
Reason: