Why Moving Average can drop down? - page 2

 
Alex Nguyen #:

Do Not Double Post!

I have deleted your duplicated topic.

 
Keith Watford #:

Your new image is showing a shifted MA, not a slow MA.
The vertical line looks like a trendline.

Yes, that is a shift MA, the vertical line not a trendline, that is shift MA in current time and it fall down to zero.

 
Alex Nguyen #: I call 2 MA with the basic code.
MA300[i]=iMA(NULL,NULL,MAPeriod,0,0,0,i);
MA300slow[i]=iMA(NULL,NULL,MAPeriod,-40,0,0,i);

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.

 
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.

Thank you so much for your explaning. I understood more about my situation. I also don't understand it base on value of the shift point MA300 ( my MA), why the shift MA is empty value
 
Alex Nguyen #: Thank you so much for your explaning. I understood more about my situation. I also don't understand it base on value of the shift point MA300 ( my MA), why the shift MA is empty value

Shifting a moving average backwards (negative shift), means that the last most recent quote is drawn in the past, but no information is available after that, because we cannot predict the future values. It is unknown.

 
Fernando Carreiro #:

Shifting a moving average backwards (negative shift), means that the last most recent quote is drawn in the past, but no information is available after that, because we cannot predict the future values. It is unknown.

another case, I use 2 MA from Mt4 indicators with the same setting and it looks like they are working normally
https://charts.mql5.com/32/731/nas100-m15-fxcm-australia-pty.png

My ideal that finding the point MA300 and MA300 shift(-40) cross each other, so I call them in my indicator.

 
for(i=limit; i>=0; i--)
     {   
      //--
      digit   = Digits;
      //--
      index=iBarShift(NULL,PERIOD_D1, Time[i], false);
      POL[i]=iOpen(NULL,PERIOD_D1, index);
      //--
      MA300[i]=iMA(NULL,NULL,MAPeriod,0,0,0,i);
      MA300ex[i]=iMA(NULL,NULL,MAPeriod,-40,0,0,i);

My code
 
Alex Nguyen #: another case, I use 2 MA from Mt4 indicators with the same setting and it looks like they are working normally https://charts.mql5.com/32/731/nas100-m15-fxcm-australia-pty.png


My ideal that finding the point MA300 and MA300 shift(-40) cross each other, so I call them in my indicator.

As already explained, a negatively shifted moving average has no current values, so you will NEVER be able to detect a cross at the current bar or even up to "x" bars, where "x" is the negative shift.

I negative shift is equivalent to trying to look into the future. It can't be done, unless you have "psychic" abilities.

 
Alex Nguyen #:

Yes, that is a shift MA, the vertical line not a trendline, that is shift MA in current time and it fall down to zero.

The reason that I said it looks like a trendline is because the MA actually passes the top of the line. So it can't possibly be a single buffer.

MA

 
Alex Nguyen:

Hi all, 
I am writing a simple indicator base on 2 MA Cross. I don't understand why Slow MA can Drop down like imagie
Can you help me!
[img]https://charts.mql5.com/32/729/nas100-m15-fxcm-australia-pty-2.png[/img]


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.