This will give you midnight:
datetime when = TimeCurrent();
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
datetime midnight = when - (when % 86400); // there are 86400 seconds in a day
HTH
Great work!
Thank you
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 when = TimeCurrent();
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];
}
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 solved thanks
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 when = TimeCurrent();
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);
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);
fly7680:
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 when = TimeCurrent();
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);
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 when = TimeCurrent();
datetime midnight = when - (when % 86400); // midnight today
midnight = midnight + 86400; // midnight tomorrow
datetime midnight = when - (when % 86400); // midnight today
midnight = midnight + 86400; // midnight tomorrow
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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);