OPEN-SOURCE SCRIPT
Adaptive Probability Zone Projector [APZ]

Adaptive Probability Zone Projector [APZ] — Kinetic Log Engine
What this is in plain English: APZ plots a physics-based forecast of where price is likely to go and how far, using the strength and acceleration of the current trend. It shows you a projected path, a destination zone, and tracks its own accuracy in real time so you always know if it's earning your trust.
What this is in precise terms: A confirmed-bar, non-repainting directional forecast engine combining a 2-state Kalman filter with log-space linear regression to produce continuous-return velocity and acceleration estimates. Projections are kinematically bounded by timeframe-aware percent caps, with self-calibrating destination zones derived from a live MAE feedback loop. Gate logic uses a 6-component confluence score including R² adaptive thresholding, Nadaraya-Watson kernel crossover freshness, HTF slope alignment, and volatility Z-score suppression.
How It Works
Price moves like a physical object. It has momentum (how fast it is moving) and acceleration (whether that momentum is building or fading). APZ measures both — in percentage terms, so a 2% move per bar means the same thing on a $10 stock as on a $50,000 asset — then projects where that motion carries price over your chosen time horizon.
The gate is selective by design. The indicator does not produce a forecast on every bar. It waits until six independent conditions align: macro and micro trend in agreement, R² confidence above the adaptive threshold, positive momentum delta, meaningful velocity relative to volatility, healthy volatility environment, and optional kernel crossover confirmation. When fewer than four of those are true, the indicator goes quiet and grays the candles. That silence is information.
The destination zone is live-calibrated. After every forecast that expires, the indicator measures how far off its terminal price was. It updates an error EMA that directly controls how wide the next zone is drawn. If recent forecasts have been accurate, zones stay tight. If the market has been chaotic, zones widen automatically. You never have to tune zone width manually — the indicator calibrates itself.
What You See on the Chart
The curved path is the projected price trajectory from the current bar forward. It follows kinematic decay — momentum gradually softens as the path extends, because sustained acceleration is rare. The path always respects directional bias — a bull forecast will never curve downward.
The destination zone (box) is the probability range at the end of the horizon. Price has historically landed inside this box roughly 50–60% of the time on gated signals. The zone is built from actual measured forecast error, not from ATR guesswork.
The Gaussian channel (the wide band) shows where price sits relative to long-run trend structure. It provides macro context for every forecast.
The kernel lines (the glowing overlay) show the fast and slow Nadaraya-Watson trend estimates. Their crossover is one of the gate conditions. They also change color with momentum strength.
Gate markers (▲ / ▼ / ✕) appear on the chart at every gate open and gate close. They tell you exactly when the indicator's conditions were met and when they broke down.
The HUD (table, top right) shows live statistics including the current state, signal integrity score, projected velocity and acceleration in percent terms, forecast price, destination zone boundaries, adaptive horizon length, and — critically — live performance tracking: direction hit rate, zone touch rate, zone close rate, mean absolute error, and mean adverse excursion.
Timeframe Guide
5-minute / 15-minute: Works correctly. Projection horizon caps at 12 bars (60–180 minutes forward). For cleaner baseline behavior, reduce ALMA Length from the default 55 down to 20–25 bars. Gate is selective — expect signals during strong intraday trends only.
1-hour: The primary design timeframe for default settings. 55-bar ALMA covers roughly 2.3 days of trend context. 12-bar horizon = 12 hours forward. Velocity cap of 1.2%/bar is calibrated for 1H equity and crypto behavior. Most users will find 1H the most intuitive experience.
4-hour: Excellent. 10-bar horizon cap projects approximately 1.7 trading days forward. 2%/bar velocity cap. freshCross gate remains active on 4H, so mid-trend entries may be suppressed — disable "Require Fresh Kernel Cross" if you want more signals in continuation trends.
Daily: Best timeframe for this indicator at default settings. 8-bar horizon = 8 trading days. 3%/day velocity cap is historically calibrated. HTF Realism Mode automatically disables the freshCross requirement on daily, so mid-trend entries work naturally.
Weekly: Dramatically improved in the log-space architecture. Prior versions produced absurd projected moves on weekly charts. This version caps weekly projections at 24% total move (higher for crypto) with a 6-bar maximum horizon. freshCross is auto-disabled in HTF Realism Mode. Weekly forecasts now look conservative, bounded, and believable.
Monthly: 3-bar maximum horizon, 20% total cap (equities), 50% total cap (crypto). Designed for macro positioning context rather than precise entry. freshCross disabled. Velocity at 5%/month corresponds to roughly 60% annualized — historically calibrated for trending assets.
Who This Is For
If you are a directional trader: Use the gate markers to know when a qualified trend signal exists. Use the forecast and zone as a target framework, not a guarantee. When the gate closes (✕), step aside.
If you are a systematic or algorithmic trader: The JSON alert payload on every gate event includes score, R², gate threshold, horizon, velocity, acceleration, forecast, zone bounds, and all live performance metrics. The alert fires once per bar close on confirmed bars only — no intrabar noise.
If you are a risk manager: The destination zone gives you a probability-weighted price range at horizon expiry. Mean adverse excursion (tracked live in the HUD) tells you how much drawdown gated signals have historically experienced before recovering. Use it to size positions.
If you are a researcher: Turn on archived forecasts to see past projection paths overlaid on realized price. The HUD shows live direction accuracy, zone touch rate, and mean absolute error in real time. This indicator shows you whether it is working on your instrument and timeframe — there is no hiding behind back-test cherry-picks.
What This Is Not
This is not a buy/sell signal generator. The gate opening is a regime signal — it means conditions are aligned for a directional move. It is not a guarantee. Markets can and will invalidate forecasts. The tracker shows you this honestly.
This is not optimized for any single asset. The log-space percent architecture means the math is consistent across a $5 stock, a $500 stock, Bitcoin, EUR/USD, and the S&P 500. The caps are calibrated by timeframe, not by instrument.
This is not a repainting indicator. All signals, forecasts, and gate events are computed on confirmed bar closes only. What you see on a closed bar will not change.
Technical Architecture (For Advanced Users)
Macro layer: ALMA baseline with Gaussian standard deviation bands. Macro slope computed as EMA of first difference of baseline.
Micro layer: Dual Nadaraya-Watson kernel regression (fast + slow bandwidth) with R²-weighted blending. Predictive R² measured by correlating prior-bar kernel estimate against current price to avoid circularity.
Kalman filter: 2-state (position + velocity) constant-velocity model operating in log-price space. Advances on confirmed bar closes only. Initialized to log(close) on bar 1.
Velocity engine: Kalman velocity blended with log-space linear regression slope. Result is a continuous log-return per bar.
Acceleration engine: Rate of change of blended velocity over lookback window, decayed geometrically per step.
Projection: Kinematic integration in log space with per-step velocity and acceleration clamping. Total cumulative log-return capped by timeframe-aware percent ceiling. Path converted to price via exp() for display only.
Zone: Half-width computed as EMA(log-return error) × sqrt(horizon), clamped to timeframe-specific percent floor and ceiling.
Gate: Six-component binary confluence score ≥ threshold, alignment persistence, optional kernel freshness, optional HTF slope agreement, and volatility Z-score within range.
Tracker: Per-signal tracking of direction, zone touch (checked on every confirmed bar during window), zone close, final MAE, worst-path MAE, max adverse and favorable excursion. Error EMA feeds back into zone sizing.
What this is in plain English: APZ plots a physics-based forecast of where price is likely to go and how far, using the strength and acceleration of the current trend. It shows you a projected path, a destination zone, and tracks its own accuracy in real time so you always know if it's earning your trust.
What this is in precise terms: A confirmed-bar, non-repainting directional forecast engine combining a 2-state Kalman filter with log-space linear regression to produce continuous-return velocity and acceleration estimates. Projections are kinematically bounded by timeframe-aware percent caps, with self-calibrating destination zones derived from a live MAE feedback loop. Gate logic uses a 6-component confluence score including R² adaptive thresholding, Nadaraya-Watson kernel crossover freshness, HTF slope alignment, and volatility Z-score suppression.
How It Works
Price moves like a physical object. It has momentum (how fast it is moving) and acceleration (whether that momentum is building or fading). APZ measures both — in percentage terms, so a 2% move per bar means the same thing on a $10 stock as on a $50,000 asset — then projects where that motion carries price over your chosen time horizon.
The gate is selective by design. The indicator does not produce a forecast on every bar. It waits until six independent conditions align: macro and micro trend in agreement, R² confidence above the adaptive threshold, positive momentum delta, meaningful velocity relative to volatility, healthy volatility environment, and optional kernel crossover confirmation. When fewer than four of those are true, the indicator goes quiet and grays the candles. That silence is information.
The destination zone is live-calibrated. After every forecast that expires, the indicator measures how far off its terminal price was. It updates an error EMA that directly controls how wide the next zone is drawn. If recent forecasts have been accurate, zones stay tight. If the market has been chaotic, zones widen automatically. You never have to tune zone width manually — the indicator calibrates itself.
What You See on the Chart
The curved path is the projected price trajectory from the current bar forward. It follows kinematic decay — momentum gradually softens as the path extends, because sustained acceleration is rare. The path always respects directional bias — a bull forecast will never curve downward.
The destination zone (box) is the probability range at the end of the horizon. Price has historically landed inside this box roughly 50–60% of the time on gated signals. The zone is built from actual measured forecast error, not from ATR guesswork.
The Gaussian channel (the wide band) shows where price sits relative to long-run trend structure. It provides macro context for every forecast.
The kernel lines (the glowing overlay) show the fast and slow Nadaraya-Watson trend estimates. Their crossover is one of the gate conditions. They also change color with momentum strength.
Gate markers (▲ / ▼ / ✕) appear on the chart at every gate open and gate close. They tell you exactly when the indicator's conditions were met and when they broke down.
The HUD (table, top right) shows live statistics including the current state, signal integrity score, projected velocity and acceleration in percent terms, forecast price, destination zone boundaries, adaptive horizon length, and — critically — live performance tracking: direction hit rate, zone touch rate, zone close rate, mean absolute error, and mean adverse excursion.
Timeframe Guide
5-minute / 15-minute: Works correctly. Projection horizon caps at 12 bars (60–180 minutes forward). For cleaner baseline behavior, reduce ALMA Length from the default 55 down to 20–25 bars. Gate is selective — expect signals during strong intraday trends only.
1-hour: The primary design timeframe for default settings. 55-bar ALMA covers roughly 2.3 days of trend context. 12-bar horizon = 12 hours forward. Velocity cap of 1.2%/bar is calibrated for 1H equity and crypto behavior. Most users will find 1H the most intuitive experience.
4-hour: Excellent. 10-bar horizon cap projects approximately 1.7 trading days forward. 2%/bar velocity cap. freshCross gate remains active on 4H, so mid-trend entries may be suppressed — disable "Require Fresh Kernel Cross" if you want more signals in continuation trends.
Daily: Best timeframe for this indicator at default settings. 8-bar horizon = 8 trading days. 3%/day velocity cap is historically calibrated. HTF Realism Mode automatically disables the freshCross requirement on daily, so mid-trend entries work naturally.
Weekly: Dramatically improved in the log-space architecture. Prior versions produced absurd projected moves on weekly charts. This version caps weekly projections at 24% total move (higher for crypto) with a 6-bar maximum horizon. freshCross is auto-disabled in HTF Realism Mode. Weekly forecasts now look conservative, bounded, and believable.
Monthly: 3-bar maximum horizon, 20% total cap (equities), 50% total cap (crypto). Designed for macro positioning context rather than precise entry. freshCross disabled. Velocity at 5%/month corresponds to roughly 60% annualized — historically calibrated for trending assets.
Who This Is For
If you are a directional trader: Use the gate markers to know when a qualified trend signal exists. Use the forecast and zone as a target framework, not a guarantee. When the gate closes (✕), step aside.
If you are a systematic or algorithmic trader: The JSON alert payload on every gate event includes score, R², gate threshold, horizon, velocity, acceleration, forecast, zone bounds, and all live performance metrics. The alert fires once per bar close on confirmed bars only — no intrabar noise.
If you are a risk manager: The destination zone gives you a probability-weighted price range at horizon expiry. Mean adverse excursion (tracked live in the HUD) tells you how much drawdown gated signals have historically experienced before recovering. Use it to size positions.
If you are a researcher: Turn on archived forecasts to see past projection paths overlaid on realized price. The HUD shows live direction accuracy, zone touch rate, and mean absolute error in real time. This indicator shows you whether it is working on your instrument and timeframe — there is no hiding behind back-test cherry-picks.
What This Is Not
This is not a buy/sell signal generator. The gate opening is a regime signal — it means conditions are aligned for a directional move. It is not a guarantee. Markets can and will invalidate forecasts. The tracker shows you this honestly.
This is not optimized for any single asset. The log-space percent architecture means the math is consistent across a $5 stock, a $500 stock, Bitcoin, EUR/USD, and the S&P 500. The caps are calibrated by timeframe, not by instrument.
This is not a repainting indicator. All signals, forecasts, and gate events are computed on confirmed bar closes only. What you see on a closed bar will not change.
Technical Architecture (For Advanced Users)
Macro layer: ALMA baseline with Gaussian standard deviation bands. Macro slope computed as EMA of first difference of baseline.
Micro layer: Dual Nadaraya-Watson kernel regression (fast + slow bandwidth) with R²-weighted blending. Predictive R² measured by correlating prior-bar kernel estimate against current price to avoid circularity.
Kalman filter: 2-state (position + velocity) constant-velocity model operating in log-price space. Advances on confirmed bar closes only. Initialized to log(close) on bar 1.
Velocity engine: Kalman velocity blended with log-space linear regression slope. Result is a continuous log-return per bar.
Acceleration engine: Rate of change of blended velocity over lookback window, decayed geometrically per step.
Projection: Kinematic integration in log space with per-step velocity and acceleration clamping. Total cumulative log-return capped by timeframe-aware percent ceiling. Path converted to price via exp() for display only.
Zone: Half-width computed as EMA(log-return error) × sqrt(horizon), clamped to timeframe-specific percent floor and ceiling.
Gate: Six-component binary confluence score ≥ threshold, alignment persistence, optional kernel freshness, optional HTF slope agreement, and volatility Z-score within range.
Tracker: Per-signal tracking of direction, zone touch (checked on every confirmed bar during window), zone close, final MAE, worst-path MAE, max adverse and favorable excursion. Error EMA feeds back into zone sizing.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.