Skip to content

atr calculate wrong #46

@wsm1992

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions