tocOn this page 8 sections
TradingView can't talk to MetaTrader 5 directly. The usual fix is to give the alert a webhook URL that points to a small listener on your Windows VPS. The listener reads the alert's JSON message, checks a shared secret, and places the order through the MT5 terminal running in the same Windows session. Because the VPS is always on, signals keep turning into trades when your own PC is off.
How the pieces fit together
There are four parts, and it helps to keep them separate in your head:
- TradingView alert: fires on a condition or strategy and sends an HTTP POST to your webhook URL. Webhook alerts need a paid TradingView plan, and TradingView only delivers to standard web ports, so plan on HTTPS on port 443.
- Reverse proxy: handles TLS on port 443 and passes requests to the listener on localhost. IIS with URL Rewrite or a small proxy such as Caddy both work.
- Bridge listener: a short Python app that checks the alert and calls MT5.
- MT5 terminal: logged in to your broker, with algorithmic trading turned on.
If you'd rather not write code, commercial bridge EAs and services do the same job. Before you trust one with your account, check how it authenticates alerts and where your signals pass through.
Prepare the VPS
Over RDP, install MT5, log in to your trading account and turn on Algo Trading in the toolbar. If you haven't set up the terminal yet, start with our guide to running MetaTrader on a Windows VPS for forex trading. Then install Python for all users and add the packages from an elevated PowerShell window:
py -m pip install MetaTrader5 flask waitress
The MetaTrader5 package is Windows-only. It connects to a running terminal through local IPC, so the bridge has to run on the same machine, under the same user, as MT5.
A minimal bridge
Save this as C:\bridge\bridge.py. It accepts a JSON alert, rejects anything without the right secret, and sends a market order:
import os
from flask import Flask, request, abort
import MetaTrader5 as mt5
app = Flask(__name__)
SECRET = os.environ["TV_SECRET"]
@app.post("/tv")
def tv():
data = request.get_json(force=True, silent=True) or {}
if data.get("secret") != SECRET:
abort(403)
if not mt5.initialize():
abort(503)
symbol = data["symbol"]
mt5.symbol_select(symbol, True)
tick = mt5.symbol_info_tick(symbol)
buy = data["side"] == "buy"
result = mt5.order_send({
"action": mt5.TRADE_ACTION_DEAL,
"symbol": symbol,
"volume": float(data["volume"]),
"type": mt5.ORDER_TYPE_BUY if buy else mt5.ORDER_TYPE_SELL,
"price": tick.ask if buy else tick.bid,
"deviation": 20,
"magic": 26001,
"comment": "tradingview",
})
return {"retcode": result.retcode}
Brokers differ, so you may also need to set type_filling to a filling mode your broker accepts. Symbol names often differ too: TradingView may call a pair EURUSD while your broker lists it as EURUSD.m or similar. Add a small lookup table that maps one name to the other, and log the retcode from every order so failures are easy to spot.
Serve the bridge on localhost only, and let the reverse proxy be the only thing exposed to the internet:
$env:TV_SECRET = "use-a-long-random-string"
cd C:\bridge
waitress-serve --listen=127.0.0.1:8080 bridge:app
Open the firewall and add HTTPS
Point a domain or subdomain at the VPS IP, set up the reverse proxy with a real certificate, and forward /tv to 127.0.0.1:8080. Then allow inbound HTTPS:
New-NetFirewallRule -DisplayName "TradingView webhook HTTPS" `
-Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
Don't open port 8080 to the internet. TradingView publishes the IP addresses it sends webhooks from. If you add those to the rule's -RemoteAddress, take them from TradingView's own documentation rather than copying them from a forum post.
Configure the TradingView alert
In the alert dialog, turn on the webhook option and enter https://your-domain/tv. Set the message to valid JSON. Placeholders such as {{ticker}} and, for strategy alerts, {{strategy.order.action}} are filled in when the alert fires:
{"secret":"use-a-long-random-string","symbol":"{{ticker}}","side":"{{strategy.order.action}}","volume":0.10}
Test on a demo account first. Fire a test alert and confirm that an order shows up in the MT5 Trade tab and that the bridge log shows a successful retcode.
Keep it running after reboots
A Windows service starts in session 0 and can't see a terminal running on your desktop, so start the bridge in the same user session as MT5. A scheduled task that runs at logon works well. Our guide on launching apps automatically when you sign in over RDP covers the setup, and you can use it to start MT5 first and the bridge a few seconds later. If the VPS also runs heavy jobs, raising the scheduled task's priority helps the bridge answer quickly. When you're done, disconnect from RDP instead of signing out, so the session stays alive.
Security checklist
- Use a long random secret and change it if it ever ends up in a screenshot or a shared alert.
- Never expose the Flask or waitress port directly. Only the TLS proxy should face the internet.
- Cap volume in the bridge so a typo in an alert can't open a huge position.
- Ignore duplicate alerts that arrive within a few seconds of each other, so a retry doesn't open a second trade.
FAQ
Do I need an Expert Advisor for this?
Not with the Python approach. The MetaTrader5 package sends orders through the terminal directly. An EA is only needed if you want the logic inside MT5, for example an EA that reads signal files the bridge writes to the terminal's Common\Files folder.
Why are my alerts arriving but no trades open?
Check four things: Algo Trading is turned on, the symbol name matches your broker's, the filling mode is supported, and the bridge runs in the same user session as MT5. The retcode in your log usually tells you which one is wrong.
Can one bridge feed several MT5 terminals?
Yes. Install each terminal in its own folder and pass that folder's path to mt5.initialize(). Use one bridge process per terminal, because each Python process connects to only one terminal at a time.
Run this on your own Windows VPS
Get a Windows VPS from WindowsVPS in about 60 seconds, with full Administrator access over RDP, NVMe storage and the Windows license included.
Written by the WindowsVPS Team
We run Windows Server VPS hosting and write these guides from the same setups our customers use: RDP, PowerShell, trading terminals and always-on bots. Questions about a guide? Contact us.