Please don't post randomly in any section. MT4/mql4 has it's own section on the forum.
I have moved your topic to the correct section, so please don't create another topic.
Please don't post randomly in any section. MT4/mql4 has it's own section on the forum.
I have moved your topic to the correct section, so please don't create another topic.
Hello Fernando,
Sorry, I hadn't noticed that there are several sections for EAs.
When the candle closes, the crossover has occurred. There is no “this case.” You said it yourself:
double aPrev = …(i+1), aCurr = …(i), bPrev = …(i+1), bCurr = …(i); bool wasUp = aPrev > bPrev, isUp = aCurr > bCurr, isCross = isUp != wasUp;
When the candle closes, the crossover has occurred. There is no “this case.” You said it yourself:
First of all just to avoid misunderstanding, candle 0 would be current candle, and you have to compare the prices of MA on close prices of candle 1 and candle 2. Also in your picture, you can see that on candle 1, faster MA is below slower MA. And on your candle 0 faster MA is above …
Candle one never opens. It is closed. All indicators should be fixed. If an indicator changes after the fact, that is called repainting and is useless.
Only candle zero (right most) opens and signals can come and then go.
Hello, sorry, I was busy these last days, but I finally took the time to make a visual backtest with screenshots:
As you can see, when checking only at candle opening, the classic method for ma crossing detection doesn't work here: when a candle opens at 10:15, a crossover occurs between 10:05 and 10:10, but not between 10:10 and 10:15. In reality, the crossover occurs during the 10:10 candle.
Finally, for checking at opening, I think the best is to check a crossover between:
- Candle 1 and candle 0
- Candle 2 and candle 1
hi Matthieu Jean Baptiste Wambergue,
yes I know this phaenomenon and I wondered how it can be, that I missed a crossover or detected it (one candle) too late...
But I will try your strategy to check the 2nd last candle before, too.
Maybe, there is another possibility to check a crossover, which I had overseen, yet.
hi Matthieu Jean Baptiste Wambergue,
yes I know this phaenomenon and I wondered how it can be, that I missed a crossover or detected it (one candle) too late...
But I will try your strategy to check the 2nd last candle before, too.
Maybe, there is another possibility to check a crossover, which I had overseen, yet.
it's very simple, the MA indicator updates continuously during the current bar with each price change, so there maybe an MA crossover during the bar but its value becomes static at the closing of the bar based upon the final closing price.
most people would only consider it a crossover based on the last closed bar not the current bar which will give too many false signals.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I recently realized that my code for detecting moving average crossovers was not perfect. Instead, it is the classic code that is generally used by EAs.
Here is an example for US30 (backtested in visual mode in order to see the values of the moving averages at each bar opening):
- At point 1: in reality, the crossover has not yet occurred;
- At point 2: as the US30 falls, the MA1 also falls. Then a crossover occurs, but it's just before point 1. As the EA is looking for a crossover between point 1 and point 2, it doesn't see the crossover before point 1.
Here is the code of the function:
All orders are properly opened except when a case like this appears.
I had the idea to do an additional check to see if a crossover occurs between bar 0 and bar 1 at the open of bar 2, but I wonder if a crossover can, depending on the volatility , occur before the bar 0.
Have you ever noticed this 'bug'?
Do you have an idea to fix it without making the code too complex?
Thanks in advance.