Os artigos de ajuda estão em inglês. Os guias dos recursos, no seu idioma, ficam em Recursos.
Trading a TradingView strategy's alerts in MT5
A Pine Script strategy already knows when it enters, exits, takes part profit and reverses. Its alerts can carry all of that to MetaTrader 5, if the bridge reads them as a strategy and not as a list of buy and sell words. This guide covers how strategy alerts work in TradingView, the choices that matter, and how Relay2Trade trades them.
How a strategy's alert works
You make one alert on the strategy, and it fires on every order the strategy makes from then on. TradingView's default message says what the order did and where the strategy now stands:
My strategy (14, 2): order buy @ 1 filled on XAUUSD. New strategy position is 1
The order's side alone is not enough. "Order sell" can open a short, close a long, or close part of it. What tells them apart is the new position: 0 means the strategy is flat, a negative number means it is short, a smaller number the same way means part of the trade was closed.
Relay2Trade reads that message exactly, for free, and acts on the position:
- A new position from flat opens a trade.
- 0 closes the listener's trades on that symbol.
- The other way, and larger reverses: the trades close and the opposite one opens.
- The same way, smaller closes part, in the same share the strategy closed.
The choices in TradingView's alert window
- Condition: your strategy. When TradingView offers a second list ("Order fills only", "alert() function calls only", or both), choose "Order fills only" for the default message above. Choose the alert() calls when your strategy writes its own messages, for example in PineConnector's format.
- Message: leave it as it is. Paste our message only if you want the alert itself to set the stop-loss, take-profits or size (the Desk's message builder writes it).
- Notifications: tick "Webhook URL" and paste your listener's address. Keep "Notification schedule" on 24/7: outside the schedule TradingView sends nothing, exits included.
Orders on past bars send nothing. The first alert comes with the strategy's next live order, so a strategy that is already in a position on the chart does not open one on your account until it trades again.
Strategies that add to a position
Some strategies buy again while they are already long (pyramiding). In the listener's setup, Relay2Trade asks "Does your strategy add to a position that is already open?":
- Yes, it adds: each entry opens another trade, and the strategy's exit closes them all.
- No: a second entry while one is open is left out as repeated, so an indicator-like strategy that signals "buy" twice does not double your position.
When your account and the strategy differ
Your account is not a copy of the backtest. Three things can make them differ, and it is worth knowing them before going live:
- Your stop-loss. If the listener or the profile sets a stop-loss, it can close a trade before the strategy exits. Until the strategy's next exit, the account is flat while the strategy is still in.
- Your limits. A trade refused by your trading hours, symbol lists or daily loss line is not opened, so the strategy's later exit finds nothing to close and says so.
- The broker's minimum lot. A partial exit smaller than the broker allows cannot be made.
Exits are always carried out, however late they come, so a position is not left open because its exit came while the app was off. Entries keep to your "Max signal age".
Coming from PineConnector
Strategies written for PineConnector send lines such as LicenseID,buy,XAUUSD,risk=1,sl=200,tp=400. Relay2Trade reads them with the same meaning, so the same script trades the same way: point the alert's webhook at your listener's address and keep the message. Pips follow PineConnector's convention. See TradingView alert messages: what we read.
Going live safely
- Put the listener on a demo account first, on "Watch".
- Send a test alert from the setup: the app answers what it would place, and nothing is placed.
- Let the strategy's real alerts fire for a while and compare the log with the strategy's list of trades.
- Switch to "Auto". With no stop-loss anywhere, you are asked to confirm it.