Home Forums Trading view How can I use alertcondition() in a custom TradingView indicator?

How can I use alertcondition() in a custom TradingView indicator?

  • Author
    Posts
    • I’m creating my own indicator in TradingView using Pine Script.

      The indicator is already generating Buy and Sell signals on the chart, but now I want TradingView to create alerts automatically whenever those signals occur.

      I came across the alertcondition() function, but I’m not sure how it works or where it should be used.

      Can someone explain the correct way to use alertcondition() in a custom indicator?

    • Yes sir, alertcondition() is the standard way to create alert conditions in a custom TradingView indicator.

      It does not send alerts by itself. Instead, it tells TradingView which conditions should be available when you create an alert.

      For example, suppose your indicator generates Buy and Sell signals like this:

      //@version=6
      indicator("EMA Crossover", overlay=true)
      
      fastEMA = ta.ema(close, 9)
      slowEMA = ta.ema(close, 21)
      
      buySignal = ta.crossover(fastEMA, slowEMA)
      sellSignal = ta.crossunder(fastEMA, slowEMA)

      Now you can create alert conditions like this:

      alertcondition( buySignal, title="Buy Signal", message="BUY")
      
      alertcondition( sellSignal, title="Sell Signal", message="SELL")

      Now save the script and add it to your chart.

      Then follow these steps:

      -Step 1:
      Click the “Create Alert” button in TradingView.

      -Step 2:
      In the Condition dropdown, select your custom indicator.

      -Step 3:
      You will now see the alert conditions that you created using alertcondition(), such as:

      -Buy Signal

      -Sell Signal

      -Step 4:
      Select the condition you want, configure the notification settings, and click “Create”.

      That’s it.

      Whenever buySignal becomes true, the “Buy Signal” alert can be triggered.

      Whenever sellSignal becomes true, the “Sell Signal” alert can be triggered.

      One important thing to remember is that alertcondition() only defines the alert conditions. It does not send alerts automatically.

      You still need to create the alert from the TradingView interface after adding the indicator to your chart.

      This is the recommended approach when you are building custom indicators and want users to create TradingView alerts based on your Buy and Sell conditions.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top