Why Moving Average can drop down? - page 3

 
Fernando Carreiro #:

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 :-)

 
Nino Guevara Ruwano #: Great answer sir, really answers the problem. Very clear and easy to understand. Thank you :-)
You are welcome!
 
maximo #:


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.