Previous Bar Moving average Value

 

Hi All,


I have been searching for an answer to this but nothing is presenting itself.


I am trying to get the value of the previous bar's moving average value. I can get the current one using iMA() without a problem, but I am not sure how to query the previous bar.


Can someone point me in the right direction?

 
AlwayzLearnin wrote >>

Hi All,

I have been searching for an answer to this but nothing is presenting itself.

I am trying to get the value of the previous bar's moving average value. I can get the current one using iMA() without a problem, but I am not sure how to query the previous bar.

Can someone point me in the right direction?

In the iMA call you just replace the shift value (zero if it's the current bar) with a 1 (or whatever) for the respective bar that you want to see. Shift (NOT ma_shift) is the bar that you want to look at - zero for current bar, one for previous bar, etc...

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

Hope that helps.

- Tovan

 
tovan wrote >>

In the iMA call you just replace the shift value (zero if it's the current bar) with a 1 (or whatever) for the respective bar that you want to see. Shift (NOT ma_shift) is the bar that you want to look at - zero for current bar, one for previous bar, etc...

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

Hope that helps.

- Tovan

I have this similar question but how do you get the value of the MA at -1 shift. for example If i put the shift to be 1 bar after the last bar. m trying to get its value but it keeps returning 0. Can you help?

 
derrickc:

I have this similar question but how do you get the value of the MA at -1 shift. for example If i put the shift to be 1 bar after the last bar. m trying to get its value but it keeps returning 0. Can you help?

That value will be just in the future. iMA indicator cannot predict the future. Maybe you confuse the following ones:

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

Cheers



 
AlwayzLearnin wrote >>

Hi All,

I have been searching for an answer to this but nothing is presenting itself.

I am trying to get the value of the previous bar's moving average value. I can get the current one using iMA() without a problem, but I am not sure how to query the previous bar.

Can someone point me in the right direction?

How do you get current value using iMA? Please write here

 
tovan wrote >>

In the iMA call you just replace the shift value (zero if it's the current bar) with a 1 (or whatever) for the respective bar that you want to see. Shift (NOT ma_shift) is the bar that you want to look at - zero for current bar, one for previous bar, etc...

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

Hope that helps.

- Tovan

Hi Tivan,

I also want this info and thought that is what the last 'shift' variable was, but wasn't sure. A retroactive thanks for the clarification.

 

Guys, that is very simple:

First put the MA values into internal variables:

double Ma_0=iMA(NULL,0,MovingFast,0,MODE_EMA,PRICE_TYPICAL,0); // MA on present bar
double Ma_1=iMA(NULL,0,MovingFast,0,MODE_EMA,PRICE_TYPICAL,1); // MA before one bar
double Ma_2=iMA(NULL,0,MovingFast,0,MODE_EMA,PRICE_TYPICAL,2); // MA before two bar
double Ma_3=iMA(NULL,0,MovingFast,0,MODE_EMA,PRICE_TYPICAL,3); // MA before three bar

Then, simply do what you want with it, like:

if (Ma_0>Ma_1) {.....}

if (Ma_2<Ma_3){.....}

etc.....

 

Hi,

Just browsing through the forum, saw this topic. If i need to look for widening downtrened of a faster and a slower moving avaerage.

Ma_0>Ma_1 does it mean that MA is, moving downwards?

 
if Ma_0>Ma_1,  MA's moving upstairs.
Reason: