High/low last bar of yesterday and first bar of today

 
Hi everyone,


I'd like to get the high/ low of 3 candles (last bar of previous days and the first two bars of the current day) for a given timeframe
I'm getting a bit stuck with a piece of mql4 code. I tried  to do it this way:

datetime now  = Time[0],
         bod  = now - now % (24*60*60); // Beginning of the day
int      iBod = iBarShift(NULL,0, bod),
         nH3  = 3 * 60 / Period(), // Number of bars for 3 hours
         iH3  = iBod - nH3 + 1;
if (iH3 <= 0) return;
double HH = iHighest(NULL,0, MODE_HIGH,nH3,iH3)
double LL =  iLowest(NULL,0, MODE_LOW, nH3,iH3) 


But it's just give me the high/low of first three candle of current day.
How  can I achieve what I want, please. 
Regards
 
bodojan468:
Hi everyone,


I'd like to get the high/ low of 3 candles (last bar of previous days and the first two bars of the current day) for a given timeframe
I'm getting a bit stuck with a piece of mql4 code. I tried  to do it this way:



But it's just give me the high/low of first three candle of current day.
How  can I achieve what I want, please. 
Regards

use iBarShift  to get the bar indexes for start and end of the period required 

feed that to iHighest and iLowest to get the bar index of highest and lowest

feed that to iHigh iLow to get the final values

 
bodojan468: But it's just give me the high/low of first three candle of current day.
         nH3  = 3 * 60 / Period(), // Number of bars for 3 hours
         iH3  = iBod - nH3 + 1;

Because that is what you asked for (nH3=3). You want to read [iBod+1 … iBod-2] (2 bars in the current chart.)

if (iBod <= 2) return; // Not yet two bars completed.
double HH = iHighest(NULL,0, MODE_HIGH,3,iBod-2);
          Find bar of the same time one day ago - MQL4 programming forum 2017.10.06
 
Paul Anscombe:

use iBarShift  to get the bar indexes for start and end of the period required 

feed that to iHighest and iLowest to get the bar index of highest and lowest

feed that to iHigh iLow to get the final values

Thanks for your answer.  I just realized I wasn't use good indexes

William Roeder:

Because that is what you asked for (nH3=3). You want to read [iBod+1 … iBod-2] (2 bars in the current chart.)

          Find bar of the same time one day ago - MQL4 programming forum 2017.10.06Thanks Wil

Thanks W. Roeder

I made it like this before I saw  your answer

datetime now  = Time[0],
         bod  = now - now % (24*60*60); 
int      iBod = iBarShift(_Symbol, _Period, bod);
int      nH2  = 2 ,
         iH2  = iBod - nH2 + 1;
if (iH2 <= 0) return;
double HH = High[iHighest(_Symbol, _Period, MODE_HIGH,nH2+1,iH2)];
double LL =  Low[iLowest(_Symbol, _Period, MODE_LOW, nH2+1,iH2)] ;
 
Reason: