![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
For a negatively (backwards) shifted moving average, you should not read past the shift point, because values will be undefined (as there is no data available after the shift point).
EDIT: In other words, the last most current 40 bars of the shifted MA are undefined.
EDIT2: That is why it is drawing an almost vertical line at the end, because it tries to connect the most recent valid value to the undefined value.
EDIT3: I am also assuming that the moving averages plotted on your chart are from a custom indicator that uses zero as its empty value without setting it as its default empty. If it were correctly coded, it would not draw the vertical line.
Great answer sir, really answers the problem.
Very clear and easy to understand.
Thank you :-)
The reason it drops to zero is because the empty value for the line is zero, so metatrader will draw the line going to zero.
EMPTY_VALUE tells metatrader not to draw a line and that value is not zero.
So set the line buffer number to EMPTY_VALUE in init() like so..
SetIndexEmptyValue(index_number,EMPTY_VALUE); // index number = buffer number of the line
Alternatively you can put EMPTY_VALUE on the last data point of where the line terminates, to stop drawing.
Thank Maximo, I fixed my indicator.