How to get the SMA of high-low of every candle.
Hello!
I think, that such formula helps:
Average = (iHigh(NULL, 0, 0) + iLow(NULL, 0, 0)) / 2
I think that you get SMA based on high prices (SMAH) and SMA based on low prices (SMAL). Then SMA of middle will be equal (SMAH + SMAL) / 2.
I got another solution which is:
If the sma period is 10.
We loop 10 times back at the low and high passed in onCalculate and then add the values of high[i] - low[i] and then divide by the sma period.
If the sma period is 10.
We loop 10 times back at the low and high passed in onCalculate and then add the values of high[i] - low[i] and then divide by the sma period.
double totalDelta = 0; for(int i=0;i<smaPeriod;i++){ totalDelta+= high[i] - low[i]; } double smaValue = totalDelta / smaPeriod;
George Mburu #: We loop 10 times back at the low and high passed in onCalculate and then add the values of high[i] - low[i] and then divide by the sma period.
That gives average range. Why not just use average true range.
How can I calculate the simple averaege of high-low of a candle in mql5 ?
This does not work inside the onCalculate event.
iMA(_Symbol,PERIOD_CURRENT,CandleSpreadMa_Period,0,MODE_SMA,high[0]-low[0]);