[Bug + Fix] Exit on Friday not calculated correct
18 replies
geektrader
8 years ago #114118
So I´ve been looking at my VPS this evening and noticed there were no more trades on (all my strategies use pending orders only). Looking in the log, I saw it always did add/adjust the new stop orders each 30 minutes like it is supposed to do, but it directly deleted them afterwards each time.
After long debugging of the MQL4 code via “Print”, it came down to the Exit on Friday functionality which always thought it´s already end of Friday and it must delete all pending orders / close all activate trades. The function compares it the following to determine if it´s the right time to exit:
….else if(dow == 5 && TimeCurrent() >= StrToTime(ExitTimeOnFriday)) {
closeActiveOrders();
closePendingOrders();
}
So after printing “TimeCurrent()” and StrToTime(ExitTimeOnFriday)) via the “Print” command, the result was that “TimeCurrent()” was indeed bigger than “ExitTimeOnFriday”, although my “ExitTimeOnFriday” is 23:57, and the MT4 trading server I am using (Global Prime Forex) currently was at Friday 01:34 by that time. So why did this happen? Simple, you can´t pass on “ExitTimeOnFriday” (“23:57”) to the “StrToTime” function like that, because the “StrToTime” function uses the current day of the LOCAL COMPUTER to add a day to the 23:57, while the “TimeCurrent()” function always uses the current day of the MT4 server – and my local computer has a completely different time than the MT4 trading server as it is in another time-zone. So in it´s original-state, the exit on Friday check compares apples with oranges.
To the SQ programmers, the fix for this is this:
….else if(dow == 5 && TimeCurrent() >= StrToTime(DoubleToStr(TimeYear(TimeCurrent()), 0) + “.” + DoubleToStr(TimeMonth(TimeCurrent()), 0) + “.” + DoubleToStr(TimeDay(TimeCurrent()), 0) + ” ” + ExitTimeOnFriday)) {
…..
This will always use the current day of the MT4 server (the same day “TimeCurrent()” returns) to calculate the Friday Exit time instead the day of the local computer. This way the Friday Exit is always accurate and you can set your local computer clock to whatever you want:)
And yes, I am still available for hiring to find and fix more bugs;)
Fluke
8 years ago #133103
Mark, with this new fix you have corrupt any mql4 source code!!! The back test on metatrader go in out of memory!!! please repair it quickly
Matusiak Adrian
8 years ago #133294
BTW,
is this bug already been resolved?
Last update was destroing mql code but does next update fixed corruped file + exit on friday?
Mark Fric
8 years ago #133295
yes, I wrote it in another thread. It is fixed with the last autoupdate.
I’m adding the autoupdate also here in case you haven’t confirmed it. You just have to extract the ZIP archive to the EA Wizard main folder.
Mark
StrategyQuant architect