How to Automate TradingView Alerts to MetaTrader (MT4/MT5)

MetaTrader is one of the most widely used platforms in retail trading — most forex and CFD brokers offer access to MT4 or MT5. But like every platform, it has the same core gap: a TradingView alert tells you when to trade, not what to actually do about it. This guide covers the current, simplest way to close that gap — a direct WebSocket connection, no Telegram bot or manual bridge required.

By the end, your TradingView alerts will automatically open, update, close, and manage trades on MT4 or MT5.

What you’ll need

  • A TradingView account with alerts enabled on your plan
  • An MT4 or MT5 account with a broker that allows Expert Advisors (EAs)
  • The TradingView to MetaTrader Expert Advisor, installed on your terminal

MetaTrader EA Download Links:

Step 1: Install the EA and get your webhook URL

Download the TradingView to MetaTrader EA from TradingView to Anywhere and attach it to one chart only on your MT4/MT5 terminal — it doesn’t need to be attached per symbol; it will automatically handle trading across every pair your broker offers.

Your webhook URL follows this pattern:

https://tradingview.to/metatrader/{your-unique-id}

Keep this URL private — anyone with it could send trade commands to your connected account.

Step 2: Build your alert message

Commands follow the format action symbol param=value. A few formatting basics:

  • Commands are not case-sensitive — buy EURUSD Quantity=0.1 and Buy eurusd QUANTITY=0.1 both work.
  • No spacing around the = — quantity=1 is valid, quantity = 1 is not.
  • Parameters can be written in full or abbreviated to their first letter (Quantity or Q).
  • You can stack up to 5 commands in one alert, each on its own line.

Opening a trade

Buy/Long/1 and Sell/Short/-1 open positions. Useful optional parameters:

  • Quantity (Q or OQ) — lot size or percentage. Defaults to the symbol’s minimum lot size if omitted.
  • Price (P) — turns the order into a limit/stop order; absolute price, percentage, or points (P=1%, P=1.2345, P=500)
  • Take Profit (TP) / Stop Loss (SL) — price, percentage, or points
  • Magic (M) — a unique ID to tag a strategy, useful if you’re running more than one
  • Trailing Trigger (TT), Trailing Distance (TD), Trailing Step (TS) — used together to build a trailing stop
  • Gap (G) — maximum spread allowed before the order is rejected
  • Balance (B) — minimum account balance required to open the trade
  • Session (S) — restrict execution to a time window, e.g. S=06:23-12:32
  • Expiry (E) — expiry time (minutes) for a pending order
  • Delay (D) — delay command execution, up to 5 seconds
buy EURUSD Q=0.5 P=500 TP=1.2500 SL=1.0500

Places a buy stop 500 points above the current price, with take profit and stop loss at fixed prices.

sell AUDCAD TP=5% SL=2%

Opens a sell trade with take profit and stop loss set as a percentage away from the current market price.

{{strategy.order.action}} EURUSD Q=0.5 TT=100 TD=50 TS=10

Dynamically buys or sells based on your strategy’s direction, with a trailing stop that activates once price moves 100 points in profit.

For trailing capabilities, you will need to install our Trailing plugin EA, which enables the trailing of limit and stop orders as well.

Dynamic pricing: P, TP, and SL can also reference recent candle data from your MetaTrader chart using {highest[n]}, {lowest[n]}, {close[n]}, {open[n]} placeholders, where n is the number of candles to reference:

buy EURUSD P={highest[5]} TP={close[1]} SL={lowest[10]}

Places a buy stop at the highest price of the last 5 candles, with take profit at the last close and stop loss at the lowest price of the last 10 candles.

Updating an open trade

Update/Modify adjust an existing position — useful for moving a stop to breakeven or adjusting trailing parameters without closing the trade.

update EURUSD T=short SL=-1

Moves the stop loss to breakeven.

modify EURUSD TT=200 TD=100 TS=50

Updates the trailing stop parameters on an open trade.

Closing a trade

Close/Flat/0 exit a position, fully or partially.

close EURUSD

Closes all EURUSD trades.

0 EURUSD T=short CQ=50%

Closes 50% of all short EURUSD trades.

Cancelling a pending order

Cancel/Exit cancel pending (not-yet-filled) orders.

cancel XAUUSD

Cancels all pending Gold orders.

Balance check

Balance/Funds/Bal return your account balance.

balance

Step 3: Wire the alert into TradingView

  1. Set your alert condition as usual.
  2. Paste the webhook URL from Step 1 into the alert’s Webhook URL field.
  3. Enter your command in the Message field using the syntax above.

For strategy alerts, {{strategy.order.action}} returns “buy”/“sell” for the executed order, while {{strategy.market_position}} returns the strategy’s current state (“long”/“flat”/“short”) — pick whichever matches how your strategy signals entries and exits.

Step 4: Test before you trust it

  1. Trigger a test alert manually from TradingView.
  2. Confirm the trade appears on your MT4/MT5 terminal with the correct size, and that Auto-Trading is enabled (green icon) on the chart.
  3. Check that stop loss, take profit, and any trailing parameters landed correctly before relying on it for live strategies.

Common mistakes

  • Mismatched entry/exit placeholders — using {{strategy.order.action}} (buy/sell only) on a strategy that also sends an exit signal can leave two opposing positions open instead of one closing the other. If your strategy has a flat/close state, use {{strategy.market_position}} instead.
  • Unexpectedly small lot sizes — if a percentage-based quantity comes out far smaller than expected, check the value your strategy is actually sending (e.g. {{strategy.order.contracts}}) — it’s often generating a size MetaTrader rejects or rounds down.
  • Broker symbol suffixes — many brokers append a suffix to symbols (XAUUSDpro, EURUSDm). If you get “Invalid Params, Symbol Not Found,” check your broker’s exact symbol name and use that instead of the plain ticker.
  • EA not attached, or attached to more than one chart — the EA only needs to be on a single chart to handle all pairs; attaching it to multiple charts can cause duplicate execution.
  • Webhook URL typos — copy-paste rather than retype; one wrong character means the alert never arrives.

If you’re still on the Telegram bot method

TTA’s original MT4/5 setup used a Telegram bridge — a bot created via BotFather, added to a channel alongside the official TradingViewToBot, with an EA relaying commands through that channel. It still works, but the WebSocket method above is simpler to set up and doesn’t require maintaining a Telegram bot or channel. If you’re on the older setup and want to switch, the steps are documented in the original guide — worth migrating over when convenient.

.

Ready to connect your account? Start today →