All problems
Average True Range
Problem
Compute the average true range from high, low, and close lists. For each t >= 1 the true range is the maximum of high[t] - low[t], abs(high[t] - close[t-1]), and abs(low[t] - close[t-1]); return the mean of those true ranges.
Return 0.0 when fewer than two bars are given.
Hint
Gaps make the true range larger than the simple high-minus-low bar range.
Test cases
case 1
in: [[10,12,13],[8,9,10],[9,11,12]]
expected: 3
case 2
in: [[5,6,7,8],[3,4,5,6],[4,5,6,7]]
expected: 2
case 3
in: [[5,6],[4,5],[5,6]]
expected: 1
case 4
in: [[5],[4],[5]]
expected: 0
Starter codePython
def average_true_range(highs, lows, closes):
# Your code here
pass4 test cases · run your code against them in the editor