Creating Alerts in TradingView (With Pine Script)
📘 Creating Alerts with Pine Script (2 Options)
TradingView supports two methods for creating alerts using Pine Script — both compatible with Xerolite. This guide shows you how to implement both:
- Option 1: Use
alert()
function in Pine Script to hardcode the alert message - Option 2: Use
strategy.entry()
orstrategy.order()
with TradingView placeholders
⚙️ Option 1: alert() Function (Fully in Code)
This method hardcodes the entire JSON alert inside your Pine Script. Best for simple Buy/Sell logic.
//@version=5
indicator("MA Crossover", overlay=true)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
longCond = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)
if (longCond)
alert('{"action":"BUY","symbol":"AAPL","qty":"10","currency":"USD","asset_class":"STOCK","exch":"SMART"}', alert.freq_once_per_bar)
if (shortCond)
alert('{"action":"SELL","symbol":"AAPL","qty":"10","currency":"USD","asset_class":"STOCK","exch":"SMART"}', alert.freq_once_per_bar)
- Open TradingView and go to the chart you want
- Click the “Pine Editor” and paste your script
- Click “Add to Chart”
- Create alert with “Any alert() function call” condition
- Paste your Xerolite webhook URL
❌ No placeholders supported. All values are fixed in code.
⚙️ Option 2: strategy.entry() + Dynamic Placeholders
This method uses Pine Script for logic and the TradingView UI for dynamic alert configuration using {{placeholders}}
.
//@version=5
strategy("MA Crossover Strategy", overlay=true)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
longCond = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)
if (longCond)
strategy.entry("Buy", strategy.long, qty=10)
if (shortCond)
strategy.entry("Sell", strategy.short, qty=10)
- Add this script to your chart via Pine Editor
- Click “Add to Chart”
- Click 🔔 Alert → Select “Strategy” as condition
- Setup your xerolite Webhook URL
- Paste this JSON message with placeholders:
{
"action": "{{strategy.order.action}}",
"qty": "{{strategy.order.contracts}}",
"symbol": "AAPL",
"currency": "{{syminfo.currency}}",
"order_type": "LIMIT",
"price": "{{strategy.order.price}}",
"asset_class": "STOCK",
"exch": "SMART"
}
✅ Placeholders let you insert live values from your strategy like action, quantity, or order price.
📘 Recommended for advanced users who want to automate dynamically.
See: MA Crossover Strategy Automation with Webhooks
👉 Full list of TradingView placeholders supported by Xerolite
📌 Summary
Feature | alert() Method | strategy.entry() + UI |
---|---|---|
Code Location | Fully in script | Part in script + TradingView UI |
Placeholders Support | ❌ | ✅ |
Dynamic Qty / Price | ❌ | ✅ |
Beginner-Friendly | ✅ | ⚠️ Intermediate |
Recommended For | Simple alerts | Flexible strategy automation |
🛠️ Smart Alert Builder
Use the Xerolite Smart Alert Builder to generate:
- ✅ Static JSON for alert()
- ✅ Dynamic JSON with TradingView placeholders

✅ It helps prevent typos and ensures full compatibility with Xerolite webhook format.