It makes it much easier for others to help you if you post some relevant code and how/when it is returning 0.
double iMA( |
I think that it is unfortunate that they use the word shift twice as it can be confusing for some people.
Maybe it could be MA Offset instead of shift.
I think that your issue is related to you expecting a value when there is no value for a particular bar index.
Of course you can use a negative MA shift in code
double ma_value=iMA(_Symbol,PERIOD_CURRENT,21,-10,MODE_EMA,PRICE_CLOSE,1);
but the above will return 0.
Why?
Because with a -10 MA shift. the MA is shifted backwards. That means there is no MA at bar 1 so bar 1 will return 0. As will all bar indexes up to and including 9.
double ma_value=iMA(_Symbol,PERIOD_CURRENT,21,-10,MODE_EMA,PRICE_CLOSE,10);
This will return a value because bar 10 is the most recent bar where the MA has a value.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
A negative MA shift value works fine in charts, but returns 0 in MQL4 code.
Why is that?
Please don't tell me that "we can't look into the future." That is not the point.
The point is a that negative MA shift value plots a certain position in the chart, and I want to obtain that same exact position/value with code.
How does that work exactly?
TIA