technical-analysis icon indicating copy to clipboard operation
technical-analysis copied to clipboard

atr calculate wrong

Open wsm1992 opened this issue 4 years ago • 0 comments

atr calculate in a wrong way, should not get the new one from last result

    if period_values.size == period
      if output.empty?
        atr = ArrayHelper.average(period_values)
      else
        atr = (output.last.atr * (period - 1.0) + tr) / period.to_f
      end

      output << AtrValue.new(date_time: v[:date_time], atr: atr)

      period_values.shift
    end

    prev_price = v
  end

you should just re-calculate the average of period_values like this

    if period_values.size == period
      atr = ArrayHelper.average(period_values)

      output << AtrValue.new(date_time: v[:date_time], atr: atr)

      period_values.shift
    end

    prev_price = v
  end

wsm1992 avatar Jan 29 '21 07:01 wsm1992