if(StringSubstr(CurrentTime,0,5)==StartTradingTime) TradingIsAllowed=true;
Print CurrentTime and you will see your substr call is bogus.
There can be minutes between ticks in the Asian session; your boolean may not trigger.
Convert your two strings to a datetime and then just compare.
Print CurrentTime and you will see your substr call is bogus.
There can be minutes between ticks in the Asian session; your boolean may not trigger.
Convert your two strings to a datetime and then just compare.
change == to >=
bool CheckTradingTime() { if(StringSubstr(CurrentTime,0,5)>=StartTradingTime) TradingIsAllowed=true; if(StringSubstr(CurrentTime,0,5)>=StopTradingTime) TradingIsAllowed=false; return TradingIsAllowed; }
Simplified bool CheckTradingTime() { return StringSubstr(CurrentTime,0,5)>=StartTradingTime && StringSubstr(CurrentTime,0,5)< StopTradingTime); }
-
When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.
See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)Remember to handle the case where start > end (e.g. 2100 … 0200)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I've been trying to put together a time filter with multiple starts and finishes. the parameter starts and finishes once, but when i repeat the procedure there is no response.