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?
You can use iMA()
If I put iMA() only write the current period, I think.
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.
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.
In a first attempt I will try the first option, if my strategy has good results i will try apply this with buffer.
double MAslope(int length=200, int iFrom=12, int iTo=2,
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