Skip to content

atr calculate wrong #46

Description

@wsm1992

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions