How to create alerts in Pine Script?

Asked by Radhesh Joshi · SOLVED
1 reply 633 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

Hi everyone,

I’m learning Pine Script and I want to create alerts whenever my trading conditions are met, such as a buy or sell signal.

Can someone explain how to create alerts in Pine Script with a simple example? I’d also like to know how to use those alerts later in TradingView.

Thanks in advance!

Posted Jul 26
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    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.

    Verified Solution
    • Ok, understand that how the alert is created in pine script. Thanks for the detailed explanation with the codes example. – Radhesh Joshi Jul 28
    Markdown supported · ```json for code blocks · paste or drop screenshots

    Be specific and kind. Never share API keys, passwords or personal account details.

    Welcome to the community

    Log in or create your account in under a minute.

    1. 1Mobile
    2. 2E-mail
    3. 3Password
    +91

    Have a password?

    By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.