Python · Indicator Code
R10 / Range Stat in Python
One-tenth of the typical daily range (mean+stddev of high-low over 30 prior bars), the standard minimum-manageable-risk sizing box.
Verified. Python and JavaScript implementations agree to
1.11e-16 on a 60-bar reference high/low series (canonical Python (edge-scan) vs JavaScript, comparable positions).Python
import numpy as np
def r10(high, low):
"""R10 / Range Stat: one-tenth of the typical daily range.
R10 = (mean(range) + population_stddev(range)) / 10 computed over the 30
EOD bars STRICTLY BEFORE the current bar (the current bar is excluded so the
value is safe for no-look-ahead sizing). ``range`` is high - low per bar.
This is the standard minimum-manageable-risk box used for position sizing:
a risk unit of one-tenth of the typical daily range.
Faithful to edge-scan ``_rangestat_from_window`` / ``compute_rangestat_for_date``
(n_div=10, fixed 30-bar strictly-before lookback).
Args:
high: sequence of bar highs, ascending by date.
low: sequence of bar lows, ascending by date.
Returns:
list aligned to the input: r10[i] uses the 30 bars before index i;
None where fewer than 2 prior bars are available.
"""
high = np.asarray(high, dtype=float)
low = np.asarray(low, dtype=float)
ranges = high - low
out = []
for i in range(len(ranges)):
window = ranges[max(0, i - 30):i] # 30 bars STRICTLY BEFORE bar i
if len(window) < 2:
out.append(None)
continue
mean = float(np.mean(window))
std_pop = float(np.std(window, ddof=0)) # population stddev
out.append((mean + std_pop) / 10.0)
return out
Improve Your Craft Every Morning
Daily commentary from Dr. Ken Long — what he's seeing in markets, how he's framing trades, and what's worth practicing today. Free.
Your email:
Tue–Fri mornings. Unsubscribe anytime. No spam, no hype.