OPEN-SOURCE SCRIPT

Kalman Adjusted Average True Range [BackQuant]

362
Kalman Adjusted Average True Range [BackQuant]
A volatility-aware trend baseline that fuses a Kalman price estimate with ATR “rails” to create a smooth, adaptive guide for entries, exits, and trailing risk.

Built on my original Kalman
This indicator is based on my original Kalman Price Filter:
Kalman Price Filter [BackQuant]

That core smoother is used here to estimate the “true” price path, then blended with ATR to control step size and react proportionally to market noise.

What it plots
  • Kalman ATR Line the main baseline that turns up/down with the filtered trend.
  • Optional Moving Average of the Kalman ATR a secondary line for confluence (SMA/Hull/EMA/WMA/DEMA/RMA/LINREG/ALMA).
  • Candle Coloring (optional) paint bars by the baseline’s current direction.


Why combine Kalman + ATR?
  • Kalman reduces measurement noise and produces a stable path without the lag of heavy MAs.
  • ATR rails scale the baseline’s step to current volatility, so it’s calm in chop and more responsive in expansion.
  • The result is a single, intelligible line you can trade around: slope-up = constructive; slope-down = caution.


How it works (plain English)
  • Each bar, the Kalman filter updates an internal state (tunable via Process Noise, Measurement Noise, and Filter Order) to estimate the underlying price.
  • An ATR band (Period × Factor) defines the allowed per-bar adjustment. The baseline cannot “jump” beyond those rails in one step.
  • A direction flip is detected when the baseline’s slope changes sign (upturn/downturn), and alerts are provided for both.


Typical uses
  • Trend confirmation Trade in the baseline’s direction; avoid fading a firmly rising/falling line.
  • Pullback timing Look for entries when price mean-reverts toward a rising baseline (or exits on tags of a falling one).
  • Trailing risk Use the baseline as a dynamic guide; many traders set stops a small buffer beyond it (e.g., a fraction of ATR).
  • Confluence Enable the MA overlay of the Kalman ATR; alignment (baseline above its MA and rising) supports continuation.


Inputs & what they do
Calculation
  • Kalman Price Source which price the filter tracks (Close by default).
  • Process Noise how quickly the filter can adapt. Higher = more responsive (but choppier).
  • Measurement Noise how much you distrust raw price. Higher = smoother (but slower to turn).
  • Filter Order (N) depth of the internal state array. Higher = slightly steadier behavior.


Kalman ATR
  • Period ATR lookback. Shorter = snappier; longer = steadier.
  • Factor scales the allowed step per bar. Larger factors permit faster drift; smaller factors clamp movement.


Confluence (optional)
  • MA Type & Period compute an MA on the Kalman ATR line, not on price.
  • Sigma (ALMA) if ALMA is selected, this input controls the curve’s shape. (Ignored for other MA types.)


Visuals
  • Plot Kalman ATR toggle the main line.
  • Paint Candles color bars by up/down slope.
  • Colors choose long/short hues.


Signals & alerts
  • Trend Up baseline turns upward (slope crosses above 0).
    Alert: “Kalman ATR Trend Up”
  • Trend Down baseline turns downward (slope crosses below 0).
    Alert: “Kalman ATR Trend Down”

These are state flips, not “price crossovers,” so you avoid many one-bar head-fakes.

How to start (fast presets)
  • Swing (daily/4H) ATR Period 7–14, Factor 0.5–0.8, Process Noise 0.02–0.05, Measurement Noise 2–4, N = 3–5.
  • Intraday (5–15m) ATR Period 5–7, Factor 0.6–1.0, Process Noise 0.05–0.10, Measurement Noise 2–3, N = 3–5.
  • Slow assets / FX raise Measurement Noise or ATR Period for calmer lines; drop Factor if the baseline feels too jumpy.

Reading the line
  • Rising & curving upward momentum building; consider long bias until a clear downturn.
  • Flat & choppy regime uncertainty; many traders stand aside or tighten risk.
  • Falling & accelerating distribution lower; short bias until a clean upturn.


Practical playbook
  • Continuation entries After a Trend Up alert, wait for a minor pullback toward the baseline; enter on evidence the line keeps rising.
  • Exit/reduce If long and the baseline flattens then turns down, trim or exit; reverse logic for shorts.
  • Filters Add a higher-timeframe check (e.g., only take longs when the daily Kalman ATR is rising).
  • Stops Place stops just beyond the baseline (e.g., baseline − x% ATR for longs) to avoid “tag & reverse” noise.

Notes
  • This is a guide to state and momentum, not a guarantee. Combine with your process (structure, volume, time-of-day) for decisions.
  • Settings are asset/timeframe dependent; start with the presets and nudge Process/Measurement Noise until the baseline “feels right” for your market.


Summary
Kalman ATR takes the noise-reduction of a Kalman price estimate and couples it with volatility-scaled movement to produce a clean, adaptive baseline. If you liked the original Kalman Price Filter (tradingview.com/script/3N2zym2w-Kalman-Price-Filter-BackQuant/), this is its trend-trading cousin purpose-built for cleaner state flips, intuitive trailing, and confluence with your existing

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.