OGT Owl Group Trading by Dr. Ken Long
Home About Learn The Loop Code Courses Essays Store Partners FAQ
JavaScript · Indicator Code

Frog (range volatility) in JavaScript

Frog is the population standard deviation of the daily High−Low range over the prior ~30 trading days, a measure of how erratic a symbol's daily bar size has been.

Concept: what FROG means →

Verified. Python and JavaScript implementations agree to 2.22e-16 on a 60-bar reference high/low series (canonical Python (edge-scan compute_frog_for_date) vs JavaScript (calcFrog30d), comparable positions).

JavaScript

/**
 * Frog — population standard deviation of the daily (High - Low) range over
 * the last n trading days preceding the current day (the final bar excluded).
 *
 * Verbatim math from edge-canvas calcFrog30d. Bit-parity with the canonical
 * Python (edge-scan compute_frog_for_date): population stddev (divide by N),
 * window = the n bars strictly before the last/current bar.
 *
 * @param {Array<{high:number, low:number}>} eodCandles - Daily OHLC bars, ascending by date.
 * @param {number} n - Lookback window in trading days (default 30).
 * @returns {number|null} Frog value, or null if fewer than 2 observations.
 */
export function frog(eodCandles, n = 30) {
  // Use up to n days PRECEDING the last bar (exclude the current day).
  const win = Math.min(eodCandles.length - 1, n);
  if (win < 2) return null;

  // Window: the win bars ending one position before the final bar.
  const window = eodCandles.slice(-(win + 1), -1);
  const ranges = window.map((c) => c.high - c.low);

  // Population variance (divide by N), then standard deviation.
  const mean = ranges.reduce((s, v) => s + v, 0) / ranges.length;
  const variance = ranges.reduce((s, v) => s + (v - mean) ** 2, 0) / ranges.length;
  return Math.sqrt(variance);
}