Reference15 min read2026-01-10

TradingView Alert JSON Format: Complete Reference Guide

Master the TradingView alert JSON format for webhook automation. Full reference of variables, examples, and best practices for trading bots.

RoboQuant

RoboQuant Team

Trading Automation Experts

tradingviewjsonwebhooksreferenceapi
TradingView Alert JSON Format: Complete Reference Guide

Understanding TradingView Alert JSON

When you create a TradingView alert with a webhook, the "Message" field contains the data sent to your automation platform. This is typically formatted as JSON (JavaScript Object Notation).

Getting the JSON format right is crucial - a single typo can cause your orders to fail.

Basic JSON Structure

JSON consists of key-value pairs enclosed in curly braces:

{
  "key1": "value1",
  "key2": "value2",
  "key3": 123
}

Important Rules

  1. Keys must be in double quotes: "symbol" not symbol
  2. String values need quotes: "buy" not buy
  3. Numbers don't need quotes: 123 not "123"
  4. No trailing commas: The last item shouldn't have a comma after it

TradingView Placeholder Variables

TradingView provides dynamic variables that get replaced when the alert fires:

Price & Time Variables

VariableDescriptionExample Output
{{ticker}}Symbol nameES1!, NQ1!
{{exchange}}ExchangeCME, NYMEX
{{close}}Closing price5050.25
{{open}}Opening price5048.00
{{high}}High price5055.00
{{low}}Low price5045.00
{{volume}}Volume15000
{{time}}Alert time (UTC)2025-01-12T14:30:00Z
{{timenow}}Current time2025-01-12T14:30:05Z

Strategy Variables

VariableDescriptionExample Output
{{strategy.order.action}}Order directionbuy, sell
{{strategy.order.contracts}}Position size1, 2, 5
{{strategy.order.price}}Order price5050.25
{{strategy.order.id}}Order IDLong Entry
{{strategy.order.comment}}Order commentMy custom comment
{{strategy.position_size}}Current position2, -1, 0
{{strategy.prev_market_position}}Previous positionlong, short, flat
{{strategy.market_position}}Current market positionlong, short, flat

Alert Variables

VariableDescriptionExample Output
{{alert.message}}Custom alert messagePrice crossed 5000
{{interval}}Chart timeframe15, 60, D
{{syminfo.currency}}Quote currencyUSD

Common JSON Templates

Basic Order

The simplest format for placing an order:

{
  "symbol": "{{ticker}}",
  "side": "{{strategy.order.action}}",
  "quantity": {{strategy.order.contracts}}
}

With Stop Loss and Take Profit

Add risk management to your orders:

{
  "symbol": "{{ticker}}",
  "side": "{{strategy.order.action}}",
  "quantity": {{strategy.order.contracts}},
  "stopLoss": 10,
  "stopLossType": "points",
  "takeProfit": 20,
  "takeProfitType": "points"
}

Using Ticks Instead of Points

For more precise stop/target placement:

{
  "symbol": "ESZ4",
  "side": "buy",
  "quantity": 2,
  "stopLoss": 40,
  "stopLossType": "ticks",
  "takeProfit": 80,
  "takeProfitType": "ticks"
}

Using Dollar Amounts

Set stops based on dollar risk:

{
  "symbol": "NQZ4",
  "side": "sell",
  "quantity": 1,
  "stopLoss": 200,
  "stopLossType": "dollars",
  "takeProfit": 400,
  "takeProfitType": "dollars"
}

Multi-Account Trading

Execute on multiple accounts simultaneously:

{
  "symbol": "{{ticker}}",
  "side": "{{strategy.order.action}}",
  "quantity": {{strategy.order.contracts}},
  "accountIds": ["account1", "account2", "account3"]
}

Close Position

To close an existing position:

{
  "symbol": "ESZ4",
  "side": "close",
  "quantity": 0
}

Flatten All Positions

Close everything on an account:

{
  "action": "flatten",
  "symbol": "all"
}

Advanced Configurations

Conditional Orders

Include metadata for conditional logic:

{
  "symbol": "{{ticker}}",
  "side": "{{strategy.order.action}}",
  "quantity": {{strategy.order.contracts}},
  "conditions": {
    "maxDailyLoss": 500,
    "maxPositionSize": 5,
    "tradingHoursOnly": true
  }
}

With Order Comments

Track orders with custom identifiers:

{
  "symbol": "{{ticker}}",
  "side": "{{strategy.order.action}}",
  "quantity": {{strategy.order.contracts}},
  "comment": "{{strategy.order.comment}}",
  "strategyId": "my-breakout-strategy"
}

Including Price Data

Pass current market data with the order:

{
  "symbol": "{{ticker}}",
  "side": "{{strategy.order.action}}",
  "quantity": {{strategy.order.contracts}},
  "triggerPrice": {{close}},
  "high": {{high}},
  "low": {{low}},
  "time": "{{time}}"
}

Common Mistakes to Avoid

1. Missing Quotes Around Strings

❌ Wrong:

{
  "symbol": {{ticker}},
  "side": buy
}

✅ Correct:

{
  "symbol": "{{ticker}}",
  "side": "buy"
}

2. Quotes Around Numbers

❌ Wrong:

{
  "quantity": "{{strategy.order.contracts}}"
}

✅ Correct:

{
  "quantity": {{strategy.order.contracts}}
}

3. Trailing Commas

❌ Wrong:

{
  "symbol": "ESZ4",
  "side": "buy",
}

✅ Correct:

{
  "symbol": "ESZ4",
  "side": "buy"
}

4. Invalid Variable Names

❌ Wrong:

{
  "side": "{{order.action}}"
}

✅ Correct:

{
  "side": "{{strategy.order.action}}"
}

Validating Your JSON

Before using your JSON in a live alert:

Online JSON Validators

Use tools like jsonlint.com to check your syntax.

Test with a Dummy Webhook

  1. Use a service like webhook.site
  2. Set it as your webhook URL
  3. Trigger your alert
  4. Verify the JSON is formatted correctly

Symbol Mapping

Different platforms use different symbol formats:

TradingViewTradovateDescription
ES1!ESZ4S&P 500 E-mini
NQ1!NQZ4Nasdaq E-mini
CL1!CLZ4Crude Oil
GC1!GCZ4Gold
RTY1!RTYZ4Russell 2000

Tip: Hardcode the Tradovate symbol instead of using {{ticker}} to avoid mapping issues.

Conclusion

Mastering the TradingView alert JSON format is essential for reliable trading automation. Start with simple templates, validate your JSON before going live, and gradually add complexity as needed.

Need help with your JSON setup? Try RoboQuant - our platform validates your webhook messages automatically.

Share this article:

Ready to Automate Your Trading?

Connect TradingView to Tradovate and start executing your strategies automatically.