Download MetaTrader 5
To add comments, please log in or register
Interested in MetaTrader 5 features? Learn more about them!
xspeculator
33
xspeculator 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?

Ian Venner
2583
Ian Venner 2014.06.23 21:01  

You can use iMA()

xspeculator
33
xspeculator 2014.06.23 21:36  
SDC:

You can use iMA()


How?

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

Ian Venner
2583
Ian Venner 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.

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


Many thanks

Ian Venner
2583
Ian Venner 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.

xspeculator
33
xspeculator 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.

whroeder1
13627
whroeder1 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?
  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