How to Add Alerts to a PineScript Indicator
You add alerts in Pine Script by calling the alert() function inside your script, then turning it into a live alert from TradingView's alert menu. The code part is short: you define a condition, and when that condition becomes true, alert("your message") fires. For example, when price crosses above a moving average, you call alert("Price crossed above the MA"). Writing that line isn't the whole job, though. You still open the Alerts panel in TradingView, choose your script as the condition, set how often it's allowed to trigger, and pick how you want to be notified, like a popup, email, or app push. An alert only tells you a condition you defined has happened. It doesn't tell you to buy or sell, and it never places a trade by itself.
Alerts turn a visual indicator into something you can act on without watching the chart. How alert conditions work in PineScript v6 and how to generate them cleanly.
Key points
- The modern way is the alert() function, which fires a custom message whenever the code around it runs and its condition is true.
- The older alertcondition() still works and creates a named condition you pick from the alert menu, but it can't be used in strategy scripts.
- Writing the alert in code is only half the setup; you also have to create the alert in TradingView's Alerts panel for it to actually fire.
- Alert frequency controls how often it can trigger, such as once per bar or once per bar close, which helps avoid repeated pings.
- Using once-per-bar-close, or checking barstate.isconfirmed, stops alerts from firing on a candle that later changes before it closes.
- An alert marks when your condition happened; it's information, not an instruction to trade or an automatic order.
Frequently asked questions
What's the difference between alert() and alertcondition()?
alert() is newer and flexible, firing a custom message from anywhere in your code when its condition is met. alertcondition() is older and creates a named option you select in the alert dialog. A key limit: alertcondition() can't be used inside strategy scripts, while alert() can.
Why isn't my alert firing?
The most common reason is skipping the second step: you added the code but never created the alert in TradingView's Alerts panel. Other causes are a condition that's never actually true, or a frequency setting like once per bar close that only fires after the candle finishes.
How do I stop getting spammed with repeated alerts?
Set the alert to trigger once per bar close instead of once per bar. That waits until the candle is finished, so a flickering condition mid-candle doesn't fire over and over. In code, checking barstate.isconfirmed does the same thing.
Can a Pine Script alert place a trade for me?
On its own, no. An alert just notifies you. It can send a message to a connected broker or webhook if you set that up separately, but the alert itself is only a heads-up that your condition happened, not an order.
Is there an easier way than writing the alert code myself?
Yes. In Agenticks you can describe the alert you want in plain words, like ping me when RSI drops below 30 on the daily, and the AlgoAgent writes the Pine Script with the alert already wired in. You paste it into TradingView and finish the setup in the Alerts panel.
Related on Agenticks
This content is for educational purposes only and does not constitute financial advice. Trading involves risk, including possible loss of capital.