How to use plot placeholders with TradingView's strategy alerts?
How to use plot placeholders with TradingView’s strategy alerts?
Section titled “How to use plot placeholders with TradingView’s strategy alerts?”TL;DR
Name the plots that contain the data you want, then reference them in alert messages using{{plot("Plot Name")}}; TradingView swaps the placeholder for the current plot value at trigger time.
At a Glance
Section titled “At a Glance”| Difficulty | Beginner |
| Time to implement | 10-15 min |
| Category | Alerts |
Quick Actions
Section titled “Quick Actions”Quick Start
Section titled “Quick Start”//@version=5strategy("Placeholder demo", overlay=true)
stopLevel = ta.lowest(low, 10)targetLevel = ta.highest(high, 10)
plot(stopLevel, "Stop")plot(targetLevel, "Target")
//@strategy_alert_message Stop: {{plot("Stop")}} | Target: {{plot("Target")}}Why It Matters
Section titled “Why It Matters”Alerts that include live price levels remove guesswork—trade management levels arrive with every notification. Plot placeholders are the simplest way to achieve that: expose the numbers via plot, then pull them into alert messages without extra state management or custom strings.
What You’ll Learn
Section titled “What You’ll Learn”- Publish the required values via
plotso TradingView can surface them in alerts. - Reference those plots with the
{{plot("Name")}}placeholder syntax. - Provide a default alert body using
//@strategy_alert_message, or type placeholders manually when creating alerts. - Validate the output to ensure rounding, formatting, and precision meet your needs.
Quick Reference
Section titled “Quick Reference”| Call | Purpose |
|---|---|
plot(series, title) | Exposes a value that placeholders can reference. |
{{plot("Name")}} | Inserts the latest value of the plot named Name into an alert. |
//@strategy_alert_message ... | Sets the default alert message for the strategy. |
alertcondition(condition, title, message) | Optionally pair placeholders with indicator-style alerts. |
tostring(value, format) | Use inside labels if you also display the value on-chart for verification. |
Implementation Blueprint
Section titled “Implementation Blueprint”-
Publish the values via plots
Plot every number you want to include in alerts and give each plot a unique, descriptive title.stop = ta.lowest(low, 14)limit = ta.highest(high, 14)plot(stop, "Stop price")plot(limit, "Target price") -
Reference plots in the alert message
Use//@strategy_alert_messageto define a default message, or type placeholders manually when creating an alert.//@strategy_alert_message Stop: {{plot("Stop price")}} | Target: {{plot("Target price")}} -
Create the alert (and test)
Add the strategy to a chart, open Create Alert, and confirm the placeholders resolve correctly. Trigger a test alert to validate formatting.
Example Playbook
Section titled “Example Playbook”//@version=5strategy("Breakout with dynamic alert", overlay=true, pyramiding=0)
len = input.int(20, "Lookback")bufferTick = input.int(2, "Buffer (ticks)")
float tickToPrice(int t) => t * syminfo.mintick
rangeHigh = ta.highest(high, len)rangeLow = ta.lowest(low, len)stopLevel = rangeLow - tickToPrice(bufferTick)targetLevel = rangeHigh + tickToPrice(bufferTick * 2)
plot(rangeHigh, "Range high")plot(rangeLow, "Range low")plot(stopLevel, "Stop level")plot(targetLevel, "Target level")
longBreakout = ta.crossover(close, rangeHigh)shortBreakout = ta.crossunder(close, rangeLow)
if longBreakout strategy.entry("Long", strategy.long)if shortBreakout strategy.entry("Short", strategy.short)
//@strategy_alert_message {{strategy.order.action}} {{strategy.order.contracts}} @ {{strategy.order.price}}\nStop: {{plot("Stop level")}} | Target: {{plot("Target level")}}- Plots expose every relevant level so placeholders can pull them into alerts.
- The default alert message combines built-in strategy variables (`strategy.order.*`) with custom plots for full context.
- Tick buffers show how to prepare values that need minor adjustments before plotting.
Pro Tips & Pitfalls
Section titled “Pro Tips & Pitfalls”- Placeholders resolve to raw numbers. If you need formatting (e.g., two decimals), use Alert formatter rules in the UI or round the plotted series beforehand.
- The alert message runs once when the alert is created. Updating the script (or changing plot names) requires recreating the alert so placeholders stay in sync.
- Strategy placeholders support both plots and built-in variables such as
{{strategy.order.contracts}}. Mix and match for richer notifications. - Indicator alerts work the same way—just ensure the indicator also exposes the series via
plot.
Troubleshooting & FAQ
Section titled “Troubleshooting & FAQ”My alert shows n/a
Section titled “My alert shows n/a”The plot returned na on that bar. Guard the plotted series (e.g., plot(condition ? value : na)) so placeholders only fire when meaningful data exists.
The placeholder text appears literally
Section titled “The placeholder text appears literally”Double-check spelling and case sensitivity. The placeholder must match the plot title exactly, including spaces and capitalisation.
Can I include multiple plots in one placeholder?
Section titled “Can I include multiple plots in one placeholder?”No—use separate placeholders (e.g., Stop: {{plot("Stop")}} | Target: {{plot("Target")}}). Each resolves independently when the alert triggers.
Key Takeaways
Section titled “Key Takeaways”- Plot placeholders bridge your chart logic with alert notifications—all you need is a named
plotand a matching{{plot("Name")}}reference. - Define a default alert body with
//@strategy_alert_messageso every alert includes the dynamic values automatically. - Validate the final alert output with a quick test trigger to confirm formatting and precision.
- Keep plot titles stable; renaming them requires updating every placeholder that references them.
Keep Going
Section titled “Keep Going”- Open AI Editor to apply the pattern with guided assistance
- Browse Strategy Examples for ready-to-run templates
- Connect to Live Trading when you are ready to automate
Adapted from tradingcode.net, optimised for Algo Trade Analytics users.