Reply

[Bug + Fix] Exit on Friday not calculated correct

18 replies

geektrader

Customer, bbp_participant, community, 542 replies.

Visit profile

5 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;)

0

geektrader

Customer, bbp_participant, community, 542 replies.

Visit profile

5 years ago #132294

I just saw that this problem is also present with the other exit methods (End of Day Exit, End of Range Exit) as well as for the trading range times. Same bug is there, but since it can be fixed with the exact same method as above, I am sure Mark is smart enough to figure it out on it´s own:)

0

Matusiak Adrian

Customer, bbp_participant, community, 308 replies.

Visit profile

5 years ago #132595

My God…don’t tell me that! I have just builded my big portfolio and all of EAs are using ExitOnFriday !

btn_viewmy_160x33.png

0

geektrader

Customer, bbp_participant, community, 542 replies.

Visit profile

5 years ago #132597

In this case the easiest fix for you, until SQ fixed the bug like I described above, is to set your PC / VPS clock to the exact same time of your brokers MT4 server. Then it will work too.

0

Matusiak Adrian

Customer, bbp_participant, community, 308 replies.

Visit profile

5 years ago #132598

I already thought that when I set “ExitTimeonfriday” to 22:50 it means that trades will be closed at 22:50 of METATRADER SERVER TIME. Am I wrong?

btn_viewmy_160x33.png

0

geektrader

Customer, bbp_participant, community, 542 replies.

Visit profile

5 years ago #132599

Yes, it should do that normally, but as I described above, it´s not implemented correctly in their MT4 code – that´s the actual bug I am talking about. It uses the local clock to check the current day, which is plain wrong and will lead to trades exiting on Friday morning etc.

 

Just set your VPS / PC clock (where you run the EAs from) to the same time of the MT4 server you are trading on and it will work as intended until they´ve fixed the bug in the way I described it above.

0

Matusiak Adrian

Customer, bbp_participant, community, 308 replies.

Visit profile

5 years ago #132600

And yes, I am still available for hiring to find and fix more bugs;)

 

Thumbs up for that! 🙂

 

Great to see someone who “knows the code”!

btn_viewmy_160x33.png

0

mikeyc

Customer, bbp_participant, community, 878 replies.

Visit profile

5 years ago #132630

I just saw that this problem is also present with the other exit methods (End of Day Exit, End of Range Exit) as well as for the trading range times. Same bug is there, but since it can be fixed with the exact same method as above, I am sure Mark is smart enough to figure it out on it´s own:)

 

Has this been fixed with the last SQ3 update?  All my strategies use TimeFrom and TimeTo time ranges to limit signals and this is one of those nasty bugs that make figuring out why other people around the world using different brokers are getting completely different results.

 

To me, this is a major bug and renders all the time based trading features of SQ as useless. 

 

@Mark – if this isn’t fixed can you please create another bug fix release?

 

Thanks,

 

Mike

0

clonex

Customer, bbp_participant, community, contributor, sq-ultimate, 263 replies.

Visit profile

5 years ago #132631

Yes, it should do that normally, but as I described above, it´s not implemented correctly in their MT4 code – that´s the actual bug I am talking about. It uses the local clock to check the current day, which is plain wrong and will lead to trades exiting on Friday morning etc.

Just set your VPS / PC clock (where you run the EAs from) to the same time of the MT4 server you are trading on and it will work as intended until they´ve fixed the bug in the way I described it above.

I have exact same problem too. I im closing trades at friday manually.

Odoslané z SM-G900F pomocou Tapatalku

0

mikeyc

Customer, bbp_participant, community, 878 replies.

Visit profile

5 years ago #132632

I think in the backtester, StrToTime uses the simulated server time (since local time makes no sense in backtesting), so backtesting the EA produced will match SQ.

 

However in demo or live testing, the results will not match if your PC or VPS time is not the same as the broker server time. :wacko:

0

mikeyc

Customer, bbp_participant, community, 878 replies.

Visit profile

5 years ago #132634

I’ve replaced all calls to StrToTime with this function:

 

//+——————————————————————+
datetime TimeStringToDateTime(string time)
{
string date = TimeToStr(TimeCurrent(),TIME_DATE);//”yyyy.mm.dd”
   return (StrToTime(date + ” ” + time));
}

 

Which should work as expected in the backtester and in real trading, always using the broker server date with the specified time.

 

However, having many, many strategies, it is quite some effort to revisit them all and make the required changes in each place…another reason why all this should be in one external mqh file used by every exported EA.

0

Mark Fric

Administrator, sq-ultimate, 3 replies.

Visit profile

5 years ago #132953

sorry it took some time, we just released a quick update with this problem fixed as per mikey suggestion, by using his function TimeStringToDateTime().

 

we’ll make mqh file optional in the new version.

Mark
StrategyQuant architect

0

geektrader

Customer, bbp_participant, community, 542 replies.

Visit profile

5 years ago #132954

@mikey: MQH files are not used by the EA once compiled. MQH is compiled into the actual EX4 code already, just that the function is not in the actual MQL4 code of the MQ4 file. There is no way for a compiled EX4 to use a external MQH once compiled. And since you need to compile before you can trade it, you have to re-compile all EAs still, even with a external MQH file.

 

However, it of course does accelerate the re-compiling still compared to re-export each EA or change the same code in every EA.

0

mikeyc

Customer, bbp_participant, community, 878 replies.

Visit profile

5 years ago #132955

@mikey: MQH files are not used by the EA once compiled. MQH is compiled into the actual EX4 code already, just that the function is not in the actual MQL4 code of the MQ4 file. There is no way for a compiled EX4 to use a external MQH once compiled. And since you need to compile before you can trade it, you have to re-compile all EAs still, even with a external MQH file.

 

However, it of course does accelerate the re-compiling still compared to re-export each EA or change the same code in every EA.

 

@Geektrader

 

You are confusing what I’m saying.  I’ve been coding MetaTrader for over 5 years, so I fully understand MQL4 language and systems.

 

I am saying that common MQ4 functionality should reside in MQH files, so that if a bug is found and fixed I can just recompile all my exported EA’s and not have to export every strategy again from SQ and then compile them.  99% of every EA exported from SQ is the same.  Same code over and over again. Put this common trading code (checking margin, opening a position, closing a position, etc, etc, etc) in ONE file.

 

As it stands, a bug is found in the code exported from SQ, I have to find every strategy, load it, re-export it a compile it.  1000 times.

 

If we use a MQH for all trading functions, if there is a bug in calculating lot size for example, I just have to update code in MQH file and restart MetaTrader.  Compilation of MQ4 files is automatic.  Done.

0

mikeyc

Customer, bbp_participant, community, 878 replies.

Visit profile

5 years ago #132958

I just re-exported a strategy as MQ4 file after saying yes to update.

 

For me the source code is unchanged, lots of calls to StrToTime, which as we know does not work as anyone would expect.

 

Confused, is this fixed in SQ or not?

0

Viewing 15 posts - 1 through 15 (of 19 total)

1 2