Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
Kalman Velocity Trend is a trend-pullback strategy built around a 2-state Kalman filter, a recursive estimation technique borrowed from aerospace and signal processing that separates a noisy signal into its underlying state and rate of change. Rather than relying on a conventional moving average — which only produces a smoothed price level and infers its slope with lag — this strategy estimates two hidden quantities of the market at once: a filtered level (the market's "fair" price) and a velocity (how fast that price is changing per bar). The velocity term is the heart of the approach: it is a directly-estimated, noise-reduced measure of trend slope that can turn before a lagging moving-average slope does.
The strategy is designed for trending market conditions with periodic pullbacks. It uses the sign of the estimated velocity to decide which direction it is allowed to trade, and it waits for price to dip back toward the filtered level and then reclaim it before entering. In other words, it is built to buy dips inside uptrends and sell rallies inside downtrends, rather than chasing extended moves. When velocity is small — a flat, directionless market — the strategy simply stays out.
As a learning tool, Kalman Velocity Trend suits traders who want to move beyond simple moving-average crossovers and understand how state-space filtering can be applied to price. It is a clean, single-timeframe example of noise-adaptive estimation: every noise setting is expressed as a fraction of the Average True Range (ATR), so the same parameters adapt to each symbol's own volatility. This makes it a useful study piece for anyone curious about adaptive filters, regime detection, and disciplined pullback entries.
How It Works
The strategy processes one completed candle at a time on your chosen timeframe. On each newly closed bar it updates the Kalman filter, checks whether a trend and a pullback are both present, and then manages positions accordingly.
- Filter update (predict + measure): The filter assumes a constant-velocity model — it predicts the next level by adding the current velocity, then corrects that prediction using the latest closing price as a noisy measurement. The correction strength (the Kalman gain) is computed automatically from the running estimate of uncertainty.
- Volatility auto-scaling: Both the process-noise and measurement-noise settings are expressed as fractions of ATR. This means the filter's responsiveness scales with the instrument's own volatility, so the parameters behave sensibly across different pairs and timeframes without manual re-tuning.
- Trend gate: The strategy only considers a side when the absolute estimated velocity exceeds
VelThreshFrac × ATR. The drift must be a meaningful fraction of one bar's typical noise before the market is judged to be trending. The sign of velocity sets the only side allowed — positive velocity permits longs, negative velocity permits shorts. - Pullback reclaim entry (long): In an up regime, the strategy signals a long when price had closed below the filtered level on the prior bar and the current bar closes back above it. This represents a pullback into the trend that then resumes.
- Pullback reclaim entry (short): The mirror image — in a down regime, price had closed above the filtered level and the current bar closes back below it.
- Reversal handling: If a fresh signal appears opposite to an open position, the strategy closes the existing position first and then opens the new one. Only one position per magic number is held at a time; if a same-side position already exists, no new order is added.
- Stop-loss logic: On entry, the stop is placed at
AtrSlMult × ATRaway from the fill price — below entry for longs, above entry for shorts. Because it is ATR-based, the stop widens in volatile conditions and tightens in calm ones. - Take-profit logic: The target is set at
AtrTpMult × ATRin the direction of the trade. With the defaults (stop 2× ATR, target 3× ATR), the strategy aims for a reward-to-risk ratio of roughly 1.5:1.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| ProcNoiseFrac | 0.10 | 0.02 | 0.50 | Process-noise sigma as a fraction of ATR. Larger values make the filter trust its own model less and react faster to price, producing a more responsive velocity estimate. |
| MeasNoiseFrac | 1.00 | 0.25 | 3.00 | Measurement-noise sigma as a fraction of ATR. Larger values make the filter trust each closing price less and smooth harder, producing a steadier but slower velocity. |
| VelThreshFrac | 0.05 | 0.00 | 0.30 | Trend gate. The required absolute velocity, as a fraction of ATR, before any trade is allowed. Higher values demand a stronger trend before acting. |
| AtrPeriod | 14 | 7 | 30 | Length of the ATR used for noise scaling, the trend gate, and stop/target distances. |
| AtrSlMult | 2.0 | 1.0 | 5.0 | Stop-loss distance as a multiple of ATR (entry −/+ AtrSlMult × ATR). |
| AtrTpMult | 3.0 | 1.0 | 8.0 | Take-profit distance as a multiple of ATR (entry +/− AtrTpMult × ATR). |
| Lots | 0.10 | 0.01 | 1.0 | Fixed lot size used for each position. |
The strategy also uses a Magic number (default 4130) to identify and manage only its own positions, keeping it isolated from manual trades or other Expert Advisors on the same account.

Recommended Chart Settings
Kalman Velocity Trend is a single-timeframe strategy: every calculation uses the chart's own timeframe, so it runs on whatever timeframe you attach it to. A common starting point for study is a major forex pair such as EUR/USD on the H1 (1-hour) timeframe, which offers reasonable liquidity and enough trend structure for the pullback logic to be meaningful. The ATR-based noise scaling means the same defaults can be explored across other liquid pairs and timeframes as well.
Because the filter and its noise settings adapt to each instrument's volatility, no per-symbol re-tuning of raw variances is strictly required. That said, results will vary considerably across different symbols, sessions, and market conditions. Always test any configuration on historical data and a demo account before drawing conclusions.
How to Install on MetaTrader 5
- Download the
.ex5file from the link below. - Copy it to your MT5
MQL5\Expertsfolder. - Restart MetaTrader 5 or refresh the Navigator panel.
- Drag the EA onto a chart matching the recommended symbol and timeframe.
- Configure the input parameters and enable Algo Trading.
What to Consider Before Using This EA
Strengths. The main advantage of this approach is that velocity is estimated directly rather than inferred from a lagging moving-average slope, so the trend gate can respond earlier and more cleanly. The pullback-reclaim entry adds discipline: it favours entering on retracements into a trend rather than chasing extension, which historically tends to improve entry location. The ATR-based noise scaling and stops give the strategy a degree of built-in adaptability across instruments, and the small, broadly-ranged parameter set reduces the temptation to over-fit.
Limitations. Like all trend-following logic, Kalman Velocity Trend can struggle in range-bound or choppy markets, where velocity flickers around the threshold and pullback reclaims produce whipsaw entries that are quickly stopped out. The constant-velocity model assumes trends persist in a roughly linear fashion; sharp reversals, gaps, or news-driven spikes can violate that assumption and produce late exits. Fixed-lot sizing does not scale risk to account equity, and the fixed ATR take-profit may cut winning trends short during strong, extended moves. It is also a fully mechanical system with no news filter or session filter.
Treat this EA as an educational framework for studying state-space filtering and pullback entries — not as a finished, ready-to-deploy product. Understanding why it enters and exits is far more valuable than the raw signals themselves.
Risk Management Tips
- Size positions conservatively. A widely-taught guideline is to risk no more than 1–2% of your account on any single trade. Because this EA uses fixed lots, you may need to adjust the
Lotsinput to keep per-trade risk within that band for your account size and the ATR-based stop distance. - Understand drawdown. Even a sound strategy will experience losing streaks. Review the maximum historical drawdown and ask yourself whether you could tolerate that decline without abandoning the plan.
- Start on a demo account. Run the strategy in a simulated environment until you understand its behaviour across trending, ranging, and volatile conditions before considering any live capital.
- Respect the stop-loss. The ATR-based stop is central to the strategy's risk profile. Disabling or widening it removes the protection the logic is built around.
- Diversify and avoid over-leverage. Concentrating capital in one strategy or one instrument, or using excessive leverage, amplifies both outcomes. Keep leverage modest and expectations realistic.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: KalmanVelocityTrend.ex5 (30 downloads)
- Source Code: KalmanVelocityTrend.mq5 (31 downloads)
- Documentation: KalmanVelocityTrend.pdf (33 downloads)