Yes, there are two ways to create alerts in Pine Script: alertcondition() and alert().
1. Using alertcondition()
This is the most common method and is mainly used to create alert conditions that appear in TradingView’s Create Alert dialog.
buyCondition = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
alertcondition(
buyCondition,
title = "Buy Signal",
message = "EMA Crossover Buy Signal"
)
2. Using alert()
The alert() function lets you trigger an alert directly from your code whenever a condition is met.
if buyCondition
alert("EMA Crossover Buy Signal")
You can also control how often the alert is triggered by using the freq parameter.
if buyCondition
alert("EMA Crossover Buy Signal", alert.freq_once_per_bar_close)
In short:
-Use alertcondition() when you want to create alert conditions that users can select from TradingView’s Create Alert window.
-Use alert() when you want to trigger alerts directly from your script with more control over when they are sent.
Both methods are useful, and the one you choose depends on how you want your alerts to behave.