![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
Do Not Double Post!
I have deleted your duplicated topic.
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.
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.
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.
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.
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.
My code
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.
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.
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.