technical-analysis
technical-analysis copied to clipboard
atr calculate wrong
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