How to get the SMA of high-low of every candle.

 

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]);

 
Hello!
I think, that such formula helps: 
Average = (iHigh(NULL, 0, 0) + iLow(NULL, 0, 0)) / 2
 

Hi @Anton Ohurtsov  how can I use it to get the SMA ?

Anton Ohurtsov
Anton Ohurtsov
  • 2023.01.03
  • www.mql5.com
Trader's profile
 
George Mburu #:

Hi @Anton Ohurtsov  how can I use it to get the SMA ?

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.
 
Anton Ohurtsov #:
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.Good 

Nice solution. Thank you.

 
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.


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.

Reason: