Maybe you did take it into account, maybe not: your code for CheckTime() will work at any time between 14:00:00 and 14:59:59, same for 23:00 ~ 24:00. This is because you check only the hour, not the minutes and seconds. Is this what is intended, or do you want it to run only once?
Hi Windmil,
Yeah that's understood and intended - it should then set the variable tradeTime = True // False at those hours you've stated. (Using the variable 'reset' to ensure this happens only once at the start of those hours).
Then as the OnTick() goes through the hours in between it should have 'the green light' to trade (tradeTime = True) if the other conditions are met (the price break out).
It only stopped functioning correctly (after three months of forward testing) once I connected to a VPS.
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20

- 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 All,
Hoping there's something really obvious someone can point out to me.
I have an EA that performs perfectly on backtests, and almost perfect on live trades - except for one key feature.
At 2pm the EA analyses whether the current day price range is within the previous day price range.
That being FALSE (and the current day already broken out before 2pm), it should not allow any trades to occur that day.
The only problem I am getting, is this key feature isn't operating correctly on live trades. So when 1400 comes around for the current day : it will instantly short (if day has broken lower than previous) or long (if broken higher) at 2pm, rather than stopping trades from occurring.
The code makes logical sense to me, and as stated, has performed perfectly on backtests without this issue.
Hope you can help me!
Here is the OnTick function -
And here is the CheckTime() function -
Variables for SessionStart and SessionClose are 14 and 23 respectively, set on initialisation.