JavaScript · Indicator Code
R10 / Range Stat in JavaScript
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).JavaScript
/**
* R10 / Range Stat: one-tenth of the typical daily range.
*
* R10 = (mean(range) + populationStdDev(range)) / 10 over the 30 EOD bars
* STRICTLY BEFORE the current bar (current bar excluded -> no look-ahead).
* `range` is high - low per bar. This is the standard minimum-manageable-risk
* box used for position sizing.
*
* Faithful to edge-canvas calcR10 (window = slice(-(n+1), -1), n<=30).
*
* @param {number[]} high - bar highs, ascending by date
* @param {number[]} low - bar lows, ascending by date
* @returns {(number|null)[]} r10[i] uses the 30 bars before index i;
* null where fewer than 2 prior bars exist
*/
function r10(high, low) {
const out = [];
for (let i = 0; i < high.length; i++) {
const n = Math.min(i, 30); // bars available STRICTLY BEFORE i
if (n < 2) { out.push(null); continue; }
const ranges = [];
for (let j = i - n; j < i; j++) ranges.push(high[j] - low[j]);
const mean = ranges.reduce((s, v) => s + v, 0) / ranges.length;
const variance =
ranges.reduce((s, v) => s + (v - mean) ** 2, 0) / ranges.length;
out.push((mean + Math.sqrt(variance)) / 10.0); // population stddev
}
return out;
}
Improve Your Craft Every Morning
A short note from Dr. Ken Long on the craft of trading. One idea to think about and work on that day, drawn from decades of teaching and live trading. Free.
Your email:
Tue–Fri mornings. Unsubscribe anytime. No spam, no hype.