RSI & BB QQE Mod (highlight) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
kLr29CM.png

Author Message:
This script is a combination of the RSI, QQE and BB

Here is an explanation on how I combined them, and how they are used:

  • RSI (Relative Strength Index)
  • Display a smoothed version of the RSI to identify "oversold" and "overbought" market phases
  • Used to calculate a QQE
  • QQE (Quantitative Qualitative Estimation)
  • Used to identify trend direction and trend strength
  • Used to set a basis for the BB
  • BB (Bollinger Bands)
  • Used with QQE as a basis to determine a relative definition of "high RSI" and "low RSI"
  • Used with QQE as a basis to determine the volatility of the RSI at a given moment
  • Used to predict pivot points

Here are the main signals:
  • When "RSI Smoothed" line above the Upper BB then "RSI Smoothed" line turns green
  • Also, display green background color highlight
  • Also, and if "RSI Smoothed" is above the overbought line then display a second green background color highlight
  • When "RSI Smoothed" line bellow the Lower BB then "RSI Smoothed" line turns red
  • Also, display red background color highlight
  • Also, and if "RSI Smoothed" is bellow the oversold line then display a second red background color highlight

CODE:
CSS:
#https://www.tradingview.com/v/XBP7E1JB/
#//@Dziwne
# Author | © Dziwne— — —
#// Glaz's QQE : https://fr.tradingview.com/script/tJ6vtBBe-QQE/
#// Mihkel00's QQE MOD : https://www.tradingview.com/script/TpUW4muw-QQE-MOD/
#// Dziwne's MFI : https://www.tradingview.com/script/fCtJdxar/
#/indicator(title='RSI, BB QQE Mod (highlight) v1.0 [Dziwne]', shorttitle='RSI, BB-QQE Mod [Dziwne]'
# Converted by Sam4Cok@Samer800        - 04/2023
declare lower;
input ColorBars = no;
input source = close;         # 'Source'
input rsi_length = 13;        # 'RSI Length'
input rsi_smoothing = 5;      # 'RSI Smoothing'
input slow_factor = 3;        # 'Slow Factor'
input level_oversold = 20;    # 'Oversold Level'
input level_overbought = 80;  # 'Overbought Level'
input bb_length = 50;         # 'BB Length'
input bb_mult = 1.414;        # 'BB Multiplier'


def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}
#// 2.1. Calculations, RSI Smoothed

def rsi = RSI(Price = source, Length = rsi_length);
def rsi_ma = ExpAverage(rsi, rsi_smoothing);

#// 2.2. Calculations, QQE base for BB

def atr_rsi = AbsValue(rsi_ma[1] - rsi_ma);
def atr_rsi_ma = ExpAverage(atr_rsi, rsi_length);

def dar = ExpAverage(atr_rsi_ma, rsi_length) * slow_factor;

def newlongband = rsi_ma - dar;
def longband;
def longband1 = if(nz(longband[1])==0,newlongband,longband[1]);
longband = if rsi_ma[1] > longband1 and rsi_ma > longband1 then Max(longband1, newlongband) else newlongband;

def newshortband = rsi_ma + dar;
def shortband;
def shortband1 = if(nz(shortband[1])==0,newshortband,shortband[1]);
shortband = if rsi_ma[1] < shortband1 and rsi_ma < shortband1 then Min(shortband1, newshortband) else newshortband;

def cross_up   = (rsi_ma>longband[1] and rsi_ma[1]<=longband1[1]) or (rsi_ma<longband[1] and rsi_ma[1]>=longband1[1]);
def cross_down = (rsi_ma>shortband[1] and rsi_ma<=shortband1[1]) or (rsi_ma<shortband[1] and rsi_ma>=shortband1[1]);

def trend;
trend = if cross_down then longband else if cross_up then shortband else if(nz(trend[1])==0, longband,trend[1]);

#// 2.3. Calculations, BB

def basis = Average(trend, bb_length);
def dev = bb_mult * stdev(trend, bb_length);

def upper_bb = basis + dev;
def lower_bb = basis - dev;

# // 3.1. Colors, Parameters

def over_bb = rsi_ma > upper_bb;
def under_bb = rsi_ma < lower_bb;

def up = rsi_ma > 50 and over_bb;
def down = rsi_ma < 50 and under_bb;

def oversold = rsi_ma < level_oversold;
def overbought = rsi_ma > level_overbought;

#// 3.2. Colors, Definition

def color_line_bb = if over_bb then 1 else if under_bb then -1 else 0;
def color_highlight_rsi_bb = if up then 1 else if down then -1 else 0;
def color_highlight_rsi_OBOS = if up and overbought then 1 else if down and oversold then -1 else 0;

#// 4.1. Display, Plotting

def upper_bb_line = upper_bb;
def lower_bb_line = lower_bb;

plot rsi_ma_line = rsi_ma;
rsi_ma_line.AssignValueColor(if color_line_bb>0 then Color.GREEN else
                             if color_line_bb<0 then Color.RED else Color.DARK_GRAY);

plot LowLine = if last then na else 0;
plot HighLine = if last then na else 100;
LowLine.SetDefaultColor(Color.GRAY);
HighLine.SetDefaultColor(Color.GRAY);

plot os = if last then na else level_oversold;
plot ob = if last then na else level_overbought;
os.SetDefaultColor(Color.DARK_RED);
ob.SetDefaultColor(Color.DARK_GREEN);
os.SEtPaintingStrategy(PaintingStrategy.DASHES);
ob.SEtPaintingStrategy(PaintingStrategy.DASHES);

#// 4.2. Display, Filling
AddCloud(upper_bb_line, lower_bb_line, Color.DARK_GRAY);

#// 4.3. Display, Highlighting

AddCloud(if color_highlight_rsi_bb>0 then pos else na, neg, Color.DARK_GREEN);    # 'Up/Down, Highlight'
AddCloud(if color_highlight_rsi_bb<0 then pos else na, neg, Color.DARK_RED);      # 'Up/Down, Highlight'

AddCloud(if color_highlight_rsi_OBOS>0 then pos else na, neg, Color.DARK_GREEN);  # 'Overbought/Oversold, Highlight')
AddCloud(if color_highlight_rsi_OBOS<0 then pos else na, neg, Color.DARK_RED);    # 'Overbought/Oversold, Highlight')

#// Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if color_line_bb>0 then Color.GREEN else
                 if color_line_bb<0 then Color.RED else Color.DARK_GRAY);

#--- END of CODE
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
476 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top