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.
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.
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.
//@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?
+
Which trend filter is best: EMA 200, Supertrend or ADX?
+
Will a trend filter reduce my number of trades?
+
Can I filter alerts without editing Pine Script?
+
Does a trend filter work on any timeframe?
+
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.