Indicators: wd.Range_DailyAvg - page 2

 

Every range calculation is off by one point. For the benefit of those who may not know how to verify the accuracy of the range: it can be checked via the Data Window by calculating the range for any particular day (subtracting the Low from the High), then summing the daily ranges over the relevant number of days, and finally dividing that total by the number of days.

The included screenshot shows the previous day's High as 294.81 and the Low as 272.37, resulting in a range of 2.44 or 244 points. However, the indicator returns 243 points. This one-point discrepancy is carried through the rest of the calculations.

A small and seemingly insignificant error—but an error nonetheless.

 

Very short edit time !

For consideration

input int   prevXDays   = 20; //  Prev Days - Daily AV 

int OnCalculate()
{
  
  double rangeToDay=0, rangePrevDay=0, rangePrevXDays=0;

  rangeToDay =(iHigh(NULL, PERIOD_D1, 0)-iLow(NULL, PERIOD_D1, 0))/_Point; 
  rangePrevDay =(iHigh(NULL, PERIOD_D1, 1)-iLow(NULL, PERIOD_D1, 1))/_Point;
  
  for(int x=1;x<=prevXDays;x++) rangePrevXDays += (iHigh(NULL,PERIOD_D1,x)-iLow(NULL,PERIOD_D1,x))/_Point; 
  
  rangePrevXDays /= prevXDays;

}
 

Not the optimal edit time window for busy people !

The above code can be tested for accuracy:

  1. Set prevXDays = 1. The code return should match the Data Widow High - Low range for the previous day.
  2. Set pevXDays = 5. From the Data Window Sum the High - Low range for the previous 5 days and divide the sum by 5. The code return should match the manual calculation.