SuperTrend and RSI Laguerre Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
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.



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


Video Tutorial

 
markos

markos

Well-known member
VIP
Warehouse

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:
B

blackbeard12

New member
This is amazing, there are some good trends with it on 8 min chart and setting mult = .7
 
T

thinky

Member
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

 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
The way to fix this would be to toss the computer out the window! :eek:
In row 11 change the I to lowercase L - l as in "low". Then in row 15 the "1" should resolve. If not, let me know. :)

@thinky Thanks for pointing that out.
Everyone, you should be using Notepad++ or other text editor on script, Never use a Word processor.
 
markos

markos

Well-known member
VIP
Warehouse
I don't have ToS available to me at the moment. Would someone please let me know if the watchlist script is fixed?
 
M

macieman

New member
VIP

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#

Hi Markos,

Can you please tell me how to save this is in a watchlist ?
 
markos

markos

Well-known member
VIP
Warehouse
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


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
 
M

macieman

New member
VIP
Give yourself a head start by going thru the tutorials, Start here: There is 1 if not 2 videos inside here to help


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

Thanks Markos,

Appreciate your help. I had been in trading for 2 yrs now & with TOS its just a week.
 
markos

markos

Well-known member
VIP
Warehouse
@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...
 
M

macieman

New member
VIP
@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...
Great ! Thanks
 
T

thinky

Member
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?
 
T

thinky

Member
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:

Top