SuperTrend Oscillator [LUX] For ThinkOrSwim

mirage6006

New member
The author states:
This oscillator is made of three components, all derived from the SuperTrend indicator. This approach allows the user to easily determine overbought/sold zones, identify whether a retracement is present or if the price is ranging or trending. It also allows for the anticipation of the potential price cross with the SuperTrend.
Image is available in the next post.

Looking for:
the indicator name is : SUPEROSC
https://www.tradingview.com/script/dVau7zqn-SuperTrend-Oscillator-LUX/
 
Last edited by a moderator:
[LUX] SuperTrend Oscillator For ThinkOrSwim
mGRUZ8O.png


CODE:

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
#https://www.tradingview.com/script/dVau7zqn-SuperTrend-Oscillator-LUX/
#// © LuxAlgo
#study("[LUX] SuperTrend Oscillator","SuperOsc [LuxAlgo]")
# Converted by Sam4Cok@Samer800 - 10/2022 - Not Typical
declare lower;
input ColorBar = no;
input length     = 10;
input mult       = 2.0;
input smooth     = 72;
#//Misc
input fixed      = no;    # 'Fixed Transparency'
input show_line  = yes;   # 'Show Lines'
input show_Signal= yes;   # 'Show Signals'
input show_Label   = no;  # 'Show % False Signals'
input src = close;
#//----
def lower; def upper; def trend;
def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
  input cond = 0;
  input src = close;
  input occurrence = 0;
  def n = occurrence + 1;
  def offset = fold j = 0 to 200 with p=1 while p < n + 1
    do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
  plot price = GetValue(src, offset-1);
}
# theme
DefineGlobalColor("Green1" , Color.GREEN); # >=90
DefineGlobalColor("Green2" , CreateColor(5,217,4)); # >=80
DefineGlobalColor("Green3" , CreateColor(4,181,4)); # >=70
DefineGlobalColor("Green4" , CreateColor(3,145,3)); # >=60
DefineGlobalColor("Green5" , CreateColor(2,117,2)); # >=50
DefineGlobalColor("Red1" , Color.RED);   # >=40
DefineGlobalColor("Red2" , CreateColor(214,6,6));   # >=30
DefineGlobalColor("Red3" , CreateColor(184,6,6));   # >=20
DefineGlobalColor("Red4" , CreateColor(145,3,3));   # >=10
DefineGlobalColor("Red5" , CreateColor(117,2,2));   # >=0
#---------------------------------------------------------
def nATR = ATR(Length=length)*mult;
def up = hl2 + nATR;
def dn = hl2 - nATR;
upper = if src[1] < upper[1] then min(up,upper[1]) else up;
lower = if src[1] > lower[1] then max(dn,lower[1]) else dn;
trend = if src > upper[1] then 1 else if src < lower[1] then 0 else trend[1];
def Spt = trend*lower+(1-trend)*upper;
#//----
def ama;
def osc = max(min((src - Spt)/(upper-lower),1),-1);
def alpha = power(osc,2)/length;
ama = nz(ama[1]+alpha*(osc-ama[1]),osc);
def hist = ExpAverage(osc - ama,smooth);
#//----
def MainFixed = if fixed then osc*100 else na;#,'Main Fixed'
def Histogram = hist*100;    # 'Histogram'
plot Signal = ama*100;       # 'Signal'
Signal.AssignValueColor( if ama > 0 then CreateColor(33,87,243) else CreateColor(103,58,183));

def var_css = if osc > 0 then
              if osc*99 > 80 then 5 else
              if osc*99 > 60 then 4 else
              if osc*99 > 40 then 3 else
              if osc*99 > 20 then 2 else 1 else
              if osc <=0 then
              if osc*-99 > 80 then -5 else
              if osc*-99 > 60 then -4 else
              if osc*-99 > 40 then -3 else
              if osc*-99 > 20 then -2 else -1 else na;

plot MainTrans = if fixed then na else osc*100;    # 'Main Transp'
MainTrans.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
MainTrans.AssignValueColor( if var_css ==5 then GlobalColor("Green1") else
                            if var_css ==4 then GlobalColor("Green2") else
                            if var_css ==3 then GlobalColor("Green3") else
                            if var_css ==2 then GlobalColor("Green4") else
                            if var_css ==1 then GlobalColor("Green5") else
                            if var_css ==-5 then GlobalColor("Red1") else
                            if var_css ==-4 then GlobalColor("Red2") else
                            if var_css ==-3 then GlobalColor("Red3") else
                            if var_css ==-2 then GlobalColor("Red4") else GlobalColor("Red5"));
#//----
def a = if isNaN(Close) then na else 80;
def b = if isNaN(Close) then na else -80;
AddCloud(a,b,CreateColor(9,26,72),CreateColor(9,26,72),yes);
AddCloud(MainFixed, 0, Color.CYAN, Color.MAGENTA);
AddCloud(Histogram, 0, Color.WHITE, Color.WHITE, yes);
#//----
def signDiff = sign(osc);
def sig = if (sign(osc) - sign(osc[1])) then osc*-100 else na;
plot Lines = if show_line then sig else na;
Lines.SetStyle(Curve.FIRM);
Lines.AssignValueColor(if osc[1] > 0 then Color.GREEN else Color.RED);
Lines.EnableApproximation();

#//----
def cross   = (src>Spt and src[1]<Spt[1]) or (src<Spt and src[1]>Spt[1]);
def crossUp = (src>Spt and src[1]<Spt[1]);
def crossDn = (src<Spt and src[1]>Spt[1]);

#//----
def false_buy  = valuewhen(crossDn,src,0) < valuewhen(crossUp,src,0);
def false_sell = valuewhen(crossUp,src,0) > valuewhen(crossDn,src,0);
def num = TotalSum(if cross and (false_buy or false_sell) then 1 else 0);
def den = TotalSum(if cross then 1 else 0);
def per = num/den*100;
#//----
def crossover = if !show_Signal then na else
                if crossUp then
                if false_sell then -1 else 1 else na;
def crossunder= if !show_Signal then na else
                if crossDn then
                if false_buy then -1 else 1 else na;
plot OverPoint = if !isNaN(crossover) then -100 else na;
OverPoint.SetPaintingStrategy(PaintingStrategy.SQUARES);
OverPoint.AssignValueColor( if crossover==-1 then Color.RED else Color.GREEN);
OverPoint.SetLineWeight(4);

plot BelowPoint = if !isNaN(crossunder) then 100 else na;
BelowPoint.SetPaintingStrategy(PaintingStrategy.SQUARES);
BelowPoint.AssignValueColor( if crossunder==-1 then Color.RED else Color.GREEN);
BelowPoint.SetLineWeight(4);
def n = barNumber();

addlabel(show_Label,"False Signal(" + round(per,2) + "%)", Color.WHITE);

AssignPriceColor(if !ColorBar then Color.CURRENT else
                 if var_css ==5 then GlobalColor("Green1") else
                 if var_css ==4 then GlobalColor("Green2") else
                 if var_css ==3 then GlobalColor("Green3") else
                 if var_css ==2 then GlobalColor("Green4") else
                 if var_css ==1 then GlobalColor("Green5") else
                 if var_css ==-5 then GlobalColor("Red1") else
                 if var_css ==-4 then GlobalColor("Red2") else
                 if var_css ==-3 then GlobalColor("Red3") else
                 if var_css ==-2 then GlobalColor("Red4") else GlobalColor("Red5"));

### END
 
Last edited by a moderator:
mGRUZ8O.png


CODE:

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
#https://www.tradingview.com/script/dVau7zqn-SuperTrend-Oscillator-LUX/
#// © LuxAlgo
#study("[LUX] SuperTrend Oscillator","SuperOsc [LuxAlgo]")
# Converted by Sam4Cok@Samer800 - 10/2022 - Not Typical
declare lower;
input ColorBar = no;
input length     = 10;
input mult       = 2.0;
input smooth     = 72;
#//Misc
input fixed      = no;    # 'Fixed Transparency'
input show_line  = yes;   # 'Show Lines'
input show_Signal= yes;   # 'Show Signals'
input show_Label   = no;  # 'Show % False Signals'
input src = close;
#//----
def lower; def upper; def trend;
def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
  input cond = 0;
  input src = close;
  input occurrence = 0;
  def n = occurrence + 1;
  def offset = fold j = 0 to 200 with p=1 while p < n + 1
    do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
  plot price = GetValue(src, offset-1);
}
# theme
DefineGlobalColor("Green1" , Color.GREEN); # >=90
DefineGlobalColor("Green2" , CreateColor(5,217,4)); # >=80
DefineGlobalColor("Green3" , CreateColor(4,181,4)); # >=70
DefineGlobalColor("Green4" , CreateColor(3,145,3)); # >=60
DefineGlobalColor("Green5" , CreateColor(2,117,2)); # >=50
DefineGlobalColor("Red1" , Color.RED);   # >=40
DefineGlobalColor("Red2" , CreateColor(214,6,6));   # >=30
DefineGlobalColor("Red3" , CreateColor(184,6,6));   # >=20
DefineGlobalColor("Red4" , CreateColor(145,3,3));   # >=10
DefineGlobalColor("Red5" , CreateColor(117,2,2));   # >=0
#---------------------------------------------------------
def nATR = ATR(Length=length)*mult;
def up = hl2 + nATR;
def dn = hl2 - nATR;
upper = if src[1] < upper[1] then min(up,upper[1]) else up;
lower = if src[1] > lower[1] then max(dn,lower[1]) else dn;
trend = if src > upper[1] then 1 else if src < lower[1] then 0 else trend[1];
def Spt = trend*lower+(1-trend)*upper;
#//----
def ama;
def osc = max(min((src - Spt)/(upper-lower),1),-1);
def alpha = power(osc,2)/length;
ama = nz(ama[1]+alpha*(osc-ama[1]),osc);
def hist = ExpAverage(osc - ama,smooth);
#//----
def MainFixed = if fixed then osc*100 else na;#,'Main Fixed'
def Histogram = hist*100;    # 'Histogram'
plot Signal = ama*100;       # 'Signal'
Signal.AssignValueColor( if ama > 0 then CreateColor(33,87,243) else CreateColor(103,58,183));

def var_css = if osc > 0 then
              if osc*99 > 80 then 5 else
              if osc*99 > 60 then 4 else
              if osc*99 > 40 then 3 else
              if osc*99 > 20 then 2 else 1 else
              if osc <=0 then
              if osc*-99 > 80 then -5 else
              if osc*-99 > 60 then -4 else
              if osc*-99 > 40 then -3 else
              if osc*-99 > 20 then -2 else -1 else na;

plot MainTrans = if fixed then na else osc*100;    # 'Main Transp'
MainTrans.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
MainTrans.AssignValueColor( if var_css ==5 then GlobalColor("Green1") else
                            if var_css ==4 then GlobalColor("Green2") else
                            if var_css ==3 then GlobalColor("Green3") else
                            if var_css ==2 then GlobalColor("Green4") else
                            if var_css ==1 then GlobalColor("Green5") else
                            if var_css ==-5 then GlobalColor("Red1") else
                            if var_css ==-4 then GlobalColor("Red2") else
                            if var_css ==-3 then GlobalColor("Red3") else
                            if var_css ==-2 then GlobalColor("Red4") else GlobalColor("Red5"));
#//----
def a = if isNaN(Close) then na else 80;
def b = if isNaN(Close) then na else -80;
AddCloud(a,b,CreateColor(9,26,72),CreateColor(9,26,72),yes);
AddCloud(MainFixed, 0, Color.CYAN, Color.MAGENTA);
AddCloud(Histogram, 0, Color.WHITE, Color.WHITE, yes);
#//----
def signDiff = sign(osc);
def sig = if (sign(osc) - sign(osc[1])) then osc*-100 else na;
plot Lines = if show_line then sig else na;
Lines.SetStyle(Curve.FIRM);
Lines.AssignValueColor(if osc[1] > 0 then Color.GREEN else Color.RED);
Lines.EnableApproximation();

#//----
def cross   = (src>Spt and src[1]<Spt[1]) or (src<Spt and src[1]>Spt[1]);
def crossUp = (src>Spt and src[1]<Spt[1]);
def crossDn = (src<Spt and src[1]>Spt[1]);

#//----
def false_buy  = valuewhen(crossDn,src,0) < valuewhen(crossUp,src,0);
def false_sell = valuewhen(crossUp,src,0) > valuewhen(crossDn,src,0);
def num = TotalSum(if cross and (false_buy or false_sell) then 1 else 0);
def den = TotalSum(if cross then 1 else 0);
def per = num/den*100;
#//----
def crossover = if !show_Signal then na else
                if crossUp then
                if false_sell then -1 else 1 else na;
def crossunder= if !show_Signal then na else
                if crossDn then
                if false_buy then -1 else 1 else na;
plot OverPoint = if !isNaN(crossover) then -100 else na;
OverPoint.SetPaintingStrategy(PaintingStrategy.SQUARES);
OverPoint.AssignValueColor( if crossover==-1 then Color.RED else Color.GREEN);
OverPoint.SetLineWeight(4);

plot BelowPoint = if !isNaN(crossunder) then 100 else na;
BelowPoint.SetPaintingStrategy(PaintingStrategy.SQUARES);
BelowPoint.AssignValueColor( if crossunder==-1 then Color.RED else Color.GREEN);
BelowPoint.SetLineWeight(4);
def n = barNumber();

addlabel(show_Label,"False Signal(" + round(per,2) + "%)", Color.WHITE);

AssignPriceColor(if !ColorBar then Color.CURRENT else
                 if var_css ==5 then GlobalColor("Green1") else
                 if var_css ==4 then GlobalColor("Green2") else
                 if var_css ==3 then GlobalColor("Green3") else
                 if var_css ==2 then GlobalColor("Green4") else
                 if var_css ==1 then GlobalColor("Green5") else
                 if var_css ==-5 then GlobalColor("Red1") else
                 if var_css ==-4 then GlobalColor("Red2") else
                 if var_css ==-3 then GlobalColor("Red3") else
                 if var_css ==-2 then GlobalColor("Red4") else GlobalColor("Red5"));

### END
Mr. Superman Thanks a lot, Perfect alway,
 
mGRUZ8O.png


CODE:

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
#https://www.tradingview.com/script/dVau7zqn-SuperTrend-Oscillator-LUX/
#// © LuxAlgo
#study("[LUX] SuperTrend Oscillator","SuperOsc [LuxAlgo]")
# Converted by Sam4Cok@Samer800 - 10/2022 - Not Typical
declare lower;
input ColorBar = no;
input length     = 10;
input mult       = 2.0;
input smooth     = 72;
#//Misc
input fixed      = no;    # 'Fixed Transparency'
input show_line  = yes;   # 'Show Lines'
input show_Signal= yes;   # 'Show Signals'
input show_Label   = no;  # 'Show % False Signals'
input src = close;
#//----
def lower; def upper; def trend;
def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
  input cond = 0;
  input src = close;
  input occurrence = 0;
  def n = occurrence + 1;
  def offset = fold j = 0 to 200 with p=1 while p < n + 1
    do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
  plot price = GetValue(src, offset-1);
}
# theme
DefineGlobalColor("Green1" , Color.GREEN); # >=90
DefineGlobalColor("Green2" , CreateColor(5,217,4)); # >=80
DefineGlobalColor("Green3" , CreateColor(4,181,4)); # >=70
DefineGlobalColor("Green4" , CreateColor(3,145,3)); # >=60
DefineGlobalColor("Green5" , CreateColor(2,117,2)); # >=50
DefineGlobalColor("Red1" , Color.RED);   # >=40
DefineGlobalColor("Red2" , CreateColor(214,6,6));   # >=30
DefineGlobalColor("Red3" , CreateColor(184,6,6));   # >=20
DefineGlobalColor("Red4" , CreateColor(145,3,3));   # >=10
DefineGlobalColor("Red5" , CreateColor(117,2,2));   # >=0
#---------------------------------------------------------
def nATR = ATR(Length=length)*mult;
def up = hl2 + nATR;
def dn = hl2 - nATR;
upper = if src[1] < upper[1] then min(up,upper[1]) else up;
lower = if src[1] > lower[1] then max(dn,lower[1]) else dn;
trend = if src > upper[1] then 1 else if src < lower[1] then 0 else trend[1];
def Spt = trend*lower+(1-trend)*upper;
#//----
def ama;
def osc = max(min((src - Spt)/(upper-lower),1),-1);
def alpha = power(osc,2)/length;
ama = nz(ama[1]+alpha*(osc-ama[1]),osc);
def hist = ExpAverage(osc - ama,smooth);
#//----
def MainFixed = if fixed then osc*100 else na;#,'Main Fixed'
def Histogram = hist*100;    # 'Histogram'
plot Signal = ama*100;       # 'Signal'
Signal.AssignValueColor( if ama > 0 then CreateColor(33,87,243) else CreateColor(103,58,183));

def var_css = if osc > 0 then
              if osc*99 > 80 then 5 else
              if osc*99 > 60 then 4 else
              if osc*99 > 40 then 3 else
              if osc*99 > 20 then 2 else 1 else
              if osc <=0 then
              if osc*-99 > 80 then -5 else
              if osc*-99 > 60 then -4 else
              if osc*-99 > 40 then -3 else
              if osc*-99 > 20 then -2 else -1 else na;

plot MainTrans = if fixed then na else osc*100;    # 'Main Transp'
MainTrans.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
MainTrans.AssignValueColor( if var_css ==5 then GlobalColor("Green1") else
                            if var_css ==4 then GlobalColor("Green2") else
                            if var_css ==3 then GlobalColor("Green3") else
                            if var_css ==2 then GlobalColor("Green4") else
                            if var_css ==1 then GlobalColor("Green5") else
                            if var_css ==-5 then GlobalColor("Red1") else
                            if var_css ==-4 then GlobalColor("Red2") else
                            if var_css ==-3 then GlobalColor("Red3") else
                            if var_css ==-2 then GlobalColor("Red4") else GlobalColor("Red5"));
#//----
def a = if isNaN(Close) then na else 80;
def b = if isNaN(Close) then na else -80;
AddCloud(a,b,CreateColor(9,26,72),CreateColor(9,26,72),yes);
AddCloud(MainFixed, 0, Color.CYAN, Color.MAGENTA);
AddCloud(Histogram, 0, Color.WHITE, Color.WHITE, yes);
#//----
def signDiff = sign(osc);
def sig = if (sign(osc) - sign(osc[1])) then osc*-100 else na;
plot Lines = if show_line then sig else na;
Lines.SetStyle(Curve.FIRM);
Lines.AssignValueColor(if osc[1] > 0 then Color.GREEN else Color.RED);
Lines.EnableApproximation();

#//----
def cross   = (src>Spt and src[1]<Spt[1]) or (src<Spt and src[1]>Spt[1]);
def crossUp = (src>Spt and src[1]<Spt[1]);
def crossDn = (src<Spt and src[1]>Spt[1]);

#//----
def false_buy  = valuewhen(crossDn,src,0) < valuewhen(crossUp,src,0);
def false_sell = valuewhen(crossUp,src,0) > valuewhen(crossDn,src,0);
def num = TotalSum(if cross and (false_buy or false_sell) then 1 else 0);
def den = TotalSum(if cross then 1 else 0);
def per = num/den*100;
#//----
def crossover = if !show_Signal then na else
                if crossUp then
                if false_sell then -1 else 1 else na;
def crossunder= if !show_Signal then na else
                if crossDn then
                if false_buy then -1 else 1 else na;
plot OverPoint = if !isNaN(crossover) then -100 else na;
OverPoint.SetPaintingStrategy(PaintingStrategy.SQUARES);
OverPoint.AssignValueColor( if crossover==-1 then Color.RED else Color.GREEN);
OverPoint.SetLineWeight(4);

plot BelowPoint = if !isNaN(crossunder) then 100 else na;
BelowPoint.SetPaintingStrategy(PaintingStrategy.SQUARES);
BelowPoint.AssignValueColor( if crossunder==-1 then Color.RED else Color.GREEN);
BelowPoint.SetLineWeight(4);
def n = barNumber();

addlabel(show_Label,"False Signal(" + round(per,2) + "%)", Color.WHITE);

AssignPriceColor(if !ColorBar then Color.CURRENT else
                 if var_css ==5 then GlobalColor("Green1") else
                 if var_css ==4 then GlobalColor("Green2") else
                 if var_css ==3 then GlobalColor("Green3") else
                 if var_css ==2 then GlobalColor("Green4") else
                 if var_css ==1 then GlobalColor("Green5") else
                 if var_css ==-5 then GlobalColor("Red1") else
                 if var_css ==-4 then GlobalColor("Red2") else
                 if var_css ==-3 then GlobalColor("Red3") else
                 if var_css ==-2 then GlobalColor("Red4") else GlobalColor("Red5"));

### END
@samer800 great job, like always.
 
Is it possible or can someone help create a scan for SuperTrendOscillator by [LUX]? I would like to scan for > 95 or < -95.
 
Last edited by a moderator:

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