The alert message is the most critical part of automated trading with TradingView. Get the format wrong and your trades won't execute. Get it right and your strategy runs hands-free.
This is a complete reference for formatting TradingView alert messages when using a webhook signal bridge like iNakaTrader.
Basic Structure
Every alert message is a JSON object with at minimum an action field:
{
"action": "alertX",
"symbol": "EURUSD",
"magic": 1001,
"direction": "BUY"
}
Required fields:
- action — What type of alert this is (alertX, alertY, alertZ, alertS, pine, etc.)
- magic — Magic Number identifying which strategy this belongs to
Common optional fields:
- symbol — Trading instrument (e.g., EURUSD, XAUUSD)
- direction — BUY or SELL
- size — Lot size (0.01 = micro, 0.1 = mini, 1.0 = standard)
- sl — Stop loss in pips
- tp — Take profit in pips
Alert Types
alertX — Arm a Trade
Sets up a pending trade that waits for alertY confirmation:
{
"action": "alertX",
"symbol": "EURUSD",
"magic": 1001,
"direction": "BUY",
"size": 0.1,
"sl": 30,
"tp": 60
}
The trade is armed but not executed. It waits for a matching alertY.
alertY — Confirm and Execute
Confirms the armed trade and triggers execution:
{
"action": "alertY",
"magic": 1001
}
alertY must follow alertX for the same Magic Number. If no alertX is pending, alertY is ignored.
alertZ — Instant Close
Close positions immediately:
{"action": "alertZ", "magic": 1001, "close": "all"}
Close options:
- "all" — Close all positions for this magic number
- "buy" — Close only BUY positions
- "sell" — Close only SELL positions
- "profit" — Close positions in profit
- "loss" — Close positions in loss
alertZ1 + alertZ2 — Guarded Close
Two-step close to prevent accidental liquidation:
{"action": "alertZ1", "magic": 1001}
Then within 5 minutes:
{"action": "alertZ2", "magic": 1001, "close": "all"}
If alertZ2 doesn't arrive within the timeout, the close is cancelled.
alertS — Loop Control / Configuration
Start, stop, or configure a strategy:
Start trading:
{"action": "alertS", "magic": 1001, "start": "START", "symbol": "EURUSD", "size": 0.1, "sl": 30, "tp": 60}
Stop trading:
{"action": "alertS", "magic": 1001, "start": "STOP"}
Direction filters:
{"action": "alertS", "magic": 1001, "start": "START BUY"}
Options: START, STOP, START BUY, STOP BUY, START SELL, STOP SELL
Enable Pine Script mode:
{"action": "alertS", "magic": 1001, "pine_script": true, "symbol": "EURUSD", "size": 0.1, "sl": 30}
pine — Pine Script Entry/Exit
Direct execution from Pine Script strategies:
{
"action": "pine",
"symbol": "{{ticker}}",
"magic": 1001,
"direction": "{{strategy.order.action}}"
}
Requires Pine Script mode to be enabled via alertS first.
alertReset — Full State Reset
Clears all counters, queues, and direction locks:
{"action": "alertReset", "magic": 1001}
Use this as a daily reset alert to start each trading day with clean state.
Risk Management Parameters
Add these to any trade-opening alert (alertX or alertS):
Trailing Stop
{
"trail_activate": 30,
"trail_distance": 15
}
trail_activate— Pips in profit before trailing startstrail_distance— How far behind price the SL trails
Breakeven
{
"move_sl_after": 25,
"move_sl_to": 3
}
move_sl_after— Pips in profit before SL moves to breakevenmove_sl_to— Pips above entry to place the new SL (buffer for spread)
Partial Take Profit (up to 4 Levels)
{
"partial_tp": "0.03=30,0.03=60,0.03=90,0.01=120"
}
Format: "volume=pips,volume=pips,..." — each level specifies the lot size to close at that pip target. Up to 4 levels. When partial TP is set, the signal's tp is automatically set to 0 (the partial system manages exits instead).
Complete Examples
Conservative Day Trade
{
"action": "alertX",
"symbol": "EURUSD",
"magic": 1001,
"direction": "BUY",
"size": 0.1,
"sl": 40,
"tp": 80,
"move_sl_after": 20,
"move_sl_to": 3,
"trail_activate": 40,
"trail_distance": 20
}
Aggressive Gold Scalp
{
"action": "alertX",
"symbol": "XAUUSD",
"magic": 2001,
"direction": "SELL",
"size": 0.05,
"sl": 80,
"tp": 160,
"move_sl_after": 40,
"move_sl_to": 10,
"trail_activate": 60,
"trail_distance": 30,
"partial_tp": "0.02=50,0.02=100"
}
Pine Script Strategy with Full Risk Management
{
"action": "alertS",
"magic": 3001,
"symbol": "GBPUSD",
"pine_script": true,
"size": 0.15,
"sl": 35,
"tp": 100,
"move_sl_after": 25,
"move_sl_to": 5,
"trail_activate": 50,
"trail_distance": 20,
"partial_tp": "0.04=35,0.04=70"
}
Then use this alert for the Pine Script strategy:
{
"action": "pine",
"symbol": "{{ticker}}",
"magic": 3001,
"direction": "{{strategy.order.action}}"
}
Multi-Timeframe Confirmation
Alert 1 (4H chart — trend direction):
{
"action": "alertX",
"symbol": "USDJPY",
"magic": 4001,
"direction": "BUY",
"size": 0.2,
"sl": 50,
"tp": 100,
"move_sl_after": 30,
"move_sl_to": 5
}
Alert 2 (15M chart — entry trigger):
{"action": "alertY", "magic": 4001}
Daily Reset
Set this to fire once per day at your preferred time:
{"action": "alertReset", "magic": 1001}
TradingView Placeholders
Use these in your alert messages to insert dynamic values:
| Placeholder | Description | Example Output |
|---|---|---|
{{ticker}} |
Symbol name | EURUSD |
{{close}} |
Current close price | 1.09550 |
{{open}} |
Current open price | 1.09480 |
{{high}} |
Current high | 1.09620 |
{{low}} |
Current low | 1.09410 |
{{volume}} |
Current volume | 15234 |
{{time}} |
UTC timestamp | 2026-03-23T14:30:00Z |
{{interval}} |
Chart timeframe | 60 |
{{strategy.order.action}} |
Buy/sell | buy |
{{strategy.order.id}} |
Order ID | Long Entry |
Common Mistakes
Invalid JSON: Missing quotes around strings, trailing commas, using single quotes instead of double quotes. TradingView sends exactly what you type — if it's invalid JSON, the signal server can't parse it.
Wrong Magic Number: alertX on magic 1001 won't match alertY on magic 1002. Always verify magic numbers match between related alerts.
Missing comma: JSON requires commas between fields. "sl": 30 "tp": 60 will fail. It should be "sl": 30, "tp": 60.
Extra whitespace in placeholders: {{ ticker }} won't work — use {{ticker}} with no spaces.
FAQ
Can I use plain text instead of JSON? Some signal bridges support plain text, but JSON is strongly recommended. It's machine-parseable, less error-prone, and supports complex parameters.
What's the maximum message length? TradingView allows up to 4,096 characters in alert messages. This is more than enough for any trading signal.
Can I include comments in the JSON? No. JSON does not support comments. If you need notes, keep them outside the alert message.
Set up your alerts and start trading automatically. iNakaTrader processes all alert types with full risk management.
Risk Disclaimer: Trading forex and other financial instruments involves substantial risk of loss and is not suitable for all investors. Past performance does not guarantee future results. Only trade with capital you can afford to lose. iNakaTrader provides signal execution tools, not financial advice.