STRATEGY · UPDATED AUGUST 2026

Trend filter for TradingView alerts: only fire with the trend.

Most losing automated signals are not bad entries — they are good entries fired against the trend, inside chop. The cheapest upgrade to any TradingView strategy is a trend filter in Pine Script: a condition that must be true before the alert is even allowed to fire. These are the four filters that work, with a ready-to-paste Pine v5 example.

BBenjamin SF · Founder Published Aug 20, 2026 Read 6 min

The most expensive signal is a good entry in a dead market.

CHOP IS WHERE AUTOMATED STRATEGIES GO TO BLEED.

Pull the trade log of almost any automated TradingView strategy and the same pattern shows up: the system makes its money in a handful of trending weeks, then hands it back in the sideways stretches in between. Your crossover, your breakout, your RSI bounce — they all have a direction they work in. When the market has no direction, they keep firing anyway, and every counter-trend entry in a range is a coin flip with spread and commission stacked against it.

The fix is not a better entry. It is refusing to enter at all unless the market agrees with the trade. That is what a trend filter is: a boolean condition in your Pine Script — price above the EMA 200, the EMA rising, Supertrend bullish, ADX above 20-25 — that gates the signal. If the filter fails, the alert never fires, the webhook never sends, and your MT5 account never sees the trade. The boring trades you skip are exactly where the edge was leaking.

One honest caveat before the code: a filter does not create edge, it protects it. If the raw signal has no edge with the trend, filtering it will not save the strategy. What it reliably does is cut the worst 30-60% of trades — the counter-trend ones in chop — which is usually the difference between a system that survives a ranging month and one that does not.

THE TOOLBOX

Four trend filters that actually work.

You do not need all four. Pick one directional filter and, if you trade a choppy symbol, add the ADX floor on top. More than two or three filters stacked together stops being a filter and starts being a refusal to trade.

Filter → what it proves
Price vs EMA 200
Which side you are on. Longs only above the EMA 200, shorts only below. The oldest filter in the book, and still the default for a reason: it kills every counter-trend dip-buy in a downtrend.
EMA 200 slope
The side is moving. The EMA today must be higher than it was N bars ago for longs (lower for shorts). Catches the case where price sits above a flat, dead EMA — technically “bullish”, actually chop.
Supertrend direction
A reactive directional read. Only take longs while Supertrend is bullish and shorts while bearish. Slower to flip than price-vs-EMA, so it keeps you out of more whipsaws — at the cost of later entries.
ADX > 20-25
A trend exists at all. ADX has no direction — it only measures strength. Below 20 the market is ranging by definition and most entry signals are noise. The single best chop-killer of the four.

THE CODE

A complete example in Pine v5.

This is a generic EMA-crossover strategy with three of the filters wired in: price vs EMA 200, EMA 200 slope, and an ADX floor of 20. The entry logic is deliberately ordinary — the point is that rawLong / rawShort fire all the time, but the alert only fires when the filter agrees. Paste it into the Pine Editor, add it to a chart, and create the alerts on the two alertcondition calls.

Pine Editor · paste as-isPine v5
//@version=5
indicator("Trend-filtered signals", overlay=true)

// --- trend filter ---
emaTrend  = ta.ema(close, 200)
emaRising = emaTrend > emaTrend[3]
[diPlus, diMinus, adxVal] = ta.dmi(14, 14)

bull = close > emaTrend and emaRising and adxVal > 20
bear = close < emaTrend and not emaRising and adxVal > 20

// --- raw entry logic (replace with yours) ---
rawLong  = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
rawShort = ta.crossunder(ta.ema(close, 9), ta.ema(close, 21))

// --- the gate: signal only fires with the trend ---
longSignal  = rawLong and bull
shortSignal = rawShort and bear

plotshape(longSignal, style=shape.triangleup, location=location.belowbar, size=size.small)
plotshape(shortSignal, style=shape.triangledown, location=location.abovebar, size=size.small)

alertcondition(longSignal, "Long with trend", '{"action":"buy","symbol":"EURUSD","lot":0.10}')
alertcondition(shortSignal, "Short with trend", '{"action":"sell","symbol":"EURUSD","lot":0.10}')

Two details worth stealing. First, the alert message already carries the order payload, so the same condition that gates the arrow also gates the trade — there is no second place where an unfiltered signal can leak through. Second, notice what is not in the code: the filter never changes the stop, the target or the size. It only says yes or no. Keep it that way — a filter that also resizes your trades is a second strategy hiding inside the first.

If you want Supertrend instead of the EMA pair, swap the two filter lines for [st, dir] = ta.supertrend(3, 10) and use dir < 0 for bullish. Same gate, different referee.

FROM ALERT TO FILL

Wire the filtered alert to MT5.

Once the filter lives in Pine, the automation side gets simpler, not harder: fewer, better alerts hitting your execution. The webhook URL and alert message go into the TradingView alert dialog exactly as before — if you have not done that part yet, the full walkthrough is in our guide to connect TradingView to MT5, and the message-format details (including why the JSON in the alert matters) are in Pine Script alert webhooks.

SignalForge executes whatever alerts arrive — entries, pending orders, closes, SL/TP modifications — so the trend decision stays on the TradingView side, where your chart logic lives. What the bridge adds downstream is control of when and how big: a per-account time-window filter for the hours your strategy is allowed to trade, position sizing per account, multi-TP and trailing management on the MT5 side. The filter says which trades; the bridge decides the rest.

If you are still picking the execution layer, the honest comparison is in best TradingView to MT5 bridges and the shorter TradingView to MT5 bridge overview. SignalForge starts at $4.99/mo with a 14-day free trial, no card — plans and bundles are on the pricing page, and the connection guide gets a filtered alert executing in about ten minutes.

FAQ

Quick questions.

Email [email protected] if yours isn’t here.

What is a trend filter in TradingView?

+
A trend filter is a condition in your Pine Script that has to be true before an entry signal is allowed to fire. Typical filters: price above or below the EMA 200, the EMA 200 sloping in the trade direction, Supertrend pointing your way, or ADX above 20-25 to prove the market is trending at all. If the filter fails, the alert never fires.

Which trend filter is best: EMA 200, Supertrend or ADX?

+
They answer different questions. Price vs EMA 200 tells you which side of the market you are on, EMA slope tells you if that side is actually moving, Supertrend gives a reactive directional read, and ADX above 20-25 tells you whether there is a trend worth trading at all. Combining price-vs-EMA with an ADX floor covers most cases; adding more filters past two or three usually just starves the strategy of trades.

Will a trend filter reduce my number of trades?

+
Yes, that is the point. A trend filter typically cuts 30-60% of signals, and the ones it removes are concentrated in sideways chop where mean-reversion entries get run over. Fewer, better-aligned trades also means less spread and commission paid to the broker.

Can I filter alerts without editing Pine Script?

+
Only partly. Direction and trend conditions live in the Pine code, so the trend filter itself belongs there. Downstream, SignalForge lets you restrict when trades are allowed with a per-account time-window filter, but it executes whatever alerts arrive — it will not judge trend direction for you. If you want with-trend entries only, filter in Pine before the alert fires.

Does a trend filter work on any timeframe?

+
Yes, but apply it one timeframe up for best results: filter M15 entries with the H1 trend, or H1 entries with the H4 trend. A filter on the same timeframe as the signal still helps, it just reacts to the same noise the signal does.
B
Benjamin SF · Founder of SignalForge
TRADER · ALICANTE 🇪🇸

Benjamin SF is the founder of SignalForge and an expert in trading algorithm automation. He builds and operates the SignalForge bridge and the SFCloud hosted-MT5 fleet for prop-firm traders.

Automate your TradingView signals on MT5

SignalForge routes your alerts to MetaTrader 5 in milliseconds. 14-day free trial, no card required.

SignalForge AI is an order-execution tool. We do not provide investment advice. Trading involves risk of loss.

Alerts filtered with-trend? Execute them on MT5 in milliseconds · 14-day free trialConnect TradingView to MT5 →