set 12:00 am
This will give you midnight:
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
HTH
Thank you
I added another code to find the highest value in X candles. but I can not make it work. The code does not have errors.
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
datetime some_time= midnight;
int shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
double val;
//--- calculating the highest value on the 20 consecutive bars in the range
//--- from the 4th to the 23rd index inclusive on the current chart
int val_index=iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,shift,1+i);
if(val_index!=-1) val=High[val_index];
else PrintFormat("Error in call iHighest. Error code=%d",GetLastError());
//Indicator Buffer 1
if( val )
{
Buffer1[i] = High[i];
}
I'm trying to change this value to read 2 or more days, but if I enter a higher figure to 172,800 the result value does not change.
1 day = 86400
2 day = 172800
3 day = 345600
How could I solve?
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
datetime some_time= midnight;
int shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
I'm trying to change this value to read 2 or more days, but if I enter a higher figure to 172,800 the result value does not change.
1 day = 86400
2 day = 172800
3 day = 345600
How could I solve?
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
datetime some_time= midnight;
int shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
% is giving you the remainder after division.
Just add 86400 to the midnight value for midnight tomorrow:
datetime midnight = when - (when % 86400); // midnight today
midnight = midnight + 86400; // midnight tomorrow
taking as an example the code iBarShift, how can I change the date in the hour 12:00 AM of the current day without having to continually change the day?
int shift=iBarShift(Symbol(),PERIOD_CURRENT,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);