A moving average does NOT REPAINT. You are just using it incorrectly. In fact, many indicators do not repaint, however, you should not be using the current bar for calculating the indicator (unless you know exactly what you are doing), because obviously the current bar is still in flux and its High, Low and Close values are still not totally defined, especially not its Close value (which is what you are using, namely "PRICE_CLOSE").
You should only consider the previously closed bar because it will no longer change. So use a shift of [1] instead of [0] and adjust your Open/Close filter to be for bar [2] instead of [1].
//--- get Moving Average ma = iMA( NULL, PERIOD_CURRENT, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 1 ); //--- sell conditions if( ( Open[ 2 ] > ma ) && ( Close[ 2 ] < ma ) ) { ... } //--- buy conditions if( ( Open[ 2 ] < ma ) && ( Close[ 2 ] > ma ) ) { ... }
An added advantage, is that since you are only considering the previous bar, you no longer need to check it on every tick. You only need to detect when a new bar is formed and only carry out your verification then, making your EA much faster during back-tests.
With regard to your strategy of only using one move average, please be aware that you will still suffer many a situation of "whipsaw" that will drain your balance away. So add extra filters, such as for detecting the slope or deviation of the moving average, in order to minimise the impact.
- 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 everyone, it is possible to obtain the moving average no repaint? By working with well-known moving average that in the historical shifts and is no longer true as I could solve?