Search code examples
pine-scriptpine-script-v5

Pine Script code for multiple buy/sell options


I have a pine script indicator with 2 different Buy/Sell alert conditions.

One is the Rsi crosses the 50 level and the +di crosses the -di,
the second condition is when the Rsi crosses 50 level and Adx is greater than 25.

I want to choose between the two options and if I choose condition one it should give me a Buy/Sell alert if that condition is met, and the same applies if the 2nd condition are met.

I tried "select" option but failed to get the desired result


Solution

  • Ask the user to choose the alert to activate :

    AlertRsiDi = input.bool(true,"Alert when Rsi crosses the 50 level and the +di crosses the -di ?")
    AlertRsiAdx = input.bool(true, "Alert when the Rsi crosses 50 level and Adx is greater than 25 ?")
    

    Then if your names of condition are Condition1 and Condition2, to create the alert :

    if AlertRsiDi and Condition1
        alert("Alerte Rsi Di", alert.freq_all)
    if AlertRsiAdx and Condition2
        alert("Alerte Rsi ADX", alert.freq_all)