SuperTrend and RSI Laguerre Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
People seem to really like the RSI Laguerre that @markos shared and SuperTrend is another popular indicator on our site. Why not combine both into a single indicator?

The indicator you see below isn't just about adding SuperTrend and RSI Laguerre into one script to save space. They actually work together to produce buy and sell signals.

4VXzYBq.png


thinkScript Code

Code:
# CSA Nube (RSI Laguerre, SuperTrend)
# Nube
# 8.28.2016

# When RSI Laguerre is combined with SuperTrend, if this study plots a
# line and ST changes that bar or the next one, then it seems to be a
# decent entry.
#
# After making this observation, I'm tentatively going to scrap the momentum
# study (VACD) and just use the Laguerre RSI to decide trend and the
# Supertrend for entry. I think something along the lines of attaching that
# to RSI will be enough to decide direction and then just flag the switchover
# between up and down in ST

# RSI in Laguerre Time Self Adjusting With Fractal Energy
# Mobius
# V02.07.2014
# V03.06.15.2016
# Both Fractal Energy and RSI are plotted. RSI in cyan and FE in yellow. Look for trend exhaustion in the FE and a reversal of RSI or Price compression in FE and an RSI reversal.

#Inputs:
input nFE = 13;#hint nFE: length for Fractal Energy calculation.
input Overbought = 0.80;
input Oversold = 0.20;
Input Label = Yes;
# Variables:
def o;
def h;
def l;
def c;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
def L0;
def L1;
def L2;
def L3;
def RSI;
def OS;
def OB;

# Calculations
o = (open + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;
def gamma = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nFE) /
        (Highest(high, nFE) - Lowest(low, nFE)))
            / Log(nFE);

L0 = (1 – gamma) * c + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];
if L0 >= L1
then {
    CU1 = L0 - L1;
    CD1 = 0;
} else {
    CD1 = L1 - L0;
    CU1 = 0;
}
if L1 >= L2
then {
    CU2 = CU1 + L1 - L2;
    CD2 = CD1;
} else {
    CD2 = CD1 + L2 - L1;
    CU2 = CU1;
}
if L2 >= L3
then {
    CU = CU2 + L2 - L3;
    CD = CD2;
} else {
    CU = CU2;
    CD = CD2 + L3 - L2;
}

RSI = if CU + CD <> 0 then CU / (CU + CD) else 0;
OS = if IsNaN(close) then Double.NaN else Oversold;
OB = if IsNaN(close) then Double.NaN else Overbought;


# Mobius
# SuperTrend
# Chat Room Request
# V03.10.2015

input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = no;

def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
def SuperTrend = ST;

AssignPriceColor(if PaintBars and close < ST
                then GetColor(5)
                else if PaintBars and close > ST
                     then GetColor(7)
                     else Color.CURRENT);

# End Code SuperTrend

def UT = sum(RSI>OB,20);
def DT = sum(RSI<OS,20);

plot Buy = if UT>DT and close > ST and close[1] < ST[1] then close else Double.Nan;
Buy.SetDefaultColor(GetColor(7));
Buy.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot Sell = if UT<DT and close < ST and close[1] > ST[1] then close else Double.Nan;
Sell.SetDefaultColor(GetColor(5));
Sell.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

AddLabel(Label, "Trend: " + if UT>DT then "Up" else if UT<DT then "Down" else "None", if UT>DT then GetColor(1) else if UT<DT then GetColor(5) else GetColor(3));

# End Study

Shareable Link

https://tos.mx/GXojSi

Video Tutorial

 

Attachments

  • 4VXzYBq.png
    4VXzYBq.png
    81.5 KB · Views: 312

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

Watchlist for SuperTrend Crossover

Please check this out to see if it works to pull up the correct charts or not... let me know... Markos
🎯 or fail?

Code:
# WatchList for SuperTrend Crossover
# Mobius in thinkScript Lounge 10:58 AM 8-8-17

input AtrMult = .7;
input nATR = 4;
input AvgType = AverageType. Hull;

def h = high;
def l = low;
def c = close;
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl2 + (ATRmult * ATR);
def DN = hl2 + (-ATRmult * ATR);
def ST = if c < ST[1] then Round(UP / TickSize(), 0) * TickSize() else Round(DN / TickSize(), 0) * TickSize();
def count = if c crosses below ST then 1 else if c < ST then count[1] + 1 else if c crosses above ST then 1 else if c > ST[1] then count[1] + 1 else count[1];
AddLabel(1, count, color.black);
AssignBackgroundColor(if c < ST then Color.Red else Color.Green);

#End of Code#
 
Last edited:
Getting errors for the watchlist script:

No such variable: I at 11:50
Only constants expected here: l CL variable indexer of count at 15:156

S117.png
 
Last edited:
Hi Markos,
Can you please tell me how to save this is in a watchlist ?
Give yourself a head start by going thru the tutorials, Start here: There is 1 if not 2 videos inside here to help

https://usethinkscript.com/threads/how-to-drive-the-tos-scanner.284/
Basically, you will put in as a scan and then create a dynamic watchlist that will update every 3 minutes with changes!

2 quick questions so that I don't talk down to you: Roughly, how long have you been investing/trading? How long w ToS?

Thanks, Markos
 
@macieman cool! With ToS, you are entitled to a free tour. Have 10 or so q's ready to ask. They will go over the complete ThinkorSwim program. Just call the regular support line to set up a time. Welcome again, tell others...
 
Changing the colors in settings doesn't change the bar colors, which seem to get their colors from a function: GetColor(5) or GetColor(7).

What would be the number for green?
 
Thanks

Dark Theme = 6 (Green)
Light Theme = 9 (Green)
Code:
104 AssignPriceColor(if PaintBars and close < ST
105   then GetColor(5)
106     else if PaintBars and close > ST
107       then GetColor(6)
108          else Color.CURRENT);
 
Last edited:
Hi guys, I'm a bit late to the party I see. I'm trying to get the above watchlist scan to work, but I can't get it to work. I don't get any errors when I import the code, it's when I try using the study as a scan that I can't get it to work. can someone spare a little time to get me straightened out? thanks -tom
 
I have copied the link for the Supertrend and RSI Laguerre and used the boolean operator on the plot. The plot looks ok but when I try to convert the signal to a scan, I am facing problems. IS there a code for a scan? If not, if I manually enter the scan and call the study, in the condition editor should I put the Buy as true within 1 bar? If enter the above condition, it shows no matches. Please advise next step. Thanks
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
251 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