Download MetaTrader 5
To add comments, please log in or register
Learn operation principles of Trading Signals for MetaTrader.
whroeder1 2014.03.16 14:11  
  1.  if (Bars==3000) Print (iATR(Symbol(),Period(),3000,0)); //Prints 0
    Bad call.
    TR[i] = max( High[i], Close[i+1] ) - min( Low[i], Close[i+1] )
    so at a minimum you must have length+1 bars to compute ATR(length).
  2. The new code (MQL4\indicators\ATR.mq4) does a
    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.

  3. The code contains (my comments in red)
    limit=InpAtrPeriod+1; // The +1 is correct here - the last valid value
    // is InpAtrPeriod, calculate remaining values.
    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++)
    Reported at service desk #978330 fix is do not recalculate the firstValue when rates_total == InpAtrPeriod + 1
    // if(rates_total<=InpAtrPeriod || InpAtrPeriod<=0)
       if(rates_total<=InpAtrPeriod+1 || InpAtrPeriod<=0)
/ /12
To add comments, please log in or register