TradingView Alert JSON Format for MT5: Complete Guide

TradingView alert JSON code for MT5

The #1 question on MQL5 forums and r/algotrading: "What JSON format do I use for TradingView alerts to execute on MT5?" Every trade copier has its own format, and getting it wrong means your alerts fire but nothing executes. This guide covers the exact JSON syntax you need.

TradingView Alert JSON for MT5: How It Works

When a TradingView alert fires, it sends an HTTP POST request to your webhook URL. The message body contains whatever text you typed in the "Message" field — TradingView does not enforce JSON formatting. That is your responsibility.

The flow:

  1. Pine Script condition triggers → alert fires
  2. TradingView sends HTTP POST to your webhook URL
  3. Your copier EA receives the POST body
  4. EA parses the JSON and executes the trade on MT5

TradingView Copier Pro JSON Format

Here is the exact format TradingView Copier Pro expects:

Basic Buy Order

{
  "action": "buy",
  "symbol": "EURUSD",
  "lot": 0.1,
  "sl": 50,
  "tp": 100
}

Basic Sell Order

{
  "action": "sell",
  "symbol": "GBPUSD",
  "lot": 0.05,
  "sl": 40,
  "tp": 80
}

Close Position

{
  "action": "close",
  "symbol": "EURUSD"
}

Partial Close (50%)

{
  "action": "close",
  "symbol": "EURUSD",
  "percent": 50
}

All Available Fields

FieldTypeRequiredDescription
actionstring✅ Yes"buy", "sell", "close", "modify"
symbolstring✅ YesTrading pair (auto-remapped)
lotnumberFor openLot size (0.01–100)
slnumberNoStop loss in pips or price
tpnumberNoTake profit in pips or price
percentnumberNoPartial close percentage (1–99)
commentstringNoTrade comment
magicnumberNoMagic number for trade identification

Using Pine Script Variables in JSON

TradingView provides placeholder variables that get replaced with actual values when the alert fires. Here is how to use them correctly in your JSON message:

{
  "action": "{{strategy.order.action}}",
  "symbol": "{{ticker}}",
  "lot": 0.1,
  "sl": 50,
  "tp": 100,
  "comment": "{{strategy.order.id}}"
}

Available Pine Script Placeholders

PlaceholderOutputExample
{{strategy.order.action}}buy or sell"buy"
{{ticker}}Symbol name"EURUSD"
{{strategy.order.price}}Order price1.08542
{{strategy.order.contracts}}Position size10000
{{strategy.order.id}}Order label"Long Entry"
{{close}}Current close1.08540
{{time}}Bar time2026-03-09T…

Important: Always wrap placeholders in double quotes. {{strategy.order.action}} without quotes produces invalid JSON because if it outputs buy, the parser sees an unquoted string.

Common JSON Mistakes and Fixes

1. Missing Quotes Around Placeholders

Wrong:

{"action": {{strategy.order.action}}, "symbol": "EURUSD"}

Right:

{"action": "{{strategy.order.action}}", "symbol": "EURUSD"}

2. Trailing Comma

Wrong:

{"action": "buy", "symbol": "EURUSD", "lot": 0.1,}

Right:

{"action": "buy", "symbol": "EURUSD", "lot": 0.1}

3. Single Quotes Instead of Double

Wrong:

{'action': 'buy', 'symbol': 'EURUSD'}

Right:

{"action": "buy", "symbol": "EURUSD"}

4. Wrong Symbol Name

TradingView uses EURUSD but your broker might use EURUSDm or EURUSD.pro. TradingView Copier Pro handles symbol remapping automatically — you always send the TradingView symbol, and the EA maps it to your broker's format.

Advanced: Strategy with Multiple TPs

For strategies that take partial profits, send separate alerts for each TP level:

Entry Alert

{
  "action": "buy",
  "symbol": "EURUSD",
  "lot": 0.3,
  "sl": 30,
  "tp": 0,
  "comment": "ICT_entry"
}

TP1 Alert (Close 33%)

{
  "action": "close",
  "symbol": "EURUSD",
  "percent": 33,
  "comment": "TP1_hit"
}

TP2 Alert (Close 50% of Remaining)

{
  "action": "close",
  "symbol": "EURUSD",
  "percent": 50,
  "comment": "TP2_hit"
}

Testing Your JSON Before Going Live

  1. Validate syntax — paste your JSON into JSONLint to check for errors
  2. Fire a test alert — set up a manual TradingView alert with your JSON message
  3. Check the EA logs — TradingView Copier Pro logs every received webhook in the Experts tab
  4. Use a demo account first — verify execution before switching to live

Troubleshooting: Webhook Fires But No Trade

If your TradingView alert fires but no trade appears on MT5, check these in order:

  1. Is the EA running? Check for the smiley face on the chart
  2. Is AutoTrading enabled? The AutoTrading button in MT5 must be green
  3. Is the JSON valid? Copy the Experts tab output and validate it
  4. Is the symbol correct? Check your broker's exact symbol name
  5. Is the lot size valid? Some brokers have minimum lot requirements

For a full TradingView webhook troubleshooting guide, check our dedicated article.

Alert → Trade in Under 50ms

TradingView Copier Pro parses your JSON alerts and executes on MT5 instantly. Supports all fields, partial closes, and symbol remapping.

Get TradingView Copier Pro →