English

## Slope of a moving average

 11 xspeculator 2014.06.23 20: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?
 1815 SDC 2014.06.23 23:01 #   You can use iMA()
 11 xspeculator 2014.06.23 23:36 #   SDC: You can use iMA() How?If I put iMA() only write the current period, I think.
 1815 SDC 2014.06.24 00: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.
 11 xspeculator 2014.06.24 01:01 #   SDC: period 200, shift 2 or 12. Many thanks
 1815 SDC 2014.06.24 01: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.
 11 xspeculator 2014.06.24 13: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.
13135
WHRoeder 2014.06.24 17: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); }```