Download MetaTrader 5

Slope of a moving average

To add comments, please log in or register
xspeculator
33
xspeculator  

I want to calculate the slope of a moving average of 200 periods.

I want to use the values of periods -12 and -2 (periodes couting from actual period) for calculate this slope.

Can I acess historical values of a moving average?

Ian Venner
2584
Ian Venner  

You can use iMA()

xspeculator
33
xspeculator  
SDC:

You can use iMA()


How?

If I put iMA() only write the current period, I think.  

Ian Venner
2584
Ian Venner  
double iMA(
string symbol, // symbol
int timeframe, // timeframe
int ma_period, // MA averaging period
int ma_shift,  // MA shift
int ma_method, // averaging method
int applied_price, // applied price
int shift // shift
);

 

period 200, shift 2 or 12.

xspeculator
33
xspeculator  
SDC:
period 200, shift 2 or 12.


Many thanks

Ian Venner
2584
Ian Venner  

you could do it like that, but it would be more efficient if you wrote it into an indicator loop and put the iMA() in a buffer and call your own buffer indexes.

xspeculator
33
xspeculator  

Thank you,

In a first attempt I will try the first option, if my strategy has good results i will try apply this with buffer.

whroeder1
14778
whroeder1  
xspeculator: I want to calculate the slope of a moving average of 200 periods.
I want to use the values of periods -12 and -2 (periodes couting from actual period) for calculate this slope.
Can I acess historical values of a moving average?
  1. I assume you mean shifts of 2 and 12
  2. Of course you can
double MAslope(int length=200, int iFrom=12, int iTo=2, 
               ENUM_MA_METHOD      mode=MODE_SMA, 
               ENUM_APPLIED_PRICE price=PRICE_CLOSE){
   double maF = iMA(NULL, PERIOD_CURRENT, length, 0, mode, price, iFrom);
   double maT = iMA(NULL, PERIOD_CURRENT, length, 0, mode, price, iTo);
   return (maF - maT) / (iFrom - iTo);
}
To add comments, please log in or register