OPEN-SOURCE SCRIPT

BUY/SELL + ADVANCE DECLINE

Updated
This script is a custom trading view indicator that helps to identify potential buy and sell signals based on the RSI (Relative Strength Index) and SMA (Simple Moving Average) indicators. The script also identifies potential reversals using a combination of RSI and price action. It plots buy, sell, and reversal signals on the chart along with an SMA line. Additionally, it provides alerts based on the buy, sell, and reversal conditions.

Changes made to the original script:

Fixed the undeclared identifier 'c' error by calculating the difference between the current closing price and the previous closing price: c = close - close[1].

Added an "ADD Value Floating Label" to the chart. The label shows the difference between the current and previous closing prices (ADD value) along with a "Bullish" or "Bearish" indicator based on the value of 'c'. The label is positioned at the top right of the visible chart area and remains static.

Here's a summary of the major components of the script:

Input settings: Define the input parameters for RSI and SMA.
Calculation of RSI and SMA: Compute the RSI and SMA values based on the input parameters.
Color definitions: Define colors for different conditions and levels.
Condition definitions: Define various conditions for buy, sell, reversal, and other criteria.
Buy and sell conditions: Determine buy and sell signals based on RSI, SMA, and price action.
Reversal conditions: Identify potential reversals using RSI and price action.
Plot signals: Display buy, sell, and reversal signals on the chart.
Bar colors: Color the bars based on the identified signals.
Plot SMA: Display the SMA line on the chart.
Alert conditions: Set up alerts for buy, sell, and reversal conditions.
ADD Value Floating Label: Add a label to the chart showing the ADD value and a "Bullish" or "Bearish" indicator.
Release Notes
Moved ADD Label up 10 units from previous day high. It was kind of in the way prior.
Release Notes
This script corrects the ADD Advance Decline Readings WITH ACCURATE ADD readings as well as moves them to a separate pane. I am still trying to find a way to move the BUY/SELL & Reversal Signals back to the Main Chart, but for now they reside in the ADD pane. Thank you!
Release Notes
Removal of the ADD Label on the Main Chart:

In the previous version of the script, the ADD indicator was plotted on the main chart with a label (+ or -) indicating its direction. In the current version, this label has been removed from the main chart by commenting out the following line:

pinescript
Copy code
// plot(a, title='ADD', color=dircol, linewidth=4)
This change ensures that the ADD label (+ or -) no longer appears on the main chart, but the ADD indicator and its associated up and down arrows for reversals remain in the separate ADD frame.

The removal of the ADD label (INCORRECT READING/CALCULATION) was the only change made in the current version compared to the previous version of the script. All other functionality, including the calculation of various technical indicators, buy/sell signals, and reversal signals, remains the same in both versions.

This is a much CLEANER, more accurate indicator now.


//version=5
indicator(title='CHASES BUY/SELL INDICATOR + ADVANCE DECLINE', shorttitle='BUY/SELL + ADD', precision=2, overlay=false)

// ADD Indicator
a = request.security('USI:ADD', '5', hlc3)
dircol = a > a[1] ? color.green : color.red

//plot(a, title='ADD', color=dircol, linewidth=4)
m10 = ta.sma(a, 10)
plot(m10, color=color.new(color.black, 0), linewidth=2)

// Input settings
rsi_length = input.int(14, title='RSI Length', step=1)
rsi_upper = input.int(80, title='Higher Value of RSI', step=1)
rsi_lower = input.int(20, title='Lower value of RSI', step=1)
sma_length = input.int(70, title='SMA Length', step=1)

// Calculate RSI and SMA
rsi = ta.rsi(close, rsi_length)
sma = ta.sma(close, sma_length)

// Define colors
color_below_sma = color.new(color.red, 30)
color_above_sma = color.new(color.lime, 30)
color_between = color.new(color.yellow, 30)

// Set color based on conditions
sma_color = rsi >= rsi_upper or rsi <= rsi_lower ? color_between : (high < sma ? color_below_sma : color_above_sma)

// Define distances and gaps
dist_sma = 1
candle_length = 1
gap_above_sma = sma + dist_sma
gap_below_sma = sma - dist_sma
gap_value = open / 100 * candle_length

// Define conditions
min_candle_size_buy = high - low > gap_value
min_candle_size_sell = high - low > gap_value
bull = open < close and high - low > 2 * gap_value and close > (high + open) / 2
bear = open > close and high - low > 2 * gap_value and close < (low + open) / 2

// Reversal conditions
rev1 = rsi > 68 and open > close and open > gap_above_sma and high - low > gap_value + 0.5 and low != close
rev1a = rsi > 90 and open < close and close > gap_above_sma and high != close and open != low
sell_reversal = rev1 or rev1a

rev2 = rsi < 50 and open < close and open < gap_below_sma and open == low
rev3 = rsi < 30 and open > close and high > gap_below_sma and open != high and barstate.isconfirmed != bear
rev4 = rsi < 85 and close == high and high - low > gap_value and open < close
rsi_cross_under_upper = ta.crossunder(rsi, rsi_upper)
rsi_cross_over_lower = ta.crossover(rsi, rsi_lower) and open < close

// Buy and sell conditions
volume_increase = volume > volume[1]
buy_condition = open < close and open > sma and ta.cross(close[1], sma) and close > sma
sell_condition = ta.cross(close, sma) and open > close
buy_signal = ta.crossover(close[1], sma) and close[1] > open[1] and high[0] > high[1] and close[0] > open[0]
sell_signal = ta.crossunder(low[1], sma) and close[1] < open[1] and low[0] < low[1] and close[0] < open[0]

// Calculate the value of 'c'
c = close - close[1]

// Plot signals
plotshape(sell_signal, title='SELL', style=shape.labeldown, color=color.new(color.red, 30), text='SELL', textcolor=color.new(color.black, 30))
plotshape(buy_signal, title='BUY', style=shape.labelup, color=color.new(color.aqua, 30), text='BUY', textcolor=color.new(color.black, 30), location=location.belowbar)

// Plot reversals
plotshape(rsi_cross_under_upper, title='Reversal1', style=shape.labeldown, color=color.new(color.yellow, 20), text='↓', textcolor=color.new(color.black, 20))
plotshape(rsi_cross_over_lower, title='Reversal2', style=shape.labelup, color=color.new(color.yellow, 20), text='↑', textcolor=color.new(color.black, 20), location=location.belowbar)

// Bar colors
barcolor(buy_signal ? color.new(color.green, 0) : sell_signal ? color.new(color.maroon, 30) : rsi_cross_under_upper or rsi_cross_over_lower ? color.new(color.yellow, 0) : na)

// Alert conditions
alertcondition(rsi_cross_under_upper or rsi_cross_over_lower, title='Both Reversal Signal', message='Reversal Alert')
alertcondition(sell_signal or buy_signal, title='Buy & Sell Signal Both', message='Buy/Sell Alert')
alertcondition(buy_signal, title='Only Buy Signal', message='Buy Alert')
alertcondition(sell_signal, title='Only Sell Signal', message='Sell Alert')
alertcondition(rsi_cross_under_upper, title='Reversal from Top', message='Down Reversal Alert')
alertcondition(rsi_cross_over_lower, title='Reversal from Down', message='Up Reversal Alert')

Release Notes
Let's highlight the key differences and what this updated script can do compared to the prior version:

Improved Visualization in ADD Pane:

In this updated script, the ADD indicator and BUY/SELL signals are correctly plotted within the ADD pane. This provides a more organized and visually appealing view of key trading information.
Clearer Buy and Sell Signals:

The script now clearly marks BUY signals with green triangles ('↑') and SELL signals with red triangles ('↓'), making it easier for traders to identify potential entry and exit points.
Enhanced Reversal Signals:

Reversal signals are marked with '↑' and '↓' symbols in the ADD pane, providing additional insights into potential trend changes.
Bar Color Coding:

The script color-codes bars in the main chart to highlight different conditions. Green bars indicate BUY signals, maroon bars indicate SELL signals, and yellow bars indicate reversal signals. This helps traders quickly assess the current market conditions.
Alert System:

The script includes an alert system that can notify traders when specific conditions are met. It can send alerts for both reversals and BUY/SELL signals, allowing traders to stay informed even when they are not actively monitoring the chart.
Customizable Parameters:

The script offers customizable input parameters for RSI length, RSI upper and lower values, and SMA length, allowing traders to adapt the indicator to their preferred trading strategies.
Technical Analysis Features:

The script incorporates various technical analysis features, such as RSI, SMA, and gap-related conditions, to help traders make informed trading decisions.
Consolidated Information:

All key trading information, including the ADD indicator, BUY/SELL signals, and reversals, are now conveniently displayed in one chart. This consolidated view simplifies analysis and decision-making.
Overall, this updated script enhances the visualization, clarity, and functionality of the indicator, making it a valuable tool for traders seeking to identify potential entry and exit points in the market.
ADDadvancedelcinebuysellbuysellsignalMoving AveragesoptionsoptionstraderoptionstradingsentimentalanalysisSimple Moving Average (SMA)smaSPDR S&P 500 ETF (SPY)

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer