BAZ

BAZ Trading guide

How to send TradingView alerts to MetaTrader 5 with a webhook

Short answer. TradingView cannot talk to MetaTrader 5 directly. You need three parts: a TradingView alert that sends a webhook, a small HTTPS server that receives and stores it, and an Expert Advisor in MT5 that fetches new orders from that server with WebRequest and places them. TradingView requires two-factor authentication for webhooks, sends only to ports 80 or 443, and gives your server 3 seconds to answer.

How the pieces fit

  1. TradingView alert. Your indicator or strategy fires an alert; its message is the order (for example JSON with symbol, side, stop and target), and the alert's webhook URL points to your server.
  2. Receiver. An HTTPS endpoint on your own server or VPS checks the request, stores the order with a unique id and answers at once (under 3 seconds).
  3. Expert Advisor. Every second or two, the EA in MT5 asks the receiver for orders newer than the last id it saw, checks them against your risk limits, places them and reports back.

The EA pulls orders instead of the server pushing them because MT5 cannot accept incoming connections; WebRequest only makes outgoing calls.

Step 1: the alert message

{"token": "<random-webhook-token>", "id": "{{timenow}}-{{ticker}}", "symbol": "{{ticker}}", "side": "buy", "price": {{close}}, "sl": 2341.5, "tp": 2362.0}

Step 2: the receiver

Step 3: the Expert Advisor

void OnTimer()
{
   char body[], reply[];
   string replyHeaders;
   string url = "https://your-server.example/orders?after=" + IntegerToString(lastId);
   int status = WebRequest("GET", url, "Authorization: Bearer " + Token + "\r\n", 2000, body, reply, replyHeaders);
   if(status != 200) return;              // try again on the next timer tick
   // parse the orders, check risk limits, send with CTrade, then remember the newest id
}

Safety checks that matter more than speed

Ready-made options

You can build this yourself or use a ready connector. BAZ Bridge (our product) is one: an EA plus a hosted receiver that executes BAZ Sniper alerts on your own MT5 account within your limits; its setup guide walks through each step. Other connectors exist; compare how each handles duplicates, symbol mapping and risk limits before you choose.

About the author

Bil Baz is a Dubai-based MQL5 developer and gold trader and the founder of BAZ Trading, which sells BAZ Bridge. Trading carries a high risk of loss; automation can lose money quickly. This guide is education, not investment advice. Read the trading risk warning.

Sources