How to Automate a TradingView Strategy on MT4 and MT5

Last updated · By the TradingView Link team
Short answer

To automate a TradingView strategy, give every order in your Pine Script a TradingView Link command with alert_message. Then create one alert on the strategy, with {{strategy.order.alert_message}} as its message and your webhook URL. Each time the strategy fills an order on a live bar, TradingView sends that command and our EA places the trade in MT4 or MT5. You need a TradingView plan with webhooks (Essential or higher) and MetaTrader running with the EA.

This guide is for traders who already have a strategy that backtests the way they want. The code examples use Pine Script v6; they work the same way in v5. If you haven't connected MetaTrader yet, start with how to connect TradingView to MT5 or how to connect TradingView to MT4.

What do you need?

How do strategy alerts work?

Step 1: Add alert_message to every order

Each strategy.entry, strategy.close, strategy.exit and strategy.order call accepts an alert_message. Put the TradingView Link command for that order there, without the password. This example buys 0.1 lots when the fast EMA crosses above the slow one, with a stop at the lowest low of the last 10 bars, and closes when it crosses back:

//@version=6
strategy("EMA cross to MT5", overlay = true)

// Your broker's symbol name, which can differ from TradingView's
brokerSymbol = input.string("BTCUSD", "Broker symbol")

fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
stopPrice = ta.lowest(low, 10)

if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, alert_message = "long " + brokerSymbol + " q=0.1 slp=" + str.tostring(stopPrice, format.mintick))
if ta.crossunder(fast, slow)
    strategy.close("Long", alert_message = "flat " + brokerSymbol)

The full command syntax, including partial closes, trailing stops and session filters, is in our documentation.

Step 2: Create one alert on the strategy

  1. Open the chart with the symbol and timeframe you want to trade, add the strategy and set its inputs.
  2. Open Create alert and pick your strategy as the condition. If the script also calls alert(), choose Order fills only so that only orders are sent.
  3. Replace the message with your webhook password and the placeholder, on two lines:
YourWebhookPassword
{{strategy.order.alert_message}}
  1. Under notifications, turn on Webhook URL and paste the webhook URL from your TradingView Link dashboard.
  2. Check the expiration date. Essential and Plus alerts last at most 2 months; Premium and higher plans can keep them open-ended. Note the date so the strategy doesn't stop without warning.
  3. Create the alert.

Step 3: Test it on a demo account

Before you go live, run the strategy on a demo account for a few trades. To check MetaTrader on its own, send a command from the Send Signal box in your dashboard. Then wait for the strategy's next live order, or test on a low timeframe where orders come quickly. Compare each trade in MT4 or MT5 with the order on your TradingView chart, and read the EA's lines in the Experts tab. If nothing arrives, follow our TradingView to MT5 troubleshooting guide.

Why don't live trades match the backtest?

What if you can't edit the script?

If the strategy is protected or invite-only, you can't add alert_message. For a strategy that always opens and closes whole positions, use this alert message instead:

YourWebhookPassword
{{strategy.market_position}} BTCUSD q=0.1 sl=300 tp=600

{{strategy.market_position}} becomes long, flat or short, the strategy's position after the order. A long entry sends long, a reversal sends short, and an exit sends flat, which closes the symbol's positions. It breaks with partial exits: the position is still long, so the alert sends long again and opens another trade.

Don't use {{strategy.order.action}} for this. It sends "buy" or "sell", and the EA only accepts long, short, flat, cancel and modify, so it logs "Invalid order type" and places nothing.

What are the most common mistakes?

Common strategy automation mistakes
MistakeWhat happensFix
{{strategy.order.action}} in the message "Invalid order type" in the Experts tab; no trade Use alert_message
Script edited after the alert was created The alert keeps running the old version Delete the alert and create a new one
Alert expired Trades stop on the expiry date Create the alert again, or move to a plan with open-ended alerts
More than 15 orders in 3 minutes TradingView stops the alert Use a higher timeframe or send fewer orders
TradingView ticker instead of the broker's symbol "Symbol not found" in the Experts tab Use the exact name from MetaTrader's Market Watch
2-factor authentication off TradingView doesn't send the webhook Turn on 2FA in your TradingView account
Automate your strategy for free
Test on MT4 or MT5 with 5 free alerts a month. No credit card. Paid plans from $4.99 a month.

Frequently asked questions

Can TradingView place trades on MT4 or MT5 by itself?

No. TradingView has no built-in link to MetaTrader. A strategy alert can send a webhook, and a bridge such as TradingView Link turns that webhook into an order that an Expert Advisor (EA) places in your MT4 or MT5 terminal.

Do I need to keep TradingView open?

No. TradingView alerts run on TradingView's servers, so you can close the chart and your browser. MT4 or MT5 must stay open with the EA running, which is why many traders use a Windows VPS.

Which TradingView plan do I need to automate a strategy?

A plan with webhook alerts: Essential, Plus, Premium, Expert or Ultimate. The free Basic plan has no webhooks. Alerts on Essential and Plus last at most 2 months, so you have to renew them; Premium and higher plans can keep alerts open-ended. TradingView also requires 2-factor authentication for webhooks.

Why did the strategy trade in the backtest but send no alert?

Strategy alerts fire only for orders filled on live bars, never for the historical trades in a backtest. If your alert is new, wait for the strategy's next live order.

Can I run several strategies on one MT5 account?

Yes. Create one alert per strategy and give each strategy its own magic number, such as m=1001, in every command, including flat. The EA then closes and reverses only the trades with that magic number.

Can I automate an indicator instead of a strategy?

Yes. Create one alert per action on the indicator's condition, each with a fixed message such as long BTCUSD q=0.1 or flat BTCUSD. A strategy is easier because one alert covers every order.

Sources

Checked in November 2026.

Related guides