Skip to content
Docs
Open Portal
Copy the page manually

Your browser did not allow direct clipboard access. Select and copy the Markdown below.

Add alerts to your script

Connect a Pine Script strategy or indicator to PineConnector, with complete examples and a clear check at each stage.

Add a PineConnector message to the conditions your script already uses. Start with a complete strategy or indicator example, then create the TradingView alert that sends its messages.

Cannot edit the script? Use Automate without code access.

Before you begin
  • Complete your setup and send a test alert before changing a script.

  • An editable Pine Script

    These worked examples retain Pine Script v5. Save a working copy so your original stays available.

  • Have your License ID and the exact symbol shown by your MetaTrader broker ready.

Open Pine Editor. Near the top, strategy(...) means a strategy; indicator(...) means an indicator. Choose the matching section below. For older code, follow TradingView’s version migration guidance before mixing versions.

This example uses SuperTrend’s existing direction changes. The buy condition is ta.change(direction) < 0; the sell condition is ta.change(direction) > 0.

Find each strategy.entry and the if condition above it. The optional plotshape lines mark those conditions on the chart, so you can compare them with your intended entries.

Use Ctrl+F on Windows or Cmd+F on Mac to find strategy.entry in the editor. Preserve the full condition and its indentation when adding the alert.

SuperTrend before and after visual markers
TradingView → Pine Editor Pine Script
//@version=5
strategy('Supertrend Strategy', overlay=true)
[supertrend, direction] = ta.supertrend(3, 10)
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, 'Up Trend', color=color.new(color.green, 0), style=plot.style_linebr)
downTrend = plot(direction < 0 ? na : supertrend, 'Down Trend', color=color.new(color.red, 0), style=plot.style_linebr)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
if ta.change(direction) < 0
strategy.entry('My Long Entry Id', strategy.long)
if ta.change(direction) > 0
strategy.entry('My Short Entry Id', strategy.short)

Save and select Add to chart. Confirm that the blue Buy and Sell labels correspond to the conditions you chose.

SuperTrend chart with blue PineConnector Buy and Sell labels and the Save and Add to chart controls highlighted Enlarge
Published TradingView example from 2022. The labels mark signal conditions, not confirmed broker trades.
Published TradingView example from 2022. The labels mark signal conditions, not confirmed broker trades.Open original
SuperTrend chart with blue PineConnector Buy and Sell labels and the Save and Add to chart controls highlighted

Place alert(...) inside the corresponding if block, at the same indentation as strategy.entry. In the complete example, the buy branch sends buy and the sell branch sends sell.

Complete SuperTrend example with alerts
TradingView → Pine Editor Pine Script
//@version=5
strategy('Supertrend Strategy', overlay=true)
[supertrend, direction] = ta.supertrend(3, 10)
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, 'Up Trend', color=color.new(color.green, 0), style=plot.style_linebr)
downTrend = plot(direction < 0 ? na : supertrend, 'Down Trend', color=color.new(color.red, 0), style=plot.style_linebr)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
if ta.change(direction) < 0
strategy.entry('My Long Entry Id', strategy.long)
alert('LicenseID,buy,EURUSD,risk=1', alert.freq_once_per_bar_close)
if ta.change(direction) > 0
strategy.entry('My Short Entry Id', strategy.short)
alert('LicenseID,sell,EURUSD,risk=1', alert.freq_once_per_bar_close)
plotshape(ta.change(direction) < 0, style=shape.labelup, location=location.belowbar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Buy', textcolor=color.new(color.white, 0)) //plotting up arrow when buy/long conditions met
plotshape(ta.change(direction) > 0, style=shape.labeldown, location=location.abovebar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Sell', textcolor=color.new(color.white, 0)) //plotting down arrow when sell/short conditions met

Before saving, replace any remaining LicenseID, change EURUSD to your exact broker symbol, and review the risk= value in both alert lines. These messages request entries; they do not add separate exit alerts or stops to your strategy.

Go to the symbol and timeframe you want, then select Create alert. Choose your saved strategy and alert() function calls only. This uses the messages you added to the script.

TradingView alert condition set to the SuperTrend strategy and alert function calls only Enlarge
Published alert-dialog example from 2024. Choose the option for alert() calls only.
Published alert-dialog example from 2024. Choose the option for alert() calls only.Open original
TradingView alert condition set to the SuperTrend strategy and alert function calls only

Add the webhook URL and create the alert. Do not also select order-fill events for this example: that is a separate alert mechanism.

Indicator: use your buy and sell conditions

Section titled “Indicator: use your buy and sell conditions”

The EMA example below uses an upward cross of the 20-period EMA over the 50-period EMA for long, and the opposite cross for short, with the published close-price conditions retained.

Use the actual boolean conditions from your indicator. A chart colour or label alone does not tell you which expression should trigger an alert. If you are unsure, ask the script author which conditions correspond to Buy and Sell.

EMA indicator before and after visual markers
TradingView → Pine Editor Pine Script
//@version=5
indicator("EMA", overlay=true)
ema20 = ta.ema(close,20)
ema50 = ta.ema(close,50)
plot(ema20, color=color.new(color.blue, 5))
plot(ema50, color=color.new(color.red, 5))
long = ta.crossover(ema20, ema50) and close > ema20
short = ta.crossunder(ema20, ema50) and close < ema20

Select Save, then Add to chart. Check that the Buy and Sell markers appear at the conditions you intended before adding alert messages.

EMA indicator with moving-average lines and PineConnector Buy and Sell labels on the chart Enlarge
Published EMA example from 2022. Confirm the markers appear where your intended conditions occur.
Published EMA example from 2022. Confirm the markers appear where your intended conditions occur.Open original
EMA indicator with moving-average lines and PineConnector Buy and Sell labels on the chart

Keep the alert(...) calls inside if long and if short. The complete example preserves the published indicator and corrects the short branch to send a sell message.

Complete EMA example with buy and sell alerts
TradingView → Pine Editor Pine Script
//@version=5
indicator("EMA", overlay=true)
ema20 = ta.ema(close,20)
ema50 = ta.ema(close,50)
plot(ema20, color=color.new(color.blue, 5))
plot(ema50, color=color.new(color.red, 5))
long = ta.crossover(ema20, ema50) and close > ema20
short = ta.crossunder(ema20, ema50) and close < ema20
plotshape(long, style=shape.labelup, location=location.belowbar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Buy', textcolor=color.new(color.white, 0)) //plotting up arrow when buy/long conditions met
plotshape(short, style=shape.labeldown, location=location.abovebar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Sell', textcolor=color.new(color.white, 0)) //plotting down arrow when sell/short conditions met
if long
alert('LicenseID,buy,EURUSD,risk=1', alert.freq_once_per_bar_close)
if short
alert('LicenseID,sell,EURUSD,risk=1', alert.freq_once_per_bar_close)

Replace any remaining LicenseID, set your broker symbol, and review both risk= values. Save the script and add it to the chart.

Select the saved indicator under Condition, then Any alert() function call. Add the webhook below and create the alert. One such alert listens to the eligible buy and sell calls in this example.

TradingView alert dialog with EMA selected and Any alert function call chosen Enlarge
Published indicator-alert example from 2024.
Published indicator-alert example from 2024.Open original
TradingView alert dialog with EMA selected and Any alert function call chosen

In the alert’s notification settings, enable Webhook URL and paste:

Use the same destination for the strategy and indicator examples.

TradingView notification settings with Webhook URL enabled and the PineConnector webhook address entered Enlarge
Published notification-settings example from 2024. Other notification channels are optional.
Published notification-settings example from 2024. Other notification channels are optional.Open original
TradingView notification settings with Webhook URL enabled and the PineConnector webhook address entered

When a new condition occurs in real time, check all three places:

  1. TradingView Alerts log: the message has the intended direction, License ID, symbol and values.
  2. PineConnector Signals log: a corresponding message was received and its processing result is available.
  3. MetaTrader: the intended demo account received the expected order, volume and any stops, without duplicates.

If a stage differs, use Missing signals or Errors. Historical chart markers do not send old alerts when you first create an alert.

Use these additions only after a basic alert works. These are Pine Script excerpts, not standalone scripts. They retain the published risk=, sl= and tp= form; their units follow your EA settings. For explicit-unit parameters, see PineConnector Syntax.

A fixed buy message
Inside your Pine Script entry condition Pine Script
alert('LicenseID,buy,EURUSD,risk=1', alert.freq_once_per_bar_close)

The symbol and value stay the same each time this line runs.

2. Add stop-loss and take-profit parameters

Section titled “2. Add stop-loss and take-profit parameters”
Fixed message with targets
Inside your Pine Script entry condition Pine Script
alert('LicenseID,buy,EURUSD,risk=1,sl=10,tp=20', alert.freq_once_per_bar_close)

Here, 10 and 20 are interpreted using your EA’s Target Type. Check those units before copying this excerpt into a working script.

The pip examples in steps 2–3 assume Target Type = Pips and Setting = Signal Parameters Only, so the message supplies its SL, TP and Risk values. The dynamic-price examples below deliberately use a different Target Type.

Use the chart ticker
Inside your Pine Script entry condition Pine Script
alert('LicenseID,buy,' +syminfo.ticker+ ',sl=10,tp=20,risk=1', alert.freq_once_per_bar_close)

syminfo.ticker supplies the chart ticker. It may differ from your broker’s symbol. For the published US100 → NAS100 example, replace the ticker before composing the message:

Map a different broker symbolExcerpt: replace LongEntryCondition with your actual condition.
TradingView → Pine Editor Pine Script
symbol = syminfo.ticker
if syminfo.ticker == "US100"
symbol := "NAS100"
if LongEntryCondition
alert('LicenseID,buy,'+symbol+',sl=10,tp=20,risk=1', alert.freq_once_per_bar_close)

4. Convert changing numbers into message text

Section titled “4. Convert changing numbers into message text”
Use values calculated by your scriptExcerpt: replace LongEntryCondition. Review generated prices before using it.
TradingView → Pine Editor Pine Script
LongSL = low[1]
LongTP = ta.ema(close,50)
RiskValue = 1
if LongEntryCondition
alert('LicenseID,buy,' +syminfo.ticker+ ',sl=' +str.tostring(LongSL)+ ',tp=' +str.tostring(LongTP)+ ',risk='+str.tostring(RiskValue), alert.freq_once_per_bar_close)
Part Meaning
low[1] The previous bar’s low price.
ta.ema(close,50) The 50-period EMA of closing prices.
RiskValue = 1 A fixed value, interpreted by your Volume Type.
str.tostring(...) Converts the number into text for the alert message.

The published excerpt adds comment="Strategy 1" inside a single-quoted Pine string. Keep those quote pairs intact. The same price-target requirements apply.

Add a strategy commentExcerpt: replace LongEntryCondition and review target prices.
TradingView → Pine Editor Pine Script
LongSL = low[1]
LongTP = ta.ema(close,50)
RiskValue = 1
if LongEntryCondition
alert('LicenseID,buy,' +syminfo.ticker+ ',sl=' +str.tostring(LongSL)+ ',tp=' +str.tostring(LongTP)+ ',risk='+str.tostring(RiskValue)+',comment="Strategy 1"', alert.freq_once_per_bar_close)

6. Send separate messages to multiple License IDs

Section titled “6. Send separate messages to multiple License IDs”

Use distinct IDs only when separate destinations are intentional. The placeholders LicenseID1 to LicenseID5 below must each be filled manually. Check multi-instance signals before adding repeated alerts to accounts already sharing one License ID.

Separate messages for five License IDsExcerpt: fill each ID and replace LongEntryCondition. These are five separate requests.
TradingView → Pine Editor Pine Script
if LongEntryCondition
alert('LicenseID1,buy,' +syminfo.ticker+ ',risk=1,sl=20', alert.freq_once_per_bar_close)
alert('LicenseID2,buy,' +syminfo.ticker+ ',risk=1,sl=30', alert.freq_once_per_bar_close)
alert('LicenseID3,buy,' +syminfo.ticker+ ',risk=1,sl=40', alert.freq_once_per_bar_close)
alert('LicenseID4,buy,' +syminfo.ticker+ ',risk=1,sl=40', alert.freq_once_per_bar_close)
alert('LicenseID5,buy,' +syminfo.ticker+ ',risk=1,sl=40', alert.freq_once_per_bar_close)

Each call is an additional alert event. TradingView limits a regular alert to 15 triggers in three minutes; several messages from one condition can reach that limit quickly. If the alert stops, inspect its status before resuming it. Watchlist alerts have separate overall and per-symbol rules. TradingView’s current trigger limits

This published example combines EMA conditions, symbol mapping, dynamic price targets and three License IDs. It sends buy messages only. It does not implement sell alerts or exits. Fill each ID manually and review the price-target requirements above.

Combined buy-only examplePine v5 · Buy only
TradingView → Pine Editor Pine Script
//@version=5
indicator("EMA", overlay=true)
ema20 = ta.ema(close,20)
ema50 = ta.ema(close,50)
plot(ema20, color=color.new(color.blue, 5))
plot(ema50, color=color.new(color.red, 5))
long = ta.crossover(ema20, ema50) and close > ema20
short = ta.crossunder(ema20, ema50) and close < ema20
//plotting arrows to print entries on the chart
plotshape(long, style=shape.labelup, location=location.belowbar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Buy', textcolor=color.new(color.white, 0)) //plotting up arrow when buy/long conditions met
plotshape(short, style=shape.labeldown, location=location.abovebar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Sell', textcolor=color.new(color.white, 0)) //plotting down arrow when sell/short conditions met
//manipulating symbol to NAS100 if ticker is US100
symbol = syminfo.ticker
if syminfo.ticker == "US100"
symbol := "NAS100"
//variables to store dynamic values
LongSL = low[1]
LongTP = ta.ema(close,50)
RiskValue = 1
//trigger 3 alerts to the various License IDs with dynamic syntax
if long
alert('LicenseID1,buy,' +symbol+ ',sl=' +str.tostring(LongSL)+ ',tp=' +str.tostring(LongTP)+ ',risk='+str.tostring(RiskValue), alert.freq_once_per_bar_close)
alert('LicenseID2,buy,' +symbol+ ',sl=' +str.tostring(LongSL)+ ',tp=' +str.tostring(LongTP)+ ',risk='+str.tostring(RiskValue), alert.freq_once_per_bar_close)
alert('LicenseID3,buy,' +symbol+ ',sl=' +str.tostring(LongSL)+ ',tp=' +str.tostring(LongTP)+ ',risk='+str.tostring(RiskValue), alert.freq_once_per_bar_close)

Waiting for a bar close can avoid some intrabar changes, but it does not fix every source of repainting. Review the script’s use of other timeframes, historical calculations and chart type in TradingView’s repainting guide.