Each template below is a small Pine Script v6 script and the alert message it sends to ZB Connector. Copy the script into the Pine Editor, create the alert, replace YOUR_LICENSE_KEY, and check the result with the playground.
These are automation examples to show how the pieces fit. They are not trading advice and not evidence that any setup is profitable. Change the numbers (moving-average lengths, 0.1 lots) to your own plan, and test on a demo account.
Verified on 2026-10-05 against TradingView’s Pine Script v6 documentation.
How every template works
Section titled “How every template works”-
Open TradingView’s Pine Editor, paste the script, and add it to the chart.
-
Create an alert (see create a TradingView alert). For an indicator, choose the script and the alert condition named in the template. For the strategy, choose the strategy.
-
Tick Webhook URL and enter the address from the alert guide.
-
Check that the Message box holds the message shown in the template, with your license key in place of
YOUR_LICENSE_KEY.What you should seeThe playground says Format is valid for the message. After the alert fires, TradingView’s alert log shows a successful Webhook status and Command History has a row.
1. Open long and short on a moving-average cross
Section titled “1. Open long and short on a moving-average cross”An indicator with two alert conditions. When the fast average crosses above the slow one it sends long, and when it crosses below it sends short.
//@version=6indicator("ZB crossover alerts", overlay = true)
fast = ta.sma(close, 14)slow = ta.sma(close, 28)plot(fast, "Fast", color = color.teal)plot(slow, "Slow", color = color.orange)
alertcondition(ta.crossover(fast, slow), "ZB long", '{"license": "YOUR_LICENSE_KEY", "action": "long", "symbol": "{{ticker}}", "volume": 0.1}')alertcondition(ta.crossunder(fast, slow), "ZB short", '{"license": "YOUR_LICENSE_KEY", "action": "short", "symbol": "{{ticker}}", "volume": 0.1}')Create two alerts: one for the condition ZB long and one for ZB short. TradingView fills the message box with the text from the script, which you can edit. This is the long message:
{ "license": "YOUR_LICENSE_KEY", "action": "long", "symbol": "{{ticker}}", "volume": 0.1}{{ticker}}is replaced by TradingView with the chart’s symbol. It must match your broker’s MT5 symbol exactly.volumeis in lots.- Check the EA input Close on reverse (options Off, Hedging, Netting; default Hedging) before you go live: it is the EA’s setting for signals that reverse the direction.
2. A strategy that sends its own message
Section titled “2. A strategy that sends its own message”A strategy builds the message in the script and passes it with alert_message. In the alert dialog, the message box must contain {{strategy.order.alert_message}}.
//@version=6strategy("ZB strategy alerts", overlay = true)
fast = ta.sma(close, 14)slow = ta.sma(close, 28)
buyMessage = '{"license": "YOUR_LICENSE_KEY", "action": "long", "symbol": "' + syminfo.ticker + '", "volume": 0.1, "positionID": "ma_long"}'sellMessage = '{"license": "YOUR_LICENSE_KEY", "action": "short", "symbol": "' + syminfo.ticker + '", "volume": 0.1, "positionID": "ma_short"}'
if ta.crossover(fast, slow) strategy.entry("Buy", strategy.long, alert_message = buyMessage)
if ta.crossunder(fast, slow) strategy.entry("Sell", strategy.short, alert_message = sellMessage){{strategy.order.alert_message}}The script sends this message when the fast average crosses above the slow one:
{ "license": "YOUR_LICENSE_KEY", "action": "long", "symbol": "{{ticker}}", "volume": 0.1, "positionID": "ma_long"}syminfo.tickeris the chart symbol without the exchange prefix. It plays the part of{{ticker}}here, because the message is built inside the script.positionIDis your own name for the position. Later commands such ascloseByIDuse it to find the position.- Do not use
{{strategy.order.action}}asaction: it returnsbuyorsell, which are not command names.
3. Close everything when a condition happens
Section titled “3. Close everything when a condition happens”An indicator that sends closeAll when the RSI crosses below 50.
//@version=6indicator("ZB close-all alert")
r = ta.rsi(close, 20)plot(r, "RSI")hline(50)
alertcondition(ta.crossunder(r, 50), "ZB close all", '{"license": "YOUR_LICENSE_KEY", "action": "closeAll"}'){ "license": "YOUR_LICENSE_KEY", "action": "closeAll"}closeAll closes every position on every symbol in the EA’s trade scope. To close one symbol only, send closeSymbol with "symbol": "{{ticker}}" instead.
4. Stop loss and take profit from your script
Section titled “4. Stop loss and take profit from your script”An indicator that sends a long with a stop loss at the low of the signal bar and a take profit calculated in the script. The take profit travels as a plot, so the message can use {{plot("TP")}}.
//@version=6indicator("ZB entry with stops", overlay = true)
fast = ta.sma(close, 14)slow = ta.sma(close, 28)tpLevel = close + 2 * (close - low)plot(tpLevel, "TP")
alertcondition(ta.crossover(fast, slow), "ZB long with stops", '{"license": "YOUR_LICENSE_KEY", "action": "long", "symbol": "{{ticker}}", "volume": 0.1, "tp": {{plot("TP")}}, "sl": {{low}}, "positionID": "ma_long"}'){ "license": "YOUR_LICENSE_KEY", "action": "long", "symbol": "{{ticker}}", "volume": 0.1, "tp": {{plot("TP")}}, "sl": {{low}}, "positionID": "ma_long"}- A message that contains
{{plot("TitleOfPlot")}}has to be wrapped in single quotes in the Pine code, because the placeholder itself contains double quotes. The script above does that. slandtpare price levels while the EA input Stop level mode is price (the default). With pips or ticks they are distances, and these values would be wrong.{{low}}is the low of the bar that triggered the alert. For a long, the stop loss must be below the entry price and the take profit above it, or the broker refuses it (error 10016).- The JSON above is not valid until TradingView has replaced the placeholders. The playground replaces them with sample values before it checks.
Next step
Section titled “Next step”Paste your own message into the playground, then run a test alert on a demo account.
Verified for EA v1.9 · dashboard 2026-10-05 · reviewed by Claude Code (owner review pending)
Trading involves substantial risk of loss. ZB Connector is software only; it does not provide investment advice, signals or brokerage services.