OPEN-SOURCE SCRIPT
Allan Variance Stability Index [forexobroker]

Allan Variance Stability Index [forexobroker] adapts the Allan deviation — the standard tool for measuring atomic clock frequency stability — to financial returns. By computing the standard deviation of block-averaged log-returns across multiple timescales tau in {1, 2, 4, 8, 16, 32}, the script asks whether price drift behaves consistently or fragments across horizons. The single stability index S then collapses that multi-scale picture into one number that an adaptive median-and-sigma floor can monitor. The unique angle is borrowing a frequency-domain stability metric instead of a price-domain volatility one, so the script reads regime change rather than range size.
🔶 ALGORITHM
1. Log-returns r_t = log(close / close[1]) are computed and the last M (default 128) are used.
2. For each lag tau in {1, 2, 4, 8, 16, 32}: the return window is split into floor(M / tau) contiguous blocks, each block-averaged, and sigma(tau) is the standard deviation of those block averages.
3. The six log-sigmas are averaged and S = -stdev(log sigma(tau)) is computed — higher S means returns scale predictably across tau, lower S means timescales disagree.
4. An adaptive floor is computed each bar as median(S, adaptive median length default 80) minus k (default 1.0) times stdev(S) over the same window.
5. When S falls below the floor the regime is destabilising; the sign of close - close[momentum lookback default 3] arms a directional bias.
6. When S crosses back above the floor inside that armed bias, the entry fires — the script trades the trend that survived the instability.
🔶 SIGNAL LOGIC
- Buy: S crosses up through the floor AND active bias is bullish (close was above close[n] while S was under the floor) AND session filter passes AND position is not already long AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: S crosses up through the floor AND active bias is bearish AND session filter passes AND position is not already short AND cooldown bars elapsed AND barstate.isconfirmed.
The cross-back is the trigger; the bias is set during the instability window.
🔶 INPUTS
- Stability Calculation group: return window M default 128, adaptive median length default 80, floor k x sigma default 1.0.
- Signal Logic group: momentum lookback default 3, cooldown bars default 15.
- Filters group: session restriction (default 0000-2400).
- Visual group: dashboard, 3-layer glow, stability line color, floor color, buy and sell colors.
🔶 ALERTS
AVS Buy, AVS Sell, AVS Any Signal, AVS Floor Break, AVS Floor Reclaim, AVS Arm Up, AVS Arm Down, AVS Vol Expanding, AVS Vol Contracting, AVS Bias Flip, AVS Webhook JSON.
🔶 LIMITATIONS
- Needs M plus 32 confirmed returns of history before sigma(32) is reliable, so early-chart bars produce noisy S values.
- The Allan-style estimator was designed for stationary frequency oscillators; under structural market shifts S can stabilise around a new floor for several bars before the adaptive median catches up.
- Block averaging at large tau reduces the number of blocks, so sigma(32) is the noisiest leg of the curve and dominates S in low-history regimes.
- Defaults are tuned for liquid futures and crypto on intraday timeframes; very thin instruments produce zero-return blocks that pin sigma(1) and inflate S.
- The bias is set on the instability bar but only fires on the reclaim, so very short instability episodes can fire a signal with stale momentum context.
🔶 ALGORITHM
1. Log-returns r_t = log(close / close[1]) are computed and the last M (default 128) are used.
2. For each lag tau in {1, 2, 4, 8, 16, 32}: the return window is split into floor(M / tau) contiguous blocks, each block-averaged, and sigma(tau) is the standard deviation of those block averages.
3. The six log-sigmas are averaged and S = -stdev(log sigma(tau)) is computed — higher S means returns scale predictably across tau, lower S means timescales disagree.
4. An adaptive floor is computed each bar as median(S, adaptive median length default 80) minus k (default 1.0) times stdev(S) over the same window.
5. When S falls below the floor the regime is destabilising; the sign of close - close[momentum lookback default 3] arms a directional bias.
6. When S crosses back above the floor inside that armed bias, the entry fires — the script trades the trend that survived the instability.
🔶 SIGNAL LOGIC
- Buy: S crosses up through the floor AND active bias is bullish (close was above close[n] while S was under the floor) AND session filter passes AND position is not already long AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: S crosses up through the floor AND active bias is bearish AND session filter passes AND position is not already short AND cooldown bars elapsed AND barstate.isconfirmed.
The cross-back is the trigger; the bias is set during the instability window.
🔶 INPUTS
- Stability Calculation group: return window M default 128, adaptive median length default 80, floor k x sigma default 1.0.
- Signal Logic group: momentum lookback default 3, cooldown bars default 15.
- Filters group: session restriction (default 0000-2400).
- Visual group: dashboard, 3-layer glow, stability line color, floor color, buy and sell colors.
🔶 ALERTS
AVS Buy, AVS Sell, AVS Any Signal, AVS Floor Break, AVS Floor Reclaim, AVS Arm Up, AVS Arm Down, AVS Vol Expanding, AVS Vol Contracting, AVS Bias Flip, AVS Webhook JSON.
🔶 LIMITATIONS
- Needs M plus 32 confirmed returns of history before sigma(32) is reliable, so early-chart bars produce noisy S values.
- The Allan-style estimator was designed for stationary frequency oscillators; under structural market shifts S can stabilise around a new floor for several bars before the adaptive median catches up.
- Block averaging at large tau reduces the number of blocks, so sigma(32) is the noisiest leg of the curve and dominates S in low-history regimes.
- Defaults are tuned for liquid futures and crypto on intraday timeframes; very thin instruments produce zero-return blocks that pin sigma(1) and inflate S.
- The bias is set on the instability bar but only fires on the reclaim, so very short instability episodes can fire a signal with stale momentum context.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.