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 the iNakaTrader signal bridge.
Basic Structure
Every alert message is a JSON object. At minimum, every alert needs an alert_name and a magic:
{
"alert_name": "alertX",
"magic": 999888,
"symbol": "XAUUSD",
"action": "BUY"
}
Required on every alert:
- alert_name — Which alert type this is: alertS, alertX, alertY, alertZ, alertZ1, alertZ2, alertReset, or one of the Pine Script forms (buy, sell, open, close, close_all)
- magic — Magic Number identifying which strategy this belongs to (must match the EA's MagicNumber input)
Common optional fields on trade-opening alerts:
- symbol — Trading instrument (e.g., EURUSD, XAUUSD)
- action — BUY, SELL, BLM (buy limit), SLM (sell limit), BST (buy stop), SST (sell stop)
- volume — Lot size (0.01 = micro, 0.1 = mini, 1.0 = standard)
- tp — Take profit in points (or ATR string like "2atr")
- sl — Stop loss in points (or ATR string like "1.5atr")
Important — points, not pips. TP and SL values are in points. On a 5-digit broker, 500 points = 50 pips. On XAUUSD, 500 points = $5.00 move. ATR-based values use a string like
"2atr"for 2× current ATR.
Alert Types
alertX — Arm a Trade (step 1 of 2)
Sets up a pending trade that waits for alertY confirmation. The trade does NOT execute until alertY arrives:
{
"alert_name": "alertX",
"magic": 999888,
"symbol": "EURUSD",
"action": "BUY",
"volume": 0.01,
"sl": 300,
"tp": 600
}
alertY — Confirm and Execute (step 2 of 2)
Confirms the armed trade and triggers execution. Must arrive AFTER an alertX for the same magic:
{
"alert_name": "alertY",
"magic": 999888,
"symbol": "EURUSD"
}
alertY may also override any field from alertX (volume, tp, sl, action, etc.).
alertZ — Instant Close
Close positions immediately, no confirmation:
{
"alert_name": "alertZ",
"magic": 999888,
"symbol": "EURUSD",
"close_type": "all"
}
close_type options:
- "all" — close all positions for this magic (default)
- "buy" — close only BUY positions
- "sell" — close only SELL positions
- "profit" — close only positions in profit
- "loss" — close only positions in loss
Optional "reset_after_close": true resets strategy state after the close.
alertZ1 + alertZ2 — Guarded Close
Two-step close to prevent accidental liquidation:
{
"alert_name": "alertZ1",
"magic": 999888,
"symbol": "EURUSD",
"close_type": "all"
}
Then within the timeout (default 300 seconds, configurable via timeout_seconds):
{
"alert_name": "alertZ2",
"magic": 999888,
"symbol": "EURUSD"
}
If alertZ2 doesn't arrive within the timeout, the close is cancelled.
alertS — Loop Control / Pine Registration
Start, stop, or configure a strategy.
Start trading (BUY + SELL allowed):
{
"alert_name": "alertS",
"magic": 999888,
"symbol": "EURUSD",
"loop_action": "START"
}
Stop trading:
{
"alert_name": "alertS",
"magic": 999888,
"symbol": "EURUSD",
"loop_action": "STOP"
}
loop_action options: START, STOP, START BUY, STOP BUY, START SELL, STOP SELL.
Start with defaults:
{
"alert_name": "alertS",
"magic": 999888,
"symbol": "EURUSD",
"loop_action": "START",
"volume": 0.01,
"tp": 500,
"sl": 250,
"max_open_buy": 3,
"max_open_sell": 3
}
Register Pine Script mode:
{
"alert_name": "alertS",
"magic": 999888,
"symbol": "EURUSD",
"pine_mode": true,
"volume": 0.01,
"tp": 500,
"sl": 250
}
Pine Script entries — buy / sell / open
Once Pine Script mode is registered via alertS, direct entries use alert_name "buy", "sell", or "open":
{
"alert_name": "{{strategy.order.action}}",
"magic": 999888,
"symbol": "{{ticker}}",
"action": "{{strategy.order.action}}"
}
{{strategy.order.action}} is replaced by TradingView with buy or sell, which matches both alert_name and action.
Pine Script close — close / close_all
{
"alert_name": "close",
"magic": 999888,
"symbol": "EURUSD"
}
Optional "close_type": "buy" / "sell" / "all" (default "all").
alertReset — Full State Reset
Clears all counters, queues, armed states, and direction locks:
{
"alert_name": "alertReset",
"magic": 999888
}
alertReset does not take a symbol. Schedule it daily before market open for a clean slate.
Risk Management Parameters
Add these to any trade-opening alert (alertX, alertS defaults, or Pine direct):
Trailing Stop
{
"trailing_activate": 300,
"trailing_distance": 150
}
trailing_activate— Points in profit before trailing startstrailing_distance— How far behind price the SL trails
Breakeven
{
"move_sl_after": 250,
"move_sl_to": 30
}
move_sl_after— Points in profit before SL moves to breakevenmove_sl_to— Points above entry to place the new SL (buffer for spread)
Partial Take Profit (up to 4 levels)
{
"partial_tp": "0.03=300,0.03=600,0.03=900,0.01=1200"
}
Format: "volume=points,volume=points,..." — each level specifies the lot size to close at that point target. Up to 4 levels. When partial_tp is set, the signal's tp is automatically set to 0 (the partial system manages exits).
TP / SL trigger limits
Stop new entries after N take-profit or stop-loss hits — useful as a daily kill-switch:
{
"tp_limit": 5,
"sl_limit": 3
}
Counts only DEAL_REASON_TP / DEAL_REASON_SL closes per magic. Send 0 to disable.
ATR-based TP/SL
Instead of fixed points, use a string "<multiplier>atr":
{
"tp": "2atr",
"sl": "1.5atr",
"atr_period": 14,
"atr_timeframe": "D1"
}
Defaults: atr_period: 14, atr_timeframe: D1. Accepted timeframes: M1, M5, M15, M30, H1, H4, D1, W1, MN1.
Complete Examples
Conservative Day Trade (EURUSD)
{
"alert_name": "alertX",
"magic": 1001,
"symbol": "EURUSD",
"action": "BUY",
"volume": 0.1,
"sl": 400,
"tp": 800,
"move_sl_after": 200,
"move_sl_to": 30,
"trailing_activate": 400,
"trailing_distance": 200
}
Aggressive Gold Scalp (XAUUSD)
{
"alert_name": "alertX",
"magic": 2001,
"symbol": "XAUUSD",
"action": "SELL",
"volume": 0.05,
"sl": 800,
"tp": 1600,
"move_sl_after": 400,
"move_sl_to": 100,
"trailing_activate": 600,
"trailing_distance": 300,
"partial_tp": "0.02=500,0.02=1000"
}
Pine Script Strategy with Full Risk Management
Register the strategy first (sets defaults for every Pine entry on this magic):
{
"alert_name": "alertS",
"magic": 3001,
"symbol": "GBPUSD",
"pine_mode": true,
"volume": 0.15,
"sl": 350,
"tp": 1000,
"move_sl_after": 250,
"move_sl_to": 50,
"trailing_activate": 500,
"trailing_distance": 200,
"partial_tp": "0.04=350,0.04=700"
}
Then the Pine Script alert on strategy.entry() / strategy.close():
{
"alert_name": "{{strategy.order.action}}",
"magic": 3001,
"symbol": "{{ticker}}",
"action": "{{strategy.order.action}}"
}
Multi-Timeframe Confirmation
Alert 1 (4H — trend direction, arms the trade):
{
"alert_name": "alertX",
"magic": 4001,
"symbol": "USDJPY",
"action": "BUY",
"volume": 0.2,
"sl": 500,
"tp": 1000,
"move_sl_after": 300,
"move_sl_to": 50
}
Alert 2 (15M — entry trigger, confirms):
{
"alert_name": "alertY",
"magic": 4001,
"symbol": "USDJPY"
}
Daily Reset
Set this alert to fire once per day at your preferred time:
{
"alert_name": "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
Wrong field names. The most common error after migrating from another bridge: using "action" for the alert type, "direction" for buy/sell, or "size" for lot size. iNakaTrader expects "alert_name", "action", and "volume" — see the field reference above.
Confusing pips with points. "sl": 30 is 30 points = 3 pips on a 5-digit broker, which is almost certainly tighter than you intended. Multiply your pip number by 10 for a 5-digit broker.
Invalid JSON. Missing quotes, trailing commas, 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? JSON is required. It's machine-parseable and supports complex parameters.
What's the maximum message length? TradingView allows up to 4,096 characters in alert messages. Plenty for any signal.
Can I include comments in the JSON? No. JSON does not support comments. Keep notes outside the alert message.
Where's the full parameter list? Every field, type, and accepted value lives in the iNakaTrader alert manual — keep it open while building your alerts.
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.