Kalman Trend Levels Indicator: Two Kalman Filters, One Chart

Written by Dominic Walsh · Published · Last updated

The kalman trend levels indicator smooths price with a Kalman filter rather than a moving average. A Kalman filter weighs each new observation against how much it already trusts its own estimate, so it settles quickly after a real move and ignores small noise. Two filters run side by side at different trust settings, and where they cross the tool marks the bar.

This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Main price chart
Plots 4: Kalman Fast, Kalman Slow, Buy, Sell
Alerts popup
Inputs 6

What the Kalman Trend Levels Indicator draws on the chart

Kalman Fast traces the responsive estimate in dodger blue.

Kalman Slow traces the steadier estimate in orange.

Buy drops a lime arrow under the bar where the fast estimate crosses above the slow one.

Sell places a red arrow above the bar on the reverse cross.

  • Kalman Fast: line, dodger blue, width 2
  • Kalman Slow: line, orange, width 2
  • Buy: arrow, lime, width 2, arrow code 233
  • Sell: arrow, red, width 2, arrow code 234
Kalman trend levels indicator on EURUSD H1 with fast and slow filter lines and cross arrows
Kalman trend levels indicator on EURUSD H1 with fast and slow filter lines and cross arrows

How the Kalman Trend Levels Indicator calculates its values

What a scalar Kalman filter does each bar

Two numbers travel forward: s, the current estimate, and p, how uncertain that estimate is. Every bar takes meas from close[i]. The gain Kf comes out as pFast / (pFast + R), a ratio between the filter’s own uncertainty and the measurement noise `InpR`. Then the estimate moves by that fraction of the error: sFast += Kf * (meas – sFast). Finally pFast shrinks through (1.0 – Kf) * pFast, because the filter now trusts itself more.

Why two Q values give two speeds

Process noise decides how much the filter expects the underlying price to have moved on its own. `InpQFast` at `0.001` says a lot, so the fast filter keeps its uncertainty high and reacts. `InpQSlow` at `0.00001` says very little, so the slow filter holds its estimate and drifts. Both filters see identical prices. The gap between them comes entirely from those two constants.

Seeding and crossing

Both estimates start from close[oldestSeries] rather than zero, which stops a false line running across the early chart. `InpWarmup` then sets how many bars settle before output begins. Crossings compare BufFast and BufSlow one bar apart: crossUp needs BufFast[i+1] at or below BufSlow[i+1] with BufFast[i] above it. An arrow lands `InpArrowGap` points clear of the candle.

How to read the signals

Separation between the two lines is a rough measure of how far price has moved from its recent settled level.

The slow line barely bends. That is the design, not a fault, and it makes a good background reference.

Arrows come from the two estimates crossing, so they lag less than an equivalent moving average pair but still lag.

After a sharp move the fast line snaps back to price while the slow one takes many bars to follow.

Alert channels in this build: popup, one message per closed bar.

One channel is present, a terminal popup, driven by `InpAlerts` at its `true` default. Messages wait for the bar to close, so a cross that forms and unwinds inside a bar never reaches you. The guard permits a single message per closed bar.

Every Kalman Trend Levels Indicator input

Core settings

Setting What it does Default
InpQFast Fast Kalman process noise Q. Process noise for the responsive filter, default `0.001`. Larger values make Kalman Fast track price almost exactly. 0.001
InpQSlow Slow Kalman process noise Q. Process noise for the steady filter, default `0.00001`. Keep it well below the fast value or both lines converge. 0.00001
InpR Measurement noise R. Measurement noise, default `0.10`. Raising it tells both filters to distrust each new close, which smooths everything. 0.10
InpWarmup Warmup bars. Bars allowed to settle before output starts, default `5`. 5

Display settings

Setting What it does Default
InpArrowGap Arrow gap (points). Distance between candle and arrow, default `25` points. 25

Alert settings

Setting What it does Default
InpAlerts Closed-bar alerts. on
Kalman trend levels indicator inputs: InpQFast, InpQSlow and InpR
Kalman trend levels indicator inputs: InpQFast, InpQSlow and InpR

Settings that fit your chart

Kalman smoothing suits instruments where noise and signal genuinely differ in scale, which describes the majors on H1 and H4. EURUSD H1 is the reference chart. On very fast charts the measurement noise swamps the process, and both filters spend their time chasing spread. On the daily the slow filter with a Q of 0.00001 becomes nearly a straight line across months.

When the Kalman Trend Levels Indicator fails

The filter assumes noise is roughly constant. A volatility regime change breaks that assumption, and the estimates lag until the uncertainty term catches up.

Two smoothed lines crossing is still a crossover signal, and it whipsaws in ranges exactly like a moving average pair.

The Q and R values are unitless here rather than scaled to the instrument, so a setting tuned on EURUSD behaves differently on gold without adjustment.

Copy the compiled Kalman Trend Levels Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.

Download the Kalman Trend Levels Indicator for MT4 and MT5

The zip holds the compiled Kalman Trend Levels Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.

Download this indicator free

Enter your email and the file is yours. You also get the full MT4 and MT5 library.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

What does InpR actually control?

Measurement noise: how much the filter distrusts each incoming close. It appears in the gain as pFast / (pFast + R). A larger `InpR` shrinks the gain, so each new price moves the estimate less and both lines smooth out. The default `0.10` keeps the fast filter responsive without letting single ticks drag it around.

Why is InpQSlow so much smaller than InpQFast?

Because that ratio is what separates the two lines. Process noise tells the filter how much it expects price to have drifted by itself. `InpQFast` at `0.001` keeps uncertainty high so the estimate keeps moving. `InpQSlow` at `0.00001` is a hundred times smaller, so that filter settles and holds. Same prices, different willingness to change.

Is Kalman Fast just an exponential moving average?

Not quite, though they behave similarly. An EMA applies a fixed weight to every new price. A Kalman filter recalculates its gain each bar from its own accumulated uncertainty, so the weighting adapts. In a long quiet stretch the gain falls and the line steadies, which a fixed-alpha average never does.

What does InpWarmup at 5 do?

It holds back output for the first few bars while both estimates settle from their seed value. Both start at close[oldestSeries] rather than zero, which already avoids the worst artefact. The warmup simply gives the uncertainty term a few bars to reach a sensible level before anything gets drawn.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Kalman Trend Levels Indicator as one input. Always backtest before trading live.

Category: this is part of our Trend collection. Also, truly, browse more Trend for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment