QQE Weighted Oscillator [LuxAlgo] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
ZpnOVwL.png

Author Message:
The QQE Weighted Oscillator is comprised of a smoothed RSI oscillator and a trailing stop derived from this same RSI. The oscillator can be used to indicate whether the market is overbought/oversold as well as an early indication of trend reversals thanks to the leading nature of the RSI.
More details : https://www.tradingview.com/v/aRxQ1g82/

CODE:

CSS:
# https://www.tradingview.com/v/aRxQ1g82/
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
#// © LuxAlgo
#indicator("QQE Weighted Oscillator [LuxAlgo]", "LuxAlgo - QQE Weighted Oscillator")
# Converted and mod by Sam4Cok@Samer800    - 08/2023
declare lower;
#//Settings
input ColorBars = yes;
input showSignals = yes;
input length = 14;
input factor = 4.236;
input smooth = 5;
input weight = 2;
input src    = close;

def na = Double.NaN;
def last = isNaN(close);

DefineGlobalColor("rsi", CreateColor(49, 121, 245));
DefineGlobalColor("teal", CreateColor(0, 137, 123));
DefineGlobalColor("red", CreateColor(255, 82, 82));

#//Weighted QQE
def ts;
def rsi;# = 0.

def delta = src - src[1];
def w_ = if delta * (rsi[1] - ts[1]) > 0 then weight else 1;
def w = if isNaN(w_) then 1 else w_;
def dw = delta * w;
#//Rsi
def num = WildersAverage(dw, length);
def den = WildersAverage(AbsValue(dw), length);
def nd = num / den;
rsi = 50 * ExpAverage(nd, smooth) + 50;
def rsidif = AbsValue(rsi - rsi[1]);
#//Trailing stop
def diff = WildersAverage(rsidif, length);

def crossover  = Crosses(rsi, ts[1], CrossingDirection.ABOVE);
def crossunder = Crosses(rsi, ts[1], CrossingDirection.BELOW);

def ts_ = if crossover  then rsi - diff * factor else
          if crossunder then rsi + diff * factor else
          if rsi > ts[1] then Max(rsi - diff * factor, ts[1]) else Min(rsi + diff * factor, ts[1]);
ts = if isNaN(ts_) then rsi else ts_;

#//Plots
def css = rsi > ts;

def SigUp = if !showSignals then na else if crossover then 20 else 0;
def SigDn = if !showSignals then na else if crossunder then 80 else 100;

AddCloud(SigUp, 0, Color.GREEN, Color.GREEN, yes);
AddCloud(100, SigDn, Color.RED, Color.RED, yes);

plot plot_rsi = rsi;    # 'RSI'
plot plot_ts  = ts;     # 'Traling Stop'

plot_rsi.SetLineWeight(2);
plot_rsi.AssignValueColor(if css then Color.CYAN else Color.LIGHT_RED);

plot_ts.AssignValueColor(if css then GlobalColor("teal") else  GlobalColor("red"));
AddCloud(plot_rsi, plot_ts, Color.DARK_GREEN, Color.DARK_RED);

plot "70" = if last then na else 70;
plot "50" = if last then na else 50;
plot "30" = if last then na else 30;
"70".SetDefaultColor(Color.GRAY);
"50".SetDefaultColor(Color.GRAY);
"30".SetDefaultColor(Color.GRAY);
"70".SetStyle(Curve.SHORT_DASH);
"50".SetStyle(Curve.SHORT_DASH);
"30".SetStyle(Curve.SHORT_DASH);


def extUp = css and rsi > 50;
def weakUp = css;
def extDn = rsi < ts and rsi < 50;
def weakDn = rsi < ts;


AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if extUp then Color.GREEN else
                 if weakUp then Color.DARK_GREEN else
                 if extDn then Color.RED else
                 if weakDn then Color.DARK_RED else Color.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
376 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