Little help please BARS AGO syntax?

 

Hi, how do I have the moving average look back to a certain number of bars ago? I tried the classic variable name with[2] after it, but that just gets me an error. I did search online and the help search and surprisingly cannot find any understandable info on this basic question on how to refer to a past data point of an indicator or price.

thanks

 
moneycode:

Hi, how do I have the moving average look back to a certain number of bars ago? I tried the classic variable name with[2] after it, but that just gets me an error. I did search online and the help search and surprisingly cannot find any understandable info on this basic question on how to refer to a past data point of an indicator or price.

thanks


Can you show the code you tried please ?
 
angevoyageur:

Can you show the code you tried please ?

i just added [2] after the ma variable. ma[2]

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);


then I'd put if (ma>ma[2] ) (but of course that don't work)


I think I need to create a new moving average that always looks backs x bars ago? would that be right? So I would have one ma indicator for the current bar and one ma indicator for the look back period?

 
moneycode:

i just added [2] after the ma variable. ma[2]

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);


then I'd put if (ma>ma[2] ) (but of course that don't work)


I think I need to create a new moving average that always looks backs x bars ago? would that be right? So I would have one ma indicator for the current bar and one ma indicator for the look back period?

If you want the MA from 2 bars ago ue 2 instead of 0

ma = iMA(NULL, 0, MovingPeriod, MovingShift, MODE_SMA, PRICE_CLOSE, 2  );

Please use the SRC button when posting code . . .

 
RaptorUK:

If you want the MA from 2 bars ago ue 2 instead of 0

Please use the SRC button when posting code . . .


Okay thanks.

 
moneycode:

Okay thanks.


Way too many years with Easy language has spoiled my brain. May take me a few extra days to start getting my models converted over to mql4
Reason: