tintin92:
Hello,
How to add a day at a datetime variable ?
My code :
Thanks,
Tintin92
The datetime variable keeps seconds since 1970-01-01, so adding 86400 (24*60*60)
would move it a day.
Hello,
How to add a day at a datetime variable ?
My code :
datetime dtDateTest = D'2004.01.01 00:00'; datetime dtDateTestPlusOne; dtDateTestPlusOne = dtDateTest + ??????? ;
Thanks,
Tintin92
The datetime variable keeps seconds since 1970-01-01, so adding 86400 (24*60*60)
would move it a day.
Thanks, it works.
Tintin92
Hello, I was wondering if any one could assist me in completing my code. I need to convert a double to a datetime value.
Code:
datetime Buy_Exp(double numberbars_buy) //** Double to time??
{
return iTime(Symbol,MTF,0) + numberbars_buy*MTF*60; // Format conversion?
}
The purpose of this code is to enable a pending order to expire in a certain number of bars.
I have tried converting both the datetime value and the double to string values and then to add the values and then to re-convert the string back to a datetime value but it was not successful.
Regards,
TimeCurrent() + (PeriodSeconds()*NumberOfBars)
May not be exactly what you want, but gives you something to work with
Ralph Ronnquist: The datetime variable keeps seconds since 1970-01-01, so adding 86400 (24*60*60)
would move it a day.
Except that that may not be a trading day, e.g. week end.
#define HR2400 86400 // PERIOD_D1*60=24*60*60
datetime next_day(datetime when){
int iToday = iBarShift(_Symbol, PERIOD_D1);
if(iToday == 0) return iTime(_Symbol, PERIOD_D1,0) + HR2400;
return iTime(_Symbol, PERIOD_D1, iToday - 1);
}
datetime next_day(datetime when){
int iToday = iBarShift(_Symbol, PERIOD_D1);
if(iToday == 0) return iTime(_Symbol, PERIOD_D1,0) + HR2400;
return iTime(_Symbol, PERIOD_D1, iToday - 1);
}
- GK0135: The purpose of this code is to enable a pending order to expire in a certain number of bars.Can't be done as there may not be a bar during a specific time like the week end, or the Asian session on the M1. "Free-of-Holes" Charts - MQL4 Articles
If you really want "a certain number of bars," compare the iBarShift of the OrderOpenTime - Trade Functions - MQL4 Reference That is how many bars the order has been pending. - datetime Buy_Exp(double numberbars_buy) //** Double to time??I have tried converting both the datetime value and the double to string values and then to add the values and then to re-convert the string back to a datetime value but it was not successful.
{
return iTime(Symbol,MTF,0) + numberbars_buy*MTF*60; // Format conversion?
}"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
Are there a global variables called Symbol and MTF? Why is numberbars_buy a double and not an int?This compiles just fine void OnStart(){
#define MTF PERIOD_H1
#define numberbars_buy 5
datetime res=iTime(_Symbol,MTF,0) + numberbars_buy*MTF*60;
}
datetime t=Time[12]; t=t+( 60*59 ); // add 59 minutes t=t+( 60*60*3 ); // add 3 hours t=t+( 60*60*24 ); // add 24 hours - 1 day
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
How to add a day at a datetime variable ?
My code :
Thanks,
Tintin92