How to fetch hourly chart high low timing

 

Hi, here i explain this. 

current hourly bar is 8:00

Now I need last hourly bar which is 7:00 high low timing in 1 minute time frame.  I mean,  there are 60 minutes for 1 hour candle. So I need a formula which will count that 7:00 hour high low timing in 1 minute chart from 7:00 to 7:59.

I know about iLowest, iHighest function. But searching it in particular range in different time frame, i dont know how to do it.

Following code able to fetch last hourly bar opening time & its low & high point.

int start()
{
double low = iLow(NULL,PERIOD_H1,1);        // Last candles low 
double high = iHigh(NULL,PERIOD_H1,1);      // Last candles high

int lowT = iLowest(NULL,PERIOD_H1,MODE_LOW,1,1);        // Fetching Last candles timing as start point for the search in 1 minute chart.

datetime LT = iTime(NULL,PERIOD_H1,lowT);

return(0);

}

 Please help.

Thank you. 

 
cashcube: But searching it in particular range in different time frame, i dont know how to do it.
datetime now = ...;
datetime lastHour  = now - 60 * Period_M1; // 60 minutes ago.
int      iLastM1   = iBarShift(NULL, PERIOD_M1, lastHour);
int      iNowM1    = iBarShift(NULL, PERIOD_M1, now);
int      iM1LL     = iLowest(NULL, PERIOD_M1, MODE_LOW, iLastM1 - iNowM1, iNowM1+1);
Print("Lowest price last hour occurred during minute bar ", iTime(NULL, PERIOD_M1, iM1LL);

iLastM1 - iNowM1 doesn't assume that there are 60 M1 bars during that hour.

also useful:

bool  is_leap_year(dateime when){
   uint year = TimeYear(when);return year%4==0 && (year%100!=0 || year%400==0);}
static int     HR2400 = PERIOD_D1 * 60; // 86400 = 24 * 3600
SECONDS  time(datetime when=0){
   return ((when == 0) ? TimeCurrent() : when) % HR2400 );           }
datetime date(datetime when=0){
   return ((when == 0) ? TimeCurrent() : when) - time(when) );  }
datetime tomorrow( datetime when=0){
   return date((when == 0) ? TimeCurrent() : when) + HR2400);     }
/// Returns previous trading day.
datetime yesterday(datetime when=0) /**< Previous relative to when.*/{
   if(when==0) when = TimeCurrent();
   download_history(PERIOD_D1, __FUNCTION__); // Make sure I have daily history.
   INDEX    iD1   = iBarShift(NULL, PERIOD_D1,  when);   // Find today.
   return iTime(NULL, PERIOD_D1, iD1 + 1);               // Return yesterday.
}
 
WHRoeder:

iLastM1 - iNowM1 doesn't assume that there are 60 M1 bars during that hour.

also useful:

Hi, Using your first code, in following way,

datetime now = TimeCurrent();
datetime lastHour  = now - 60 * PERIOD_M1; // 60 minutes ago.
int      iLastM1   = iBarShift(NULL, PERIOD_M1, lastHour);
int      iNowM1    = iBarShift(NULL, PERIOD_M1, now);
int      iM1LL     = iLowest(NULL, PERIOD_M1, MODE_LOW, iLastM1 - iNowM1, iNowM1+1);
Print("Lowest price last hour occurred during minute bar ", iTime(NULL, PERIOD_M1, iM1LL));

 It showing only previous 1 minute bar timing. If current time is 11:24, then its printing 11:23

So i updated the code little,

double low = iLow(NULL,PERIOD_H1,1);        // Last candles low 
double high = iHigh(NULL,PERIOD_H1,1);      // Last candles high

int lowT = iLowest(NULL,PERIOD_H1,MODE_LOW,1,0);     // Pointing current hour
datetime LT = iTime(NULL,PERIOD_H1,lowT);

datetime now = LT;
datetime lastHour  = now - 60 * PERIOD_M1; // 60 minutes ago.
int      iLastM1   = iBarShift(NULL, PERIOD_M1, lastHour);
int      iNowM1    = iBarShift(NULL, PERIOD_M1, now);
int      iM1LL     = iLowest(NULL, PERIOD_M1, MODE_LOW, iLastM1 - iNowM1, iNowM1+1);
Print("Lowest price last hour occurred during minute bar ", iTime(NULL, PERIOD_M1, iM1LL));

Now its showing if current hourly is 11:00, its showing 10:59. Somehow iLowest fails to search it seems.

Actual low formed at 10:49.

 

Just to clarify what you want to achieve:

If the low of the previous H1 bar was 1.0050, you want to find out exactly which M1 bar that happened on.

Is that correct? 

If so, this basic framework should do it (you'll need to deal with missing history still)

   datetime LastHr = iTime(NULL,PERIOD_H1,1),
            ThisHr = iTime(NULL,PERIOD_H1,0);
   int      Start  = iBarShift(NULL,PERIOD_M1,ThisHr)+1,
            Count  = iBarShift(NULL,PERIOD_M1,LastHr)-Start+1,
            Index  = iLowest(NULL,PERIOD_M1,MODE_LOW,Count,Start);
   datetime When   = iTime(NULL,PERIOD_M1,Index);
   printf("The low of the %s H1 bar happened at %s",TimeToStr(LastHr,TIME_MINUTES),TimeToStr(When,TIME_MINUTES));
 
datetime lastHour  = now - 60 * PERIOD_M1; // 60 minutes ago.
datetime lastHour  = now - 60 * PERIOD_H1; // 60 minutes ago.
 
honest_knave:

Just to clarify what you want to achieve:

If the low of the previous H1 bar was 1.0050, you want to find out exactly which M1 bar that happened on.

Is that correct? 

If so, this basic framework should do it (you'll need to deal with missing history still)

 

Thank you very much for the code. It worked! 

About missing history, thanks to Mr. WHRoeder, I can use his 2nd part of the code to download the data. 

It will be an indicator on current bar so, i'm not sure history will be needed or not. 

Reason: