Mis à jour
AF_StochZ_Overlay

AF_StochZ Overlay — Adaptive Fisher-Transformed Stochastic with Z-Score Normalized Lead Signals & Divergence Detection
Overview
AF_StochZ Overlay is a price-chart (overlay) signal tool built on a statistically normalized, adaptive stochastic oscillator. Instead of plotting the oscillator in a separate pane, it converts the oscillator's extreme readings and divergences directly into labeled buy/sell markers on price, so traders can react to momentum-based signals without switching focus between panes.
How it works
Adaptive lookback (Efficiency Ratio): The stochastic lookback length is not fixed. It is calculated每 bar using Kaufman's Efficiency Ratio (ER), which compares net directional price change to total path traveled over erLen bars. When price moves efficiently (strong trend), the lookback contracts toward minLen for faster response; when price is choppy, the lookback expands toward maxLen to filter noise.
Stochastic → Fisher Transform: A standard %K stochastic is calculated over this adaptive length, smoothed, then rescaled to a ±1 range and passed through a Fisher Transform. The Fisher Transform sharpens turning points by converting a bounded oscillator into a signal with a more Gaussian (normal) distribution, making extremes statistically more distinct than a raw stochastic.
Z-Score normalization: The Fisher-transformed value is then normalized against its own rolling mean and standard deviation (zLen) to produce a Z-Score. This means overbought/oversold thresholds are expressed in standard deviations from the indicator's own recent behavior, rather than fixed 0–100 levels — the thresholds self-adjust to each instrument's and timeframe's own statistical character.
Lead-signal confirmation logic: A raw Z-Score pivot alone is not enough to fire a signal. The script requires the oscillator to pivot beyond the user-defined threshold, AND price itself to form a confirmed swing pivot (pricePivotL/pricePivotR) within a maximum bar lag (maxPriceLag) after that oscillator pivot. Only when both conditions line up in sequence does a BUY/SELL label print. This two-stage confirmation is designed to reduce the false positives that pure oscillator-crossing signals typically generate.
Regular & hidden divergence detection: Independently of the lead signals, the script scans a configurable lookback window (divLookbackMin–divLookbackMax) for regular divergence (price extreme vs. oscillator extreme disagreement, signaling potential reversal) and hidden divergence (signaling potential trend continuation), comparing confirmed price pivots against the Z-Score oscillator at the same pivots.
What problem it solves
Classic stochastic oscillators use a fixed lookback and fixed 0–100 overbought/oversold bands, which makes them lag in trending markets and whipsaw in choppy ones, and their thresholds are not adapted to the volatility regime of the specific instrument being traded. AF_StochZ Overlay addresses this by (a) adapting its own lookback to current market efficiency, (b) expressing overbought/oversold as a statistically self-calibrating Z-Score rather than an arbitrary fixed band, and (c) requiring price-action confirmation before a signal is drawn, rather than firing on the oscillator alone.
Originality
While each individual building block (Efficiency Ratio-based adaptive length, Fisher Transform, Z-Score normalization, pivot-based divergence) is a known technical-analysis concept, the specific combination here — an ER-adaptive stochastic whose Fisher-transformed output is Z-Score normalized, gated through a two-stage oscillator-then-price pivot confirmation sequence, and cross-checked against independent regular/hidden divergence logic, all rendered as overlay labels rather than a separate pane — is an original synthesis, not a copy of any single public script.
How to use
Green/Red "BUY"/"SELL" labels: statistically-confirmed lead signals (oscillator pivot + confirmed price pivot within the lag window).
"R-Bull"/"R-Bear" labels: regular divergence (potential reversal).
"H-Bull"/"H-Bear" labels: hidden divergence (potential trend continuation).
All lengths, thresholds, and lag windows are adjustable in the input groups.
Disclaimer
This script is a technical analysis tool, not financial advice. No indicator can guarantee profit or eliminate risk. Backtest and forward-test on your own instruments/timeframes before live use, and always apply independent risk management.
Overview
AF_StochZ Overlay is a price-chart (overlay) signal tool built on a statistically normalized, adaptive stochastic oscillator. Instead of plotting the oscillator in a separate pane, it converts the oscillator's extreme readings and divergences directly into labeled buy/sell markers on price, so traders can react to momentum-based signals without switching focus between panes.
How it works
Adaptive lookback (Efficiency Ratio): The stochastic lookback length is not fixed. It is calculated每 bar using Kaufman's Efficiency Ratio (ER), which compares net directional price change to total path traveled over erLen bars. When price moves efficiently (strong trend), the lookback contracts toward minLen for faster response; when price is choppy, the lookback expands toward maxLen to filter noise.
Stochastic → Fisher Transform: A standard %K stochastic is calculated over this adaptive length, smoothed, then rescaled to a ±1 range and passed through a Fisher Transform. The Fisher Transform sharpens turning points by converting a bounded oscillator into a signal with a more Gaussian (normal) distribution, making extremes statistically more distinct than a raw stochastic.
Z-Score normalization: The Fisher-transformed value is then normalized against its own rolling mean and standard deviation (zLen) to produce a Z-Score. This means overbought/oversold thresholds are expressed in standard deviations from the indicator's own recent behavior, rather than fixed 0–100 levels — the thresholds self-adjust to each instrument's and timeframe's own statistical character.
Lead-signal confirmation logic: A raw Z-Score pivot alone is not enough to fire a signal. The script requires the oscillator to pivot beyond the user-defined threshold, AND price itself to form a confirmed swing pivot (pricePivotL/pricePivotR) within a maximum bar lag (maxPriceLag) after that oscillator pivot. Only when both conditions line up in sequence does a BUY/SELL label print. This two-stage confirmation is designed to reduce the false positives that pure oscillator-crossing signals typically generate.
Regular & hidden divergence detection: Independently of the lead signals, the script scans a configurable lookback window (divLookbackMin–divLookbackMax) for regular divergence (price extreme vs. oscillator extreme disagreement, signaling potential reversal) and hidden divergence (signaling potential trend continuation), comparing confirmed price pivots against the Z-Score oscillator at the same pivots.
What problem it solves
Classic stochastic oscillators use a fixed lookback and fixed 0–100 overbought/oversold bands, which makes them lag in trending markets and whipsaw in choppy ones, and their thresholds are not adapted to the volatility regime of the specific instrument being traded. AF_StochZ Overlay addresses this by (a) adapting its own lookback to current market efficiency, (b) expressing overbought/oversold as a statistically self-calibrating Z-Score rather than an arbitrary fixed band, and (c) requiring price-action confirmation before a signal is drawn, rather than firing on the oscillator alone.
Originality
While each individual building block (Efficiency Ratio-based adaptive length, Fisher Transform, Z-Score normalization, pivot-based divergence) is a known technical-analysis concept, the specific combination here — an ER-adaptive stochastic whose Fisher-transformed output is Z-Score normalized, gated through a two-stage oscillator-then-price pivot confirmation sequence, and cross-checked against independent regular/hidden divergence logic, all rendered as overlay labels rather than a separate pane — is an original synthesis, not a copy of any single public script.
How to use
Green/Red "BUY"/"SELL" labels: statistically-confirmed lead signals (oscillator pivot + confirmed price pivot within the lag window).
"R-Bull"/"R-Bear" labels: regular divergence (potential reversal).
"H-Bull"/"H-Bear" labels: hidden divergence (potential trend continuation).
All lengths, thresholds, and lag windows are adjustable in the input groups.
Disclaimer
This script is a technical analysis tool, not financial advice. No indicator can guarantee profit or eliminate risk. Backtest and forward-test on your own instruments/timeframes before live use, and always apply independent risk management.
Notes de version
Practical Tips Based on Code LogicAlways Use the Trend Filter (Use Trend Filter):
The script relies on oscillator-based overbought/oversold logic. In strong trending markets (e.g., aggressive bull runs), oscillators can continuously trigger false "SELL" signals.
By enabling Use Trend Filter = true, you focus strictly on BUY signals when price is above the 200 EMA, and SELL signals when price is below it.
Confirm with Divergence:
Your script plots R-Bull / H-Bull (Regular / Hidden Bullish Divergence) labels.
Combined signals—such as a "BUY + R-Bull" combination—statistically offer the highest win-rate setups compared to standalone signals.
Mind the Confirmation Lag:
Because pricePivotR is set to 2, signals appear on the chart 2 bars after the pivot occurs. This is not a repaint issue; it is a mandatory mechanism to confirm a pivot low or high. Enter the trade on the bar closure with your stop loss placed just below/above the confirmed pivot bar.
Quick Summary
Crypto / Forex (High Volatility): Use 15m - 1H charts with default parameters, setting Use Trend Filter = true and Require %K/%D Confirmation = true.
Stocks / Equities (Strong Trend Bias): Use 1H - 4H - Daily charts with threshold levels tightened to -1.5 / +1.5 to catch major macro swings.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.