Skip to content

Free MT5 indicator

KAMA Trend Filter

Kaufman adaptive moving average for MT5 coloured by trend state, using the efficiency ratio to separate trending from ranging markets.

Trendv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Alerts

What it does

KAMA Trend Filter draws Perry Kaufman's adaptive moving average and colours it in three states: green for an efficient uptrend, red for an efficient downtrend and grey when price is moving without much direction. Arrows mark the closed bar on which a new green or red state begins.

The aim is a single line that speeds up when the market trends cleanly and slows almost to a halt when the market chops, so it doubles as a trend filter for other signals.

How it works

  1. Efficiency ratio (ER) = |close − close n bars ago| ÷ sum of |close − previous close| over the same n bars. It is 1 when every bar moved the same way and close to 0 in noisy, back-and-forth trading.
  2. Smoothing constant = (ER × (fast SC − slow SC) + slow SC)², where fast SC = 2 ÷ (2 + 1) and slow SC = 2 ÷ (30 + 1) with the default inputs.
  3. KAMA = previous KAMA + smoothing constant × (close − previous KAMA).
  4. Trend state: if ER is at or above the threshold (0.30) and KAMA is higher than it was 3 bars ago, the state is up. If ER passes the threshold and KAMA is lower, the state is down. Otherwise the state is range.

An arrow is drawn when a closed bar's state changes to up or down from anything else.

How to use it

  • Use the colour as a permission filter. Look for long setups from another method only while the line is green, and short setups only while it is red.
  • Grey periods are a warning that the market is not trending efficiently. Many traders reduce size or stand aside then, or switch to range tactics around support and resistance.
  • Because KAMA flattens in noise, price crossing a flat grey line means little. A crossing that comes with a colour change is more informative.
  • Raising the ER threshold gives fewer, more selective trend states. Lowering it colours more of the chart.
  • It is well suited to H1 to D1 on currency pairs, gold and indices.

Settings

InputDefaultWhat it changes
Efficiency ratio length10Window for measuring trend efficiency; longer is steadier
Fast smoothing length2How quickly KAMA follows price in strong trends
Slow smoothing length30How slowly KAMA moves in noise
Minimum efficiency ratio0.30Threshold between trend and range colouring
Bars used to measure slope3Sensitivity of the up/down decision
Pop-up alert / Push notificationfalse / falseOne alert per closed bar on a new trend state

Limitations

  • The efficiency ratio is calculated on closing prices only, so large wicks are ignored.
  • State changes can flicker around the threshold when ER hovers near 0.30.
  • KAMA still lags at turning points, especially after a long efficient trend when it has caught up closely with price.
  • The live bar's colour can change until the bar closes; arrows and alerts are confirmed on the close and stay fixed.
  • This is an educational filter, not a complete strategy. Trading involves substantial risk of loss.

Key inputs

Key inputs of KAMA Trend Filter
InputDefaultDescription
Efficiency ratio length10Bars used to measure how directional price movement is.
Fast smoothing length2EMA-equivalent length used when the market is perfectly efficient.
Slow smoothing length30EMA-equivalent length used when the market is pure noise.
Minimum efficiency ratio to call a trend0.30Below this value the line is grey and the market is treated as ranging.
Bars used to measure KAMA slope3Compares KAMA with its value this many bars ago to decide direction.
Pop-up alert on new trend statefalseAlerts once when a closed bar starts a new up or down state.

Educational tools, not advice. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 indicators