Skip to content
All library documents

Kalman-Filtered Trend Following with Adaptive Stops and Loss-Based Sizing

Article TradingView scripts

Summary

This strategy applies a recursive Kalman-style filter to price and tracks a directional state. A stop line trails the filtered price at a percentage distance: it ratchets in the direction of the current trend and flips sides when the filter crosses it. The distance begins wider and gradually narrows toward a minimum, making the stop more responsive as a trend persists. Signals can enter long or short positions within a user-defined date window, with settings to enable either direction.

The script also adjusts order quantity and take-profit distances after an unprofitable outcome, multiplying them by configurable factors until a calculated order-size ceiling is reached. It then resets these values and increments a failure counter. Profit-taking can be split across three targets, with optional stop adjustments after earlier targets and an initial percentage stop. This loss-responsive sizing can increase exposure after losses; the code does not establish that it controls drawdown or improves returns. No performance results are supplied, and the strategy’s behavior depends on its state logic, inputs, instrument, and backtest assumptions.

Key ideas

  • The recursive filter combines price changes and a velocity term to estimate a smoothed trend.
  • A percentage stop follows the filter, tightening over time and switching sides when the trend state changes.
  • After a loss, the strategy can increase order size and widen target distances up to configured limits.
  • Three staged take-profit levels and optional protective stops manage partial exits.
  • The script provides configurable backtest dates but no evidence that its adaptive sizing is profitable or safe.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.