StrToTime setting a time from previous day

 

Hi

I am using StrToTime and I am trying to get it to start from 12:00 on the previous day, I have this but it is not working correctly, can anyone help please:

{t=StrToTime("00:00")-(1440)+(12*3600);} //I am trying to get 00:00 on the day before plus 12 hours to give me 12:00 the previous day

Thanks

Antony

 

I think you want

t=iTime(Symbol(),PERIOD_D1,1)+12*3600 ;

 
tonyjms2005:
I am using StrToTime and I am trying to get it to start from 12:00 on the previous day, I have this but it is not working correctly, can anyone help please:
{t=StrToTime("00:00")-(1440)+(12*3600);} //I am trying to get 00:00 on the day before 
                                         //plus 12 hours to give me 12:00 the previous day

1440 is the number of minutes per day (60*24) not seconds. you wanted 86400.

However, the calculation will compute noon yesterday but yesterday may not be a trading day (weekend, bank holidays) iTime(Symbol(),PERIOD_D1,1) is the previous trading day. Ickyrus' post is what you want if you want 12:00 the previous trading day.

However, on early Monday morning, 1200 Sunday is before trading opens. If you want the last noon trading was open, you need something like:

datetime bod = iTime(Symbol(),PERIOD_D1,0); // Beginning of the day
for (int shift=0; true; shift++){
    datetime noon = iTime(Symbol(),PERIOD_H1, shift);
    if (TimeHour(noon) = 12 && noon < bod) break;
}