# Slope of a moving average

33
2014.06.23 18:52

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?

2584
2014.06.23 21:01

You can use iMA()

33
2014.06.23 21:36
SDC:

You can use iMA()

How?

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

2584
2014.06.23 22:51
```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.

33
2014.06.23 23:01
SDC:
period 200, shift 2 or 12.

Many thanks

2584
2014.06.23 23:33

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.

33
2014.06.24 11:31

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.

14750
2014.06.24 15:48
 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? I assume you mean shifts of 2 and 12Of 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); }```