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.
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.
Check your script type
Section titled “Check your script type”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.
Strategy: add a message to each entry
Section titled “Strategy: add a message to each entry”This example uses SuperTrend’s existing direction changes. The buy condition is ta.change(direction) < 0; the sell condition is ta.change(direction) > 0.
1. Check where the entries appear
Section titled “1. Check where the entries appear”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.
Save and select Add to chart. Confirm that the blue Buy and Sell labels correspond to the conditions you chose.
Enlarge2. Add the buy and sell alerts
Section titled “2. Add the buy and sell alerts”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.
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.
3. Create the TradingView alert
Section titled “3. Create the TradingView alert”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.
EnlargeAdd 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.
1. Identify the conditions
Section titled “1. Identify the conditions”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.
Select Save, then Add to chart. Check that the Buy and Sell markers appear at the conditions you intended before adding alert messages.
Enlarge2. Add the messages
Section titled “2. Add the messages”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.
Replace any remaining LicenseID, set your broker symbol, and review both risk= values. Save the script and add it to the chart.
3. Create the indicator alert
Section titled “3. Create the indicator alert”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.
EnlargeConnect and verify
Section titled “Connect and verify”In the alert’s notification settings, enable Webhook URL and paste:
Use the same destination for the strategy and indicator examples.
EnlargeWhen a new condition occurs in real time, check all three places:
- TradingView Alerts log: the message has the intended direction, License ID, symbol and values.
- PineConnector Signals log: a corresponding message was received and its processing result is available.
- 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.
Build dynamic messages
Section titled “Build dynamic messages”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.
1. Start with a fixed message
Section titled “1. Start with a fixed message”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”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.
3. Use the chart’s symbol
Section titled “3. Use the chart’s symbol”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:
4. Convert changing numbers into message text
Section titled “4. Convert changing numbers into message text”| 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. |
5. Add a recognisable comment
Section titled “5. Add a recognisable comment”The published excerpt adds comment="Strategy 1" inside a single-quoted Pine string. Keep those quote pairs intact. The same price-target requirements apply.
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.
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
7. Read the combined example
Section titled “7. Read the combined example”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.
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.
Next steps
Section titled “Next steps”- Follow the SuperTrend walkthrough for one complete strategy setup.
- Keep PineConnector Syntax nearby when adding parameters.
- Use Best Practices & Tips before enabling a new automation.
