Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atr calculate wrong #46

Open
wsm1992 opened this issue Jan 29, 2021 · 0 comments
Open

atr calculate wrong #46

wsm1992 opened this issue Jan 29, 2021 · 0 comments

Comments

@wsm1992
Copy link

wsm1992 commented Jan 29, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant