How To Create Multiple Conditions In Trading View Alert Using Pine Script.

1. Script Initialization:
   - The script starts with //@version=2, indicating the version of Pine Script being used.
   - study("RSI-MultipleIndicators", overlay=true) initializes the script and sets the chart's title.

2. Calculating RSI:
   - rsi_value = rsi(close, 14) calculates the Relative Strength Index (RSI) with a period of 14 using the closing prices.


 

3. Buy Signal Conditions:
   - rsi_buy_signal = close > open and crossover(rsi, 70)  defines conditions for a buy signal:
     - The close price of the current candle must be greater than the open price.
     - The RSI value must cross above 70.

4. Sell Signal Conditions:
   - rsi_sell_signal = open > close and crossunder(rsi, 30) defines conditions for a sell signal:
     - The open price of the current candle must be greater than the close price.
     - The RSI value must cross below 30.

5. Drawing Shapes on Chart:
   - plotshape()` is used to visually represent buy and sell signals on the chart:
     - plotshape(rsi_buy_signal, style=shape.triangleup, text="up") draws an upward triangle for buy signals.
     - plotshape(rsi_buy_signal, style=shape.triangledown, text="down") draws a downward triangle for sell signals.

6. Alert Conditions:
   - alertcondition() sets up alerts based on buy and sell signals:
     - alertcondition(rsi_buy_signal, title="RSI buy signal", message="close < open and rsi value is crossed up by 70") triggers an alert for a buy signal.
     - alertcondition(rsi_buy_signal, title="RSI sell signal", message="open > close and rsi value is crossed down by 30") triggers an alert for a sell signal.

   - The variables rsi_buy_signal and rsi_sell_signal are used as parameters in alertcondition(), ensuring alerts are triggered based on these conditions.

This script calculates buy and sell signals based on RSI conditions and plots them on the chart while also setting up alerts for these signals in the TradingView platform.

 

Complete Code


//@version=2
study("RSI-MultipleIndicators", overlay=true)
// We have set data series for RSI having length length 14
rsi_value = rsi(close, 14)

// Condition for  buy signals:

// Here is the buy signal having two condtions
//1 - current candle close should be greater than current candle open
//2 - rsi value must crossing up value 70

rsi_buy_signal = close > open and crossover(rsi, 70)


// Condition for sell signals:

// Here is the sell signal having two condtions
//1 - current candle open should be greater than current candle close
//2 - rsi value must crossing down RSI value 70

rsi_sell_signal = open > close and crossunder(rsi, 30)

// IF you want to draw  shapes on the chart if all conditions are true

plotshape(rsi_buy_signal, style=shape.triangleup, text="up")
plotshape(rsi_buy_signal, style=shape.triangledown, text="down")

// This step is very import
// if use pine script alert condition, then you can create alert on buy and sell signals in trading view alert

alertcondition(rsi_buy_signal, title="RSI buy signal", message="close < open and rsi value is crossed up by 70")

alertcondition(rsi_buy_signal, title="RSI sell signal", message="open > close and rsi value is crossed down by 30")

 

This is the way to create multiple conditions in Trading Veiw alert system. You must notice that your variable names like "rsi_buy_signal" and "rsi_sell_signal" must match with first parameters in alertcondition pine script function

 

0
Author
No Image
Admin
MmantraTech

Mmantra Tech is a online platform that provides knowledge (in the form of blog and articles) into a wide range of subjects .

You May Also Like

Write a Response