Download MetaTrader 5

Little help please BARS AGO syntax?

To add comments, please log in or register
john
213
john  

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

Alain Verleyen
Moderator
33341
Alain Verleyen  
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 ?
john
213
john  
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?

Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
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 . . .

john
213
john  
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.

john
213
john  
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
To add comments, please log in or register