
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Interesting project. Somehow also seem to have issues running this correctly on a Saturday, unsure how to resolve. Can anyone provide instructions for the proper fix and secondly
Hello Carl, first of all, thanks for your library and detailed guide on how to use time on MQL5.
I allow myself to answer to your question directed to Flying Dutchman because I think I have the same issue. (quite of)
To give you as much information as I can, I am using FTMO Demo server as my strategy tester server.
FTMO Demo server seems to be as of today, 25/04/24, on UTC +3, and if I try to start backtesting on the first of March, it seems to be in UTC +2 and on the 10th of March, it is UTC +3 because of NY change of timezone.
If one was to start the strategy tester on the first of April of this year, the bot would stop instantly, if one was to start it on the prior Friday of this date (29/03), it would run without issues, or it seems like it.
I tried on multiple Monday, and the issue was there everytimes. The issue seems to happen on Sunday, and Monday when I start the strategy tester on them. And the error I get is that it stopped in the initialisation with the alert "setBrokerOffset failed".
Here are the snippets I used from the library :
From my understanding of your explanation, that is enough to make the library to work on any expert advisor.
I may have reached another issue, or maybe just me that do not understand exactly how the script works, it is not correlated with the Sunday/Monday issue but with the DST changes.
As weird as it looks like, starting on 11th of March, which is as you guessed it, the Monday right after NY DST change, my broker seems to already get in UTC +3 (I check a news on Trading view at 12:30 UTC, and compare it to my visual backtest where it says 15:30), so it has already made the change in server time to New York. The strange part is that the OffsetBroker.actOffset is giving me -4, which means UTC+4, which is not what my broker gives, so it switches of one hour too much on the week of NY Sum EU win.
The previous week, everything was fine and FTMO was providing with UTC +2, and it was calculated correctly from what I've seen. And right after the 30th of March, so after the European DST, it switches back to UTC +3, which makes it quite weird to me.
I'm not sure if it's a problem in the code itself, or if I just did not understand what you wrote about the NYsumEUwin, even after reading it 4 times, but I think that may be useful to notice it here, so I can understand what's happening.
Thanks for the information, I will look into this at the weekend.
The cause of this problem is the faulty BoW() macro.
No, I already replaced it with a corrected version.
The problem is the MQL5 function CopyTime().
This:
does not copy the open time of the actual bar which is tC = TimeCurrent(). What ever I tried the last copied time of the h1 bars is Fr. Mar. 29 2024 22:00, the bar of the given time is missing :(
I know MQL5 does not like to look into the future but failing with the present is new to me - or is this a feature?
I am working with MQ demo account on EurUsd.
CopyTime
That is because The last bar of TC is uncompleted bar, that is normal behavior.
Instead, use:
or,
Also, you still have a problem on Saturdays, because BoW is faulty().
Fixed version see #18
Also, you still have a problem on Saturdays, because BoW is faulty().
Not to my understanding.
If I start on Saturday 2024.03.30 00:00:00 the beginning of the week is the previous Sunday 00:00 =>
This is important as the change of DST happens after Su 00:00.
BUT timestamps in the future do not woth with CopyTime() and other CopyXxxx():
I set the beginning of debugging at D'2024.04.01 00:00:00' Monday:
arrTme now runs from:
arrTme[0] = D'2024.03.29 00:00:00'
...
arrTme[22] = D'2024.03.29 22:00:00'
despite the 'highest' time should be tC+3600 = D'2024.04.01 01:00:00'
That means even if the market is already opened at Mon. 00:00 I am trapped as CopyTime() won't fill the array with this timestamp :(
and I cannot get and detect the time gap e.g. from Fr.22:00 to Su. 22:00.
If I start the debugging at Tuesday 2024.04.02 00:00:00 CopyTime is filled by:
arrTme[0] = D'2024.03.29 00:00:00'
...
arrTme[46] = D'2024.04.01 23:00:00'
See, the date (yyyy.mm.dd 00:00:00) when the debugger/tester starts 'lies in the future' and so it won't be part of the array :(
Forum on trading, automated trading systems and testing trading strategies
Libraries: Dealing with time (2) functions
Carl Schreiber, 2024.04.27 21:42
Not to my understanding.
If I start on Saturday 2024.03.30 00:00:00 the beginning of the week is the previous Sunday 00:00 =>
Check this:
Regarding errors with CopyTime(), you can replace CopyTime() to iBarShift().
Please check my lib here
Check this:
Regarding errors with CopyTime(), you can replace CopyTime() to iBarShift().
Please check my lib here
int iB = iBarShift(_Symbol, PERIOD_H1, tC, false);