Thanks WHRoeder, but TimeCurrent() gives time in seconds since 1st Jan 1970, I need to consider things like daylight saving so the difference will be different depending on whether the US is in daylight saving or not?
(sorry, forgot to put the DST in the OP)
Thanks WHRoeder, but TimeCurrent() gives time in seconds since 1st Jan 1970, I need to consider things like daylight saving so the difference will be different depending on whether the US is in daylight saving or not?
(sorry, forgot to put the DST in the OP)
Thanks to @Thirteen's code I was able to knock up the following functions to use in my EA, thought I'd post them here for others to use / verify.
// Get time differece between server time and market time double GetTimeDiff(string strSymbol) { double dblResult = 0; if (strSymbol == "US30.M" || strSymbol == "_US30") { if (IsInstrumentInDST(strSymbol)) { dblResult = -25200; } else { dblResult = -28800; } } return(dblResult); } // Is the market for the sybol in DST bool IsInstrumentInDST(string strSymbol) { bool bolResult = false; int intYear = Year(); if (strSymbol == "US30.M" || strSymbol == "_US30") { int intDSTStartDay = 14 - MathMod((1 + 5*intYear/4), 7); int intDSTEndDay = 7 - MathMod((1 + 5*intYear/4), 7); string strDSTStart = (Year() + ".03." + intDSTStartDay + " 02:00"); string strDSTEnd = (Year() + ".11." + intDSTEndDay + " 02:00"); Output("DST starts on " + strDSTStart + " and ends on " + strDSTEnd); if (TimeCurrent() > StrToTime(strDSTStart) && TimeCurrent() < StrToTime(strDSTEnd)) { Output("For " + strSymbol + " currently DST applies..."); bolResult = true; } } return(bolResult); }
Thanks to @Thirteen's code I was able to knock up the following functions to use in my EA, thought I'd post them here for others to use / verify.
This . . .
double GetTimeDiff
. . . should be a datetime not a double . . same for dblResult
#define HR2400 86400 // 24 * 3600 int TimeOfDay(datetime when){ return( when % HR2400 ); } datetime DateOfDay(datetime when){ return( when - TimeOfDay(when) ); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm working on a system that trades the US30 but I only want it to trade during hours the market is actually open, 09:30 to 16:00, I need something that can do this on current market and historically so I can back test.
Is it possible to return the current time in the market of the instrument?
thanks...