Using Pine Script Variables in Alerts: Indicators vs. Strategies

Master TradingView alert placeholders for indicators and strategies. Learn how to use {{ticker}}, {{strategy.order.action}}, and 20+ other dynamic variables to create powerful, automated alert messages.

Using Pine Script Variables in Alerts: Indicators vs. Strategies

When creating alerts in TradingView, you can use special placeholders to dynamically include variable values in the alert message. However, different placeholders apply depending on whether the alert is based on an indicator or a strategy. Below is a comprehensive breakdown of all available placeholders and their usage.

Placeholders for Indicators

These placeholders can be used when setting alerts based on indicators:

General Information

  • {{ticker}} – The symbol's ticker (e.g., AAPL, BTCUSD).
  • {{exchange}} – The exchange where the symbol is traded (e.g., NASDAQ, NYSE, CME). For delayed symbols, it may end with _DL or _DLY.
  • {{interval}} – The timeframe of the chart where the alert is created. On price-based alerts and Range charts, this always returns "1" (1-minute timeframe).

Bar Data (Applies to price alerts and indicator-based alerts)

  • {{close}}, {{open}}, {{high}}, {{low}} – The respective values of the bar that triggered the alert.
  • {{volume}} – The trading volume of the current bar.
  • {{time}} – The bar's timestamp in UTC (yyyy-MM-ddTHH:mm:ssZ format).
  • {{timenow}} – The exact time when the alert was triggered (differs from {{time}} if the alert is delayed).

Indicator-Specific Placeholders

  • {{plot_0}}, {{plot_1}}, ..., {{plot_19}} – Outputs from the indicator on which the alert is set. The numbering follows the order in which the series are defined in the indicator's Pine Script (up to 20 plots).
  • {{plot("Name")}} – Refers to an indicator's plot by its title (as set in plot(title="Name")).
  • For built-in indicators, the English name must be used when referencing plots.

Currency Information

  • {{syminfo.currency}} – The currency of the symbol (e.g., "USD", "EUR").
  • {{syminfo.basecurrency}} – The base currency of a forex pair (e.g., "EUR" for "EURUSD").

Example for a Volume indicator:

Volume: {{plot_0}}, Volume MA: {{plot_1}}

Placeholders for Strategies

When setting alerts on strategies, additional placeholders prefixed with {{strategy.}} provide trade execution details:

Order Execution Details

  • {{strategy.order.action}} – "buy" or "sell" depending on the order executed.
  • {{strategy.order.contracts}} – The number of contracts traded.
  • {{strategy.order.price}} – The price at which the order was executed.
  • {{strategy.order.id}} – The unique ID of the executed order (set in strategy.entry, strategy.exit, or strategy.order).
  • {{strategy.order.comment}} – The order comment (if none, it defaults to strategy.order.id).
  • {{strategy.order.alert_message}} – A custom alert message set in strategy.entry, strategy.exit, or strategy.order (Pine v4+ required).

Position Tracking

  • {{strategy.position_size}} – The number of contracts in the current position (can be negative for short positions).
  • {{strategy.market_position}} – "long", "flat", or "short", indicating the current market position.
  • {{strategy.market_position_size}} – The absolute size of the current position.
  • {{strategy.prev_market_position}} – The previous market position ("long", "flat", or "short").
  • {{strategy.prev_market_position_size}} – The absolute size of the previous position.

Using Placeholders in Pine Script

When using Pine Script, you can insert these placeholders into alert messages. Example for an indicator-based alert:

//@version=6
indicator("My Indicator", overlay=true)
plot(close, title="Series")
alertcondition(close > open, title="Price Alert", message="Price {{ticker}} = {{close}}")

For a strategy-based alert, placeholders go in the alert dialog's Message box, not inside the script. TradingView's manual notes that placeholders are not filled in inside alert_message. When you want the script itself to write the message, build the values in Pine:

//@version=6
strategy("My Strategy", overlay = true)
if close > open
    strategy.entry("Long", strategy.long, alert_message = "Trade executed: buy " + syminfo.ticker + " at " + str.tostring(close))

Important Notes

  1. Case Sensitivity: All placeholders are case-sensitive and must use lowercase letters exactly as shown.
  2. Version Requirements: The {{strategy.order.alert_message}} placeholder requires Pine Script v4 or higher. All examples in this guide use Pine Script v6, the current version.
  3. Interval Behavior: The {{interval}} placeholder returns "1" for:
    • Price-based alerts (calculated on 1-minute data)
    • Range charts (built from 1-minute data)
  4. Plot Limitations: Only the first 20 plots (numbered 0-19) are accessible via placeholders.
  5. Built-in Indicators: When referencing plots by name in built-in indicators, you must use the English titles.

CrossTrade Integration: Automated Trading with Strategy Sync

Here's how these placeholders work in a CrossTrade webhook payload. Our Strategy Sync engine ensures your NinjaTrader 8 account stays perfectly synchronized with your TradingView strategy.

Example Alert Configuration

Here's how to configure a TradingView alert message to work with CrossTrade's automated trading system. Note that CrossTrade primarily utilizes strategy-related placeholders for automated trading, while indicator placeholders are mainly for informational purposes:

key=your-secret-key;
command=PLACE;
account=Sim101;
instrument=NQ1!;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY;

// --- The New Sync Engine ---
sync_strategy=true;
market_position={{strategy.market_position}};
prev_market_position={{strategy.prev_market_position}};
out_of_sync=flatten;

How Strategy Sync Works

  1. Direction and size fill in automatically. {{strategy.order.action}} and {{strategy.order.contracts}} carry the side and quantity of the order the strategy just placed.
  2. The strategy states where it expects to be. {{strategy.market_position}} and {{strategy.prev_market_position}} tell CrossTrade the position before and after this order.
  3. CrossTrade checks before every entry. With sync_strategy=true, it compares that expectation with the live position on the destination account just before the order is placed.
  4. You choose what happens on a mismatch. out_of_sync=flatten closes the position on that account and contract and waits for the next clean entry. resync sends a correcting order instead, and wait skips the signal.
💡
TradingView fills in every placeholder before the alert leaves TradingView, so CrossTrade receives finished values, never the braces. That means any field can carry one: instrument={{ticker}} or limit_price={{close}} work in an indicator alert just as action={{strategy.order.action}} does in a strategy alert. The only rule is that {{strategy.*}} placeholders resolve only when the alert fires from a strategy.

Quick reference: every placeholder

Placeholder Returns Works in
{{ticker}} The symbol, such as ES1! Any alert
{{exchange}} The exchange, such as CME_MINI Any alert
{{interval}} The chart timeframe Any alert
{{open}} {{high}} {{low}} {{close}} Prices of the bar that fired the alert Any alert
{{volume}} Volume of that bar Any alert
{{time}} Bar open time, UTC Any alert
{{timenow}} The moment the alert fired, UTC Any alert
{{plot_0}} to {{plot_19}} An indicator's plotted values, in order Indicator alerts
{{plot("Name")}} A plot by its title Indicator alerts
{{syminfo.currency}} {{syminfo.basecurrency}} The symbol's currencies Any alert
{{strategy.order.action}} buy or sell Strategy alerts
{{strategy.order.contracts}} Size of the order that filled Strategy alerts
{{strategy.order.price}} Its fill price Strategy alerts
{{strategy.order.id}} Its order ID Strategy alerts
{{strategy.order.comment}} Its comment, or the ID if none Strategy alerts
{{strategy.order.alert_message}} The alert_message set in Pine Strategy alerts
{{strategy.position_size}} Position after the fill, negative when short Strategy alerts
{{strategy.market_position}} long, short or flat after the fill Strategy alerts
{{strategy.market_position_size}} Absolute position size after the fill Strategy alerts
{{strategy.prev_market_position}} long, short or flat before the fill Strategy alerts
{{strategy.prev_market_position_size}} Absolute position size before the fill Strategy alerts

Placeholders in a JSON alert

CrossTrade also reads webhook messages written as JSON, with the same field names. Placeholders work inside JSON string values. Keep every placeholder in quotes, including numeric ones: TradingView substitutes the raw text first, and an unquoted placeholder that fills in unexpectedly produces invalid JSON, which CrossTrade rejects rather than guesses at.

{
  "key": "your-secret-key",
  "command": "place",
  "account": "Sim101",
  "instrument": "{{ticker}}",
  "action": "{{strategy.order.action}}",
  "qty": "{{strategy.order.contracts}}",
  "order_type": "market",
  "tif": "day",
  "sync_strategy": "true",
  "market_position": "{{strategy.market_position}}",
  "prev_market_position": "{{strategy.prev_market_position}}",
  "target_quantity": "{{strategy.position_size}}",
  "out_of_sync": "resync"
}

Add "destination": "tradovate" to send the same order to a linked Tradovate account. The full rules are in the JSON webhook format docs, and a walkthrough is in TradingView Webhook JSON.

Frequently asked questions

What are TradingView alert placeholders?

Text in double braces, such as {{ticker}} or {{close}}, that TradingView replaces with a live value when the alert fires. The webhook receives the finished value, not the braces.

Why does {{strategy.order.action}} come through empty?

The alert was created on an indicator or with a price condition. Strategy placeholders only resolve when the alert's condition is the strategy itself.

Can I use placeholders in a JSON webhook message?

Yes, inside string values. Keep every placeholder in quotes so the message stays valid JSON after TradingView fills it in.

What is the difference between position_size and market_position_size?

{{strategy.position_size}} is negative when short. {{strategy.market_position_size}} is always positive, and {{strategy.market_position}} carries the direction.

Do placeholders work inside alert_message or alert()?

TradingView fills placeholders in the alert dialog's Message box. Inside a script, build the values in Pine instead, with syminfo.ticker and str.tostring(close).

Final Thoughts

TradingView's alert placeholder system provides traders with a powerful toolkit for creating dynamic, informative alert messages. Whether you're working with simple indicator-based alerts using basic placeholders like {{ticker}} and {{close}}, or building sophisticated strategy alerts that leverage position tracking with {{strategy.market_position}} and order details via {{strategy.order.action}}, these placeholders transform static alert messages into rich, contextual notifications.

Remember to pay attention to case sensitivity, version requirements, and the specific behavior of placeholders like {{interval}} to ensure your alerts work reliably across all market conditions and timeframes.


Ready to automate your TradingView strategies with CrossTrade?

Start your free trial

Try CrossTrade for 7 days.

Sign Up