![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
I made deeper research.
MT generates ticks correctly if there are 5 min bars covering the testing area.
In my case, the available 5 min bars are from 2015.04.01. When I start the script after the 1st of April, MT tester generates the ticks correctly. However, it fails on data before April 1st.
It looks like it generates the tick prices more or less well, but the the tick time always ends 35 or 25 seconds before the bar closing time.
The tester doesn't complain that there is no M5 bars for the testing period. It composes some bars probably from the higher time frame. It is interesting that this issue was reported to me several days ago and I was not able to reproduce it since today.
This is one more issue I have to workaround in my code.
Here is another case.
void OnTick()
{
MqlTick mqlTick;
SymbolInfoTick(_Symbol,mqlTick);
string time = TimeToString(mqlTick.time, TIME_DATE|TIME_MINUTES|TIME_SECONDS);
MqlRates rates[];
ArraySetAsSeries(rates,false);
int copied=CopyRates(_Symbol,_Period,0,1,rates);
PrintFormat("Time: %s, Tick volume: %d, Real volume: %d, MqlTick volume: %d",
time, rates[0].tick_volume, rates[0].real_volume, mqlTick.volume);
}
I print the tick time and volume on MT5.
The backtester generates thousands of ticks but not the tick time. Even the time on the chart popup panel is wrong. The seconds stay zero hence the bar is generated. We have 12145 ticks for that bar, but the time is not changed at all.
so this would mean the tester is useless for EA's that rely on ticks since they are artificially created and do not reflect true market conditions.
probably this is the reason a trailingstop can be tuned to the tick generating algo resulting in unreal profits.
for more reliable testing then the only thing left for EA's would be to use OHLC data only, but then again, i wonder how the high and lows come into being since they are also tick related.
maybe the tick generating mechanism only generates an X number of ticks between high and low for the last bar.
the fact that time does not change is kinda logical otherwise the algo has to divide the number of ticks generated over the time span of the bar and generate them in a way they exactly match in between the period.
thanks for bringing this to our attention.
MT tester should generate the tick prices as well as the tick time according to this documentation: https://www.mql5.com/en/articles/75
I've working on backtetsing algorithms for about 15 years. It is interesting that the first algorithm I "invented" on about the far 2002 was almost 1:1 to the algorithm MT uses now. I called that algorithm "shortest interpolation". The name comes from the fact that this is the shortest trajectory passing through the 4 reference points: Open, High/Low and Close. Unfortunately many users of my product reported false backtests showing unrealistically high results. Later on I implemented 4 other algorithms for bar interpolation.
This specific implementation of MT is not totally wrong, if you know how it works and how to go round the pitfalls.
My expert is 6000 lines long where 4000 lines fight with the different issues.
I workaround this tick time issue by "closing" the previous bars at the first tick of the new bar and immediately after that I rise an open event. The problem is that I cannot prevent the Close-Open gap, but it is a way better than leaving the positions open for forever (since the ticks time never go to the end of the bar).
Here is another case.
void OnTick()
{
MqlTick mqlTick;
SymbolInfoTick(_Symbol,mqlTick);
string time = TimeToString(mqlTick.time, TIME_DATE|TIME_MINUTES|TIME_SECONDS);
MqlRates rates[];
ArraySetAsSeries(rates,false);
int copied=CopyRates(_Symbol,_Period,0,1,rates);
PrintFormat("Time: %s, Tick volume: %d, Real volume: %d, MqlTick volume: %d",
time, rates[0].tick_volume, rates[0].real_volume, mqlTick.volume);
}
I print the tick time and volume on MT5.
The backtester generates thousands of ticks but not the tick time. Even the time on the chart popup panel is wrong. The seconds stay zero hence the bar is generated. We have 12145 ticks for that bar, but the time is not changed at all.
Your topic is about MT4, why are you talking about MT5 now ? The algorithm is not the same.
If you use TimeCurrent(), that will give you the time of the tick.
MT tester should generate the tick prices as well as the tick time according to this documentation: https://www.mql5.com/en/articles/75
I've working on backtetsing algorithms for about 15 years. It is interesting that the first algorithm I "invented" on about the far 2002 was almost 1:1 to the algorithm MT uses now. I called that algorithm "shortest interpolation". The name comes from the fact that this is the shortest trajectory passing through the 4 reference points: Open, High/Low and Close. Unfortunately many users of my product reported false backtests showing unrealistically high results. Later on I implemented 4 other algorithms for bar interpolation.
This specific implementation of MT is not totally wrong, if you know how it works and how to go round the pitfalls.
My expert is 6000 lines long where 4000 lines fight with the different issues.
I workaround this tick time issue by "closing" the previous bars at the first tick of the new bar and immediately after that I rise an open event. The problem is that I cannot prevent the Close-Open gap, but it is a way better than leaving the positions open for forever (since the ticks time never go to the end of the bar).
Which pitfalls are you talking about ? MT4 or MT5 ? They are NOT the same. Please don't mix MT4 and MT5, create a new topic if you want to talk about MT5 Strategy Tester "pitfalls".
The Strategy Tester will NEVER by accurate, no matter which algorithm is used. Of course that doesn't mean we want to use a bad or poor algorithm, but backtesting is only backtesting, not the same as a live account.
Thank you Alain for joining to the topic!
If you use TimeCurrent(), that will give you the time of the tick.
Well, returning back to MT4, I'm printing now the tick time with both MqlDateTime and TimeCurrent(). Both show the same values. We see the tick time never goes nearer to the assumed bar closing on M5 chart. The nearest is 23:39:34, which is 26 seconds before the bar close.
The code:
The screenshot: (It shows the last tick time for a bar)
Sorry for spamming the topic, but I found that the "control points" model always gives a last tick 1 second before the bar close. This is completely enough for my work.
Alain, if you are part of the dev. team (or if you can contact them), you can easily add a last second tick to the "Every tick" model or at least in the case when such a tick is missing.
This is the same script, run on the same data, but using the "Control Points" model.
Sorry for spamming the topic, but I found that the "control points" model always gives a last tick 1 second before the bar close. This is completely enough for my work.
Alain, if you are part of the dev. team (or if you can contact them), you can easily add a last second tick to the "Every tick" model or at least in the case when such a tick is missing.
This is the same script, run on the same data, but using the "Control Points" model.
Sorry but I am only a volunteer moderator.
To contact Metaquotes your write to the ServiceDesk.