
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
ATR[i] = Atr[i+1] + (TR[i]-TR[i+length])/length
This is more efficient SMA than summing up length elements (which the old code did.) But, if the previous value is computed wrong, it takes length new values to reset. This is what your Bars=4500/6000 shows.limit=InpAtrPeriod+1; // The +1 is correct here - the last valid value
// is InpAtrPeriod, calculate remaining values.
}
else
limit=prev_calculated-1; // Here prev_calculated-1 must be recalculated.
// But if rates_total == InpAtrPeriod+1 there is
// no ATR[i-1] value
//--- the main loop of calculations
for(i=limit; i<rates_total; i++)
{
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-InpAtrPeriod])/InpAtrPeriod;