DxdCn:
Correctiondatetime lasttime = NULL;
if (Time[0] == lasttime ) return;
datetime lasttime = 0; int start() { if (Time[0] >= lasttime ) return (0); lasttime = Time[0];
Thanks for your help.
Unfortunately it didn't fully solved the problem.
With the code of DxdCn now I have only one entry for each cross but many of them have been missed (for example the one I used in the original post) as you can see below. And there shouldn't be 3 cross up in a row, the algorithm certainly missed the cross downs in between them.
With the correction of Irtron I do not get any result. If I understand well the code, I guess the present time is always >= the last time so this statement is always true and the main part of the code is never actually executed.
Any ideas?
Thanks for your time.
Alvo
Output with the code of DxdCn:
Unfortunately it didn't fully solved the problem.
With the code of DxdCn now I have only one entry for each cross but many of them have been missed (for example the one I used in the original post) as you can see below. And there shouldn't be 3 cross up in a row, the algorithm certainly missed the cross downs in between them.
With the correction of Irtron I do not get any result. If I understand well the code, I guess the present time is always >= the last time so this statement is always true and the main part of the code is never actually executed.
Any ideas?
Thanks for your time.
Alvo
Output with the code of DxdCn:
2007.08.24 10:09:32 2007.08.05 00:00 cross_alert GBPUSD,Daily: Cross UP 2007.08.24 10:09:32 2007.06.08 00:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.24 10:09:32 2007.05.24 00:00 cross_alert GBPUSD,Daily: Cross UP 2007.08.24 10:09:32 2007.04.27 00:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.24 10:09:32 2007.03.18 00:00 cross_alert GBPUSD,Daily: Cross UP 2007.08.24 10:09:32 2007.02.23 00:00 cross_alert GBPUSD,Daily: Cross UP 2007.08.24 10:09:32 2007.02.02 00:00 cross_alert GBPUSD,Daily: Cross UP 2007.08.24 10:09:32 2006.12.25 00:00 cross_alert GBPUSD,Daily: Cross DOWN
This is because you use previous and current bars for ma calculations. Although
the current bar is being formed and its close price changes.
Use most recent complete bars #1 and #2 for ma crossing calculation.
Use most recent complete bars #1 and #2 for ma crossing calculation.
Hi Irtron,
Using if (Time[0] == lasttime ) and bar #1 and #2 did the trick!
Thanks again!
Alvo
Using if (Time[0] == lasttime ) and bar #1 and #2 did the trick!
Thanks again!
Alvo
![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'm just starting to learn MQL4.
I want to make the classic example of looking for EMA crosses:
I run it on GBPUSD on the daily chart and it detects the crosses well but the output in the Journal tab is pretty weird. For example there is a cross on 2007.07.27 and this is what I see in the Journal (it is the same at any other cross as well):
I have no intention to use this code to execute any order but if I did would it execute 18 orders???
How can I fix this to have only one single entry for each cross?
Thanks for your help!
Alvo