[blackcat] L2 Super Oscillator for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
sGdsbqf.png


Creator Message:
Function

Represented by a white line, this Super Oscillator indicator identifies instruments that are overbought or oversold, which can be an important part of determining buy and sell points. An oversold market is a market that has fallen sharply and is expected to recover. In this indicator, gray candlesticks are used at the bottom to show that an oversold zone is near and a red candlestick shows that the overbought zone is ending. On the other hand, an overbought market has risen sharply and could be ripe for a decline. Yellow line dips are used to indicate overbought zones.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L2 Super Oscillator","[blackcat] L2 Super Oscillator",
# Converted and mod by Sam4Cok@Samer800     - 03/2023
declare lower;
input n  = 5;#
input n1 = 9;
input m1 = 3;
input m2 = 3;
input p  = 9;
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 10;
    def r_val;
    r_val = if length >= 1 then
            fold i = 0 to length - 1 with p do
            if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else p else Double.NaN;
    plot out = r_val;
}
#bton(b) =>
script bton {
    input b = no;
    def bton = if b then 1 else 0;
    plot out = bton;
}
#xsa(src, len, wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sum;
    def ma;
    def out;
    sum = CompoundValue(1, sum[1] - src[len] + src, src);
    ma  = if IsNaN(src[len]) then Double.NaN else sum / len;
    out = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}
def na = Double.NaN;
#//source code
def xsa1 = (close - Lowest(low, 13)) / (Highest(high, 13) - Lowest(low, 13)) * 100;
def super_osc = 3 * xsa(xsa1, 5, 1) - 2 * xsa(xsa(xsa1, 5, 1), 3, 1);
def preparation_period = If(super_osc >= 90, 82, 100);
plot Super = super_osc;
plot Prep = preparation_period;
Super.SetLineWeight(2);
Super.SetDefaultColor(Color.CYAN);
Prep.SetDefaultColor(Color.RED);

def lowv = Lowest(close, 15);
def highv = Highest(close, 15);
def rsv = ExpAverage((close - lowv) / (highv - lowv) * 100, 3);
def k = ExpAverage(rsv, 3);
def sup = super_osc <= 10;
def candidate_cond = sup[1] and k > xrf(k, 1);
def os_cond = super_osc <= 10;

def xsa2 = (close - Lowest(low, n)) / (Highest(high, n) - Lowest(low, n)) * 100;
def var1 = 4 * xsa(xsa2, 5, 1) - 3 * xsa(xsa(xsa2, 5, 1), 3.2, 1);
def candCondCount = if var1> 8 then candCondCount[1] + 1 else 0;
def candidate_cond2 = candCondCount==1;
def os_cond2 = var1 <= 8;
def var2 = xrf(low, 1);
def var3 = xsa(AbsValue(low - var2), 3, 1) / xsa(Max(low - var2, 0), 3, 1) * 100;
def var4 = ExpAverage(If(close * 1.3, var3 * 10, var3 / 10), 3);
def var5 = Lowest(low, 13);
def var6 = Highest(var4, 13);
def var7 = If(Average(close, 34), 1, 0);
def var8 = ExpAverage(If(low <= var5, (var4 + var6 * 2) / 2, 0), 3) / 618 * var7;
def var9 = If(var8 > 100, 100, var8);

def osCondCount = if bton(var9 > 20) > 0.5 then osCondCount[1] + 1 else 0;
def os_cond3 = osCondCount==1;

def fast_line = (close-lowest(low,n1))/(highest(high,n1)-lowest(low,n1))*100;
def slow_line = xsa(fast_line,m1,1);
def void = xsa(slow_line, m2, 1);
def osCondCnt4 = if slow_line > void then osCondCnt4[1] + 1 else 0;
def os_cond4 = barssince(osCondCnt4==1)<p and osCondCnt4==1 and slow_line<20;
def os_zone  = if(os_cond or os_cond2 or os_cond3,0,0);

def longCnt   = if bton(candidate_cond) > 0.5 then longCnt[1] + 1 else 0;
def long_cond = if(longCnt==1 or candidate_cond2 or os_cond4 and super_osc<20,58,0);

def cond    = os_cond or os_cond2 or os_cond3;
def cond1   = longCnt==1 or candidate_cond2 or os_cond4 and super_osc<20;
plot osZone = if cond then os_zone else na;
plot Long   = If(cond1, if(longCnt==1 or candidate_cond2 or os_cond4 and super_osc<20, 18, 0), 0);

osZone.SetPaintingStrategy(PaintingStrategy.SQUARES);
osZone.SetDefaultColor(Color.YELLOW);
osZone.SetLineWeight(2);
long.SetDefaultColor(Color.GREEN);

plot mid = if isNaN(close) then na else 50;
mid.SetDefaultColor(Color.DARK_GRAY);
#AddCloud(osZone, Long, Color.YELLOW);
AddCloud(103, preparation_period, Color.DARK_RED);
AddCloud(Long, -3, Color.DARK_GREEN);

#--- END of CODE
 
Last edited by a moderator:
Very interesting - looks too complicated to scan - can you suggest an approach, for example to scan for Super crossing Prep or Long? Thanks so much
 
Very interesting - looks too complicated to scan - can you suggest an approach, for example to scan for Super crossing Prep or Long? Thanks so much
I tried to create a scan, with no luck. TOS says it's too complex. I'd like to find a way to scan for when the Super Oscillator crosses the middle line (either going up or down). Any suggestions?
 
Very interesting - looks too complicated to scan - can you suggest an approach, for example to scan for Super crossing Prep or Long? Thanks so much
I tried to create a scan, with no luck. TOS says it's too complex. I'd like to find a way to scan for when the Super Oscillator crosses the middle line (either going up or down). Any suggestions?
It is not possible to pare down this study to work in the Scan Hacker, Watchlists, Conditional Orders or any other widget that utilizes the Condition Wizard.
It is too complex.
 

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
447 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