Guide

Pine Script Alert Message Placeholders and How to Use Them

Which {{placeholders}} work in a Pine Script alert message, where they fail, and how to build the JSON body a webhook needs.

•11 min read

You set up an alert, wire a webhook to it, and the message that arrives says Price crossed above EMA. Useful, until you have the same alert on eight symbols and three timeframes and nothing in the message tells you which chart fired. Or worse, the receiving server gets the literal text {{close}} instead of a number, because a bracket was misplaced or a quote was the wrong kind. Alert message placeholders fix the first problem and cause the second, and most of the confusion around them comes from one fact: TradingView fills them in at a different moment than your Pine Script runs.

This guide covers every placeholder TradingView documents, which ones need a strategy and which need an indicator, how the {{plot()}} forms work, how to build a JSON body that a webhook can parse, and what to do when you need dynamic text inside alert(), where placeholders are not the tool you want. The code blocks are complete Pine Script v6 and each one is meant to be pasted into the Pine Editor as it stands.

What a placeholder actually is

A placeholder is a token wrapped in double curly brackets, such as {{ticker}}. It is not Pine Script. Your script never sees it and cannot read its value. TradingView's alert system sees it: when the alert fires, TradingView scans the message text, swaps each known token for its current value, and sends the result. That is why placeholders work in the "Message" field of the Create Alert dialog and in the message argument of alertcondition(), both of which are plain text handed to the alert system.

This also explains the most common surprise. Because the swap happens after your script has finished its calculation for that bar, a placeholder can only report what the alert system knows: the symbol, the exchange, the timeframe, the values of the bar that triggered, the time, and the values your script plotted. It cannot report an arbitrary variable. If you have a variable called stopPrice and you want it in the message, a placeholder cannot reach it. You either plot it, or you build the message in code, and the last sections show both.

A second consequence is that the tokens are matched by exact spelling. A misspelled token such as {{tickr}} is not an error anywhere. TradingView sends the text {{tickr}} exactly as you typed it, and you find out when the receiving side chokes on it. Always read a fired alert at least once before you trust a template.

The placeholders you can rely on

TradingView's Pine Script manual lists a short set for alertcondition() and the alert dialog, and a longer set that only exists for strategy orders. The market ones are these.

{{ticker}} is the symbol's ticker, such as BTCUSDT. {{exchange}} is the exchange the symbol belongs to. Together they give you {{exchange}}:{{ticker}}, which is the form most people want because a bare ticker can exist on several exchanges. {{interval}} is the timeframe of the chart the alert was created on, so a 15 minute chart gives 15 and a daily chart gives 1D. There is one quirk worth knowing: Range charts are calculated from 1 minute data, so on a Range chart the placeholder always returns 1.

{{open}}, {{high}}, {{low}}, {{close}} and {{volume}} are the values of the bar on which the alert triggered. Two details matter here. On a bar that is still forming, these values are the current ones, and they can change before the bar closes. And {{close}} is the close of the bar that triggered, not the price at the instant the message was delivered. If your alert fires once per bar close, the two are the same. If it fires intrabar, {{close}} is simply the latest price at that moment.

{{time}} is the time at the beginning of the triggering bar, in UTC, formatted like 2026-09-04T14:35:00Z. {{timenow}} is the moment the alert fired, in UTC, with the same format and a precision of one second regardless of the chart's timeframe. The distinction is useful for debugging: if {{time}} and {{timenow}} are far apart on a bar-close alert, something delayed the delivery, and if they differ by almost exactly the timeframe, the alert fired at the close of the bar it names.

Finally, there are the plot placeholders, which deserve their own section.

Putting plotted values in the message

Indicators can include plotted values through two forms. {{plot_0}} through {{plot_19}} refer to plots by their position, starting at zero, in order of appearance in the script. Only the first twenty plots can be reached this way. {{plot("RSI")}} refers to a plot by its title argument, and it requires double quotes around the title inside the brackets. That in turn means the whole message string must be wrapped in single quotes, otherwise the quotes collide and the script does not compile.

The title form is the safer one. Position numbers break silently the moment you add or reorder a plot above the one you meant, and the message keeps working while quietly reporting the wrong series. A title survives reordering. Here is an indicator that uses it, together with the market placeholders.

pine
//@version=6
indicator("RSI cross alert with placeholders", overlay = false)

rsiLength = input.int(14, "RSI length", minval = 2)
rsiValue  = ta.rsi(close, rsiLength)

plot(rsiValue, "RSI", color = color.blue)
hline(50, "Midline", color = color.gray)

crossUp   = ta.crossover(rsiValue, 50)
crossDown = ta.crossunder(rsiValue, 50)

alertcondition(crossUp, "RSI above 50",
     'RSI crossed above 50 on {{exchange}}:{{ticker}} ({{interval}}). RSI {{plot("RSI")}}, close {{close}}')
alertcondition(crossDown, "RSI below 50",
     'RSI crossed below 50 on {{exchange}}:{{ticker}} ({{interval}}). RSI {{plot("RSI")}}, close {{close}}')

After you add this to a chart, open the Create Alert dialog, pick the script as the condition, and choose one of the two named alerts. The message field is pre-filled from the message argument, and you can edit it there too. Two limits apply. Only numeric values can be reached, because strings cannot be plotted, so a text variable can never arrive through {{plot()}}. And a value only exists as a plot if you plot it. If you want a number in the message that you do not want drawn on the chart, plot it with display = display.none, which keeps it available to the alert while hiding it from the chart.

pine
//@version=6
indicator("Hidden plot for alert text", overlay = true)

atrValue = ta.atr(14)
stopGap  = atrValue * 1.5

// Not drawn on the chart, but reachable as {{plot("StopGap")}}.
plot(stopGap, "StopGap", display = display.none)

longSignal = ta.crossover(close, ta.sma(close, 50))
plotshape(longSignal, "Long", shape.triangleup, location.belowbar, color.green, size = size.tiny)

alertcondition(longSignal, "Close above SMA 50",
     'Close crossed above the 50 SMA on {{ticker}}. Gap to use for a stop: {{plot("StopGap")}}')

Building a JSON body for a webhook

If the message goes to a webhook, the receiving server usually expects JSON, and that changes how you write the template. JSON has two rules that placeholders interact with. Text values need double quotes, and numbers must not have them. So a template that wants a numeric price and a text symbol looks like this: {"ticker": "{{ticker}}", "price": {{close}}}. The ticker sits inside quotes because it is text, and the price sits outside because the server wants a number. Wrap a number in quotes and many servers will reject it or treat it as a string, and leave a text value bare and the JSON is invalid.

In Pine Script, that template is a single quoted string, because the JSON itself uses double quotes. It can be a constant, which is exactly what alertcondition() needs, since its message must be a constant string.

pine
//@version=6
indicator("Webhook payload", overlay = true)

fastEma = ta.ema(close, 9)
slowEma = ta.ema(close, 21)

plot(fastEma, "Fast", color = color.aqua)
plot(slowEma, "Slow", color = color.orange)

crossUp = ta.crossover(fastEma, slowEma)

string payload = '{"ticker": "{{ticker}}", "exchange": "{{exchange}}", "interval": "{{interval}}", "price": {{close}}, "volume": {{volume}}, "time": "{{time}}"}'

alertcondition(crossUp, "EMA cross up", payload)

Notice that string payload = ... is declared once and reused. When you have several alerts, define the template in one place so a fix lands everywhere. Before you point a live webhook at it, test the shape. Paste a fired message into any JSON validator, and check three things: the quotes are balanced, the numeric fields have no quotes, and no token survived unreplaced. A surviving {{...}} is a misspelling or a placeholder that does not apply to this kind of script.

Remember too what a webhook is: a message delivered to a URL, nothing more. A TradingView alert can post to a webhook, and a server of yours has to be listening. Pine Script does not connect to brokers or APIs by itself, which the post on connecting Pine Script to an API, broker or webhook covers in detail.

Strategy placeholders and alert_message

Strategies add placeholders that describe the order that just filled: {{strategy.order.action}} is buy or sell, and {{strategy.position_size}} is the position size after the fill. The manual's own examples also use {{ticker}} in the same message. These only make sense for strategies, because an indicator places no orders. In an indicator they would arrive as literal text.

The other half is the alert_message argument on the strategy.entry(), strategy.exit() and strategy.close() calls. It lets each order carry its own text, and you can mix script variables with placeholders in it, because the string is assembled in your code and the placeholders are filled when the order fires. To make that text appear in the alert, the alert's Message field must contain {{strategy.order.alert_message}}. If you forget that token, your carefully written alert_message never reaches the alert. And if only some order calls set alert_message, an empty string replaces the token for the ones that do not.

pine
//@version=6
strategy("Order alert messages", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)

fastMa = ta.sma(close, 10)
slowMa = ta.sma(close, 30)

plot(fastMa, "Fast", color = color.aqua)
plot(slowMa, "Slow", color = color.orange)

string orderText = "{{strategy.order.action}} {{strategy.position_size}} {{ticker}}"

if ta.crossover(fastMa, slowMa)
    strategy.entry("Long", strategy.long, alert_message = orderText)

if ta.crossunder(fastMa, slowMa)
    strategy.close("Long", alert_message = orderText)

When you create the alert for this script, choose the script as the condition, pick order fills, and set the Message field to {{strategy.order.alert_message}}. The text from the order call is then the message. You can still keep different text per order by passing different strings, such as one for entries and one for exits.

When placeholders are the wrong tool

Placeholders are the right answer when the value is something the alert system already knows. They are the wrong answer when the value lives in your script. For that, build the message in code and send it with alert(). Unlike alertcondition(), which wants a constant string, alert() accepts a string that can change from bar to bar, so you can drop any variable into it with str.tostring() or str.format(). The alert() call also lets you choose its frequency, so you control whether it fires once per bar or once per bar close.

pine
//@version=6
indicator("Dynamic alert text", overlay = true)

fastEma = ta.ema(close, 9)
slowEma = ta.ema(close, 21)
atrValue = ta.atr(14)

plot(fastEma, "Fast", color = color.aqua)
plot(slowEma, "Slow", color = color.orange)

if ta.crossover(fastEma, slowEma)
    string head = '{"ticker": "' + syminfo.ticker + '", "price": ' + str.tostring(close)
    string tail = ', "stop_gap": ' + str.tostring(atrValue * 1.5, format.mintick) + '}'
    string message = head + tail
    alert(message, alert.freq_once_per_bar_close)

Here syminfo.ticker, close and the stop gap are all read in the script, so nothing depends on token replacement, and a computed value such as the ATR-based gap can appear in the message without being plotted. The cost is that you now own the string building, and a missing quote in your concatenation breaks the JSON just as surely. For the details of str.format() and of choosing between the two alert functions, see alertcondition vs alert() in Pine Script and the guide to building labels and alert text with str.format. If you want a message that must not repaint, read why an alert fires on the wrong bar as well, because placeholder values on an unconfirmed bar can still change.

Common mistakes and how to spot them

Most failures fall into a handful of patterns. A placeholder shows up literally in the received message, and the cause is almost always a typo or a token that does not apply, such as a strategy token in an indicator. The JSON is rejected, and the cause is usually a numeric placeholder wrapped in quotes or a text one left bare. The script does not compile after you add {{plot("RSI")}}, and the cause is double quotes inside a double quoted string, so switch the outer quotes to single. The wrong value arrives from {{plot_1}}, and the cause is that a plot was added above it and shifted the numbering, so use the title form. The alert message ignores your alert_message text, and the cause is a missing {{strategy.order.alert_message}} in the Message field.

A related trap is that editing the message inside the script does not change alerts you have already created. An alert stores the message it was created with. After changing a template in code you need to delete the alert and create it again, or edit the message in the alert dialog, otherwise you keep receiving the old text and wonder why your fix did nothing.

A habit that avoids most of this is to fire the alert on purpose, once, before you rely on it. Use a recent bar where the condition is true, or temporarily loosen the condition, and read the delivered message. It takes two minutes and catches every pattern above.

Let the editor write the alert text

Writing a template by hand is fine for one alert. It gets tedious when you have a payload with a dozen fields, a strategy with separate entry and exit messages, and a receiving server with strict types. That is the part to hand to the PineScripter editor: describe the alert and the payload your webhook expects in plain English, for example that entries and exits should send the symbol, price and time as JSON with a numeric price, and it writes Pine Script v6 and checks it for compile errors, fixing what it finds. Because a follow-up request edits only the affected lines, adding a field later does not rewrite the rest of the script.

Once the alert exists, PineScripter's alerts tracker gives each script a unique webhook address. Paste it into a TradingView alert's webhook URL field and each time the alert fires it is recorded with its name, price and time, so you can check that the message and the timing match what you intended. It needs a TradingView alert, and so a TradingView plan that supports webhooks, to receive anything. For the wider design of an alert setup that does not misfire, the guide to building a repaint-free alert system is the natural next read.

PineScripter is a developer tool for writing Pine Script. It does not place trades, give advice, or predict prices, and an alert message describes a condition in your own code, not a recommendation.

Frequently asked questions

Can I use {{close}} inside an alertcondition message?

Yes. The message argument of alertcondition() is a constant string handed to the alert system, which replaces {{close}} with the close of the bar that triggered the alert.

Why does my alert send the literal text {{plot_0}}?

The alert system only replaces tokens it recognises in the context it supports. A typo, a strategy-only token in an indicator, or a plot number with no matching plot are the usual causes, so fire the alert once and read the delivered text.

How many plots can I reach with {{plot_N}}?

Only the first twenty, numbered from {{plot_0}} to {{plot_19}} in order of appearance. For a more robust reference, use {{plot("Title")}} with the plot title.

Do placeholders work in a string I build for alert()?

Treat alert() as the place to build text in code. Because the string can change each bar, you can add any variable with str.tostring() instead of relying on token replacement.

Why does my strategy alert ignore my alert_message text?

For order fill alerts, the alert Message field must contain {{strategy.order.alert_message}}. Without it, the text set on the order calls is never used.

Do I need to recreate an alert after changing the message in my script?

Yes. An alert keeps the message it was created with, so delete and recreate it, or edit the message in the alert dialog.

Describe your indicator in plain English and get Pine Script that compiles →


Disclaimer: PineScripter is a coding tool for Pine Script development. It does not provide financial advice and does not guarantee trading profits. Always backtest strategies thoroughly and understand the risks before live trading.