TradingView alert messages

TradingView Alert Placeholders: Syntax, JSON Webhooks, and Reference

TradingView alert placeholders insert values into supported alert messages. Use {{strategy.order.action}} for an executed order and {{strategy.market_position}} for the resulting position. {{strategy.position_avg_price}} is not in TradingView's documented placeholder list: strategy.position_avg_price is a Pine Script variable. To send that value, build a message in Pine with str.tostring() and alert(), which does not parse placeholders.

Build an alert script

Is strategy.position_avg_price an alert placeholder?

No documented placeholder has that name. Adding double braces around a Pine variable does not make it a supported alert field. The variable strategy.position_avg_price contains the simulated position's average entry price and is na when there is no open position. Use {{strategy.order.price}} when you need the price of the order that triggered a fill alert; use Pine code when you need the position average.

Value neededUseMeaning
Executed order price{{strategy.order.price}}Price of this broker-emulator fill.
Position averagestrategy.position_avg_price in PineAverage entry price of the open simulated position; handle na explicitly.
Live account averageBroker or execution-service dataTradingView strategy state does not verify the receiving account's actual fills.

Strategy order and position placeholders

Use these fields in a strategy order-fill alert message. Order quantity describes the transaction; position size describes exposure after it. For example, a sell order can close a long position to flat, so action alone does not identify the resulting direction.

  • A reversal transaction can be larger than the resulting position because it closes existing exposure and opens the opposite side.
  • Do not treat a TradingView fill alert as confirmation that an external broker accepted or filled an order.
PlaceholderValueInterpretation
{{strategy.order.action}}buy or sellDirection of the filled order.
{{strategy.order.contracts}}NumberQuantity traded by that order.
{{strategy.order.price}}NumberEmulated execution price.
{{strategy.order.id}}TextIdentifier of the filled order.
{{strategy.order.comment}}TextOrder comment, or the order ID if no comment is set.
{{strategy.order.alert_message}}TextCustom alert_message supplied by the order command.
{{strategy.market_position}}long, short, or flatPosition direction after the fill.
{{strategy.market_position_size}}Nonnegative numberAbsolute position size after the fill.
{{strategy.position_size}}Signed numberPositive for long exposure, negative for short exposure.
{{strategy.prev_market_position}}long, short, or flatPosition direction before the fill.
{{strategy.prev_market_position_size}}Nonnegative numberAbsolute size before the fill.

Trigger and field availability matrix

Select the trigger before writing the message. Choosing a combined strategy alert enables two event paths, each with its own message construction. Historical strategy trades do not send a backlog of alerts; notifications apply to realtime events.

  • Chart fields include {{ticker}}, {{exchange}}, {{open}}, {{high}}, {{low}}, {{close}}, and {{volume}}.
  • {{time}} is the triggering bar's time; {{timenow}} is the alert fire time. Both use UTC, but they describe different events.
  • {{interval}} can return 1 for simple price alerts and Range charts, regardless of the chart interval.
  • Indicator values can use {{plot_0}} through {{plot_19}}, or a supported named plot such as {{plot("RSI")}}.
TriggerChart placeholdersStrategy order placeholdersCustom Pine values
Strategy order fillSupported in the alert dialogSupported in the alert dialogUse the order command's alert_message and its placeholder.
Strategy or indicator alert()Not parsedNot parsedConcatenate values into the message in Pine.
Indicator alertcondition()SupportedNot availableExpose numeric series through plots and plot placeholders.
Price alertSupportedNot availableNo arbitrary Pine variables.

JSON template for order-fill alerts

Select your strategy and include order fills, then put this template in the Message field. It is an illustrative payload, not a universal broker API schema. Text values are quoted; numeric fields are unquoted. TradingView sends valid JSON with application/json and other messages with text/plain.

  • If the receiver requires numbers, quoting numeric placeholders changes the schema to strings and is not a general fix.
  • Free-form order IDs, comments, or user inputs need JSON escaping for quotes, backslashes, and control characters. This template omits those fields.
  • Do not put passwords, broker credentials, or API keys in the message. Follow the receiving service's authentication instructions.
Order-fill message template; numeric tokens become JSON values after substitutionjson
{
  "symbol": "{{ticker}}",
  "exchange": "{{exchange}}",
  "action": "{{strategy.order.action}}",
  "contracts": {{strategy.order.contracts}},
  "order_price": {{strategy.order.price}},
  "market_position": "{{strategy.market_position}}",
  "market_position_size": {{strategy.market_position_size}},
  "fired_at": "{{timenow}}"
}

Send the position average with Pine Script v6

This complete teaching strategy uses alert() to report a changed position at the next bar-close calculation that observes it. It serializes a missing average as JSON null. This is a position-state notification, not an exact fill-time event. The EMA conditions only provide example orders and are not a trading recommendation.

  • For position-state JSON, create an alert on this strategy using alert() function calls. The message comes from the code.
  • For the separate fill event messages, include order fills and set the dialog Message to {{strategy.order.alert_message}} without surrounding quotes.
  • Selecting both event types can produce a fill notification followed by a position-state notification. Route them by event; do not execute the same trade twice.
  • This example detects size changes. A strategy that closes and reopens the same size between calculations needs different state tracking.
  • Default market orders normally fill on the next available tick. calc_on_order_fills changes calculation timing and can alter historical results; it is not enabled here.
Complete v6 example: position-state JSON and separate custom order-fill messagespinescript
//@version=6
strategy("Position average alert example", overlay=true)

int fastLength = input.int(9, "Fast EMA", minval=1)
int slowLength = input.int(21, "Slow EMA", minval=1)
float fast = ta.ema(close, fastLength)
float slow = ta.ema(close, slowLength)
bool enterLong = ta.crossover(fast, slow)
bool exitLong = ta.crossunder(fast, slow)

if enterLong and strategy.position_size == 0
    strategy.entry("Long", strategy.long, alert_message='{"event":"long_entry_fill"}')
if exitLong and strategy.position_size > 0
    strategy.close("Long", alert_message='{"event":"long_exit_fill"}')

bool positionChanged = strategy.position_size != nz(strategy.position_size[1])
if barstate.isconfirmed and positionChanged
    string average = na(strategy.position_avg_price) ? "null" : str.tostring(strategy.position_avg_price, format.mintick)
    string message = '{"event":"position_observed","position_size":' + str.tostring(strategy.position_size) + ',"position_avg_price":' + average + '}'
    alert(message, alert.freq_once_per_bar_close)

plot(fast, "Fast EMA", color=color.blue)
plot(slow, "Slow EMA", color=color.orange)

Validate one alert before connecting an executor

The procedure below is a reproducible check, not a claim of a completed live webhook test. Syntax validation alone cannot establish that a receiver accepts your message or that an external order executes.

CheckWhat to inspectCorrection
Unsupported tokenA token remains literal or a field is missing.Match the token to the official list and event type; serialize Pine variables in code.
JSON parsingCapture the actual received body and parse it as JSON.Repair quoting, escaping, or missing numeric values before retrying.
Receiver schemaCompare field names, types, symbol format, and units with its API.Adapt the example to the receiver; valid JSON does not imply a valid order.
Empty custom messageAn order command omitted alert_message.Set it on every relevant command when using strategy.order.alert_message.
Stale settingsThe running alert uses earlier script or input values.Recreate the alert after changing the script, inputs, symbol, or timeframe.
No historical notificationsA chart shows older fills but no corresponding alerts.Wait for a qualifying realtime event; historical trades do not replay as alerts.
Where Pineify fits

Pine Script AI Coding Agent

Use Pineify to draft or revise the Pine code that builds your alert message. Include the trigger type and the receiver's field schema in your request, then verify the resulting payload in TradingView and your receiver.

Build an alert script

Frequently asked questions

Educational programming reference, not investment advice. Example orders are simulated; syntax checks do not verify webhook delivery, broker execution, or strategy profitability. Test the receiver in a non-executing environment before enabling order routing.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.