Help ›

Strategy Lab: Trend filter, animated

The trend filter lets a buy signal through only when the bigger trend agrees. It has two questions. First: is the close above its average on a longer time frame? Then, if you ask for it: is that average itself going up? The pictures below play both, step by step. You find the filter on the Algo Brain page under Entry filters to try, and in the Signal Backtest under step 2's filters.

the trend average the newest closed candle the average N candles ago

The candles are made up for the pictures (4H candles, EMA 20). The two checks are worked out from them the same way the system checks real candles.

1. The close above its average

On the Algo Brain, Trend filter is on or off: each idea gets its trend time frame from its own (the table below). In the Signal Backtest you pick the longer time frame yourself (15m, 1H, 4H, 1D or 1W). Trend average picks the moving average. When a buy signal comes, the filter looks at the newest longer candle that has already closed. If its close is above the average, the signal goes on. If it is below, or exactly equal, the signal is skipped: no trade.

Close above the averageTrade taken
Close below the averageSignal skipped

Its time frame must be longer than the idea's. The filter's job is to ask about the bigger picture. On the idea's own candles it would mostly repeat what the buy signal already says. The Algo Brain takes the shortest trend time frame at least 4 times longer than the idea's:

Idea's time frameTrend filter on
1m to 3m15m
5m, 15m1H
30m, 1H4H
2H, 4H1D
1D1W
1Wnone: the idea runs without the filter

To ask about the price and an average on the idea's own candles, use a condition of the idea instead, for example Crosses above average.

The trend average. A short average follows the price closely and turns often. A long one is steadier and turns late. On 4H candles, EMA 12 (the one picked unless you choose another) covers about 2 days, EMA 20 about 3 days and EMA 50 about 8 days. SMA 200 on 1D is the long-term trend of most charts.

If there are too few candles yet to work out the average, the signal is skipped. The filter never looks ahead: it only uses longer candles that had closed when the signal came.

2. Trend average rising over (candles)

Empty, only the first question is asked. With a number N, the average itself must also be higher than it was N trend candles before. On 4H, 3 means higher than 12 hours ago. Equal counts as not rising. Both answers must be yes.

Price above, average risingTrade taken

The close is above the average, and the average is higher than 3 candles ago. A real uptrend.

Price above, but average fallingSignal skipped

One strong candle jumped above a falling average. The first question alone lets this through. The rising check stops it: this is often a short bounce inside a downtrend.

Average rising, but price belowSignal skipped

The average is still going up, but the newest close fell under it. The first question already says no.

Try it: the average has only just turned up

Change N and watch the look-back point
Rising over

The average fell for days, then turned up 3 candles ago. A small N looks only a short way back, so it already counts as rising. A larger N reaches back to before the turn, when the average was higher, so the signal is skipped until the uptrend has lasted longer.

NEffect
1 to 2Quick: any small uptick of the average counts.
3 to 5Balanced: the average must have climbed for a while.
6 to 20Strict: fewer trades, only in a long, steady uptrend.

3. Did the filter stop my idea?

The filter never fails an idea by itself: it only removes buy signals before any trade is made. An idea fails on what is left, for example too few trades on the unseen part, or trades that lose.

The Signals column. In an idea's four gates, every variant's row has a Signals column that counts what each entry filter removed, in the order they are asked, for example 52 signals, close under the trend average -31, trend average not rising -9: 12 left, 8 trades. Signals left can be more than trades: a signal that comes while a trade is still open makes no new trade. A variant tested before this count was added shows "-" until it is tested again.

The twin test. Keep Also try without the trend filter ticked: the Brain then tests every idea twice, with and without the filter. Compare the two:

Without the filterWith the filterWhat it means
Many trades, losesFewer trades, winsThe filter helps: the rule was buying against the trend.
Enough tradesToo few tradesThe filter caused the failure: it removed almost every signal. Try a shorter average, a smaller N or a shorter time frame.
LosesLosesThe rule itself is weak, not the filter.
WinsLosesThe filter removed the good trades.