RSI combined TSI with cRSI

longluu

New member
This is my RSI that i combine TSI with cRSI, Can i have views on this, to make it better?
# Cyclic RSI
# Origanlly found on Tradingview: https://www.tradingview.com/v/TmqiR1jp/
# Shout out to WentToTrade for the amazing indicator.
# Written in ThinkScript by mfox

# The cyclic smoothed RSI indicator is an enhancement of the classic RSI , adding
# additional smoothing according to the market vibration,
# adaptive upper and lower bands according to the cyclic memory and
# using the current dominant cycle length as input for the indicator.

# The cRSI is used like a standard indicator. The chart highlights trading signals where the signal line # crosses above or below the adaptive lower/upper bands. It is much more responsive to market moves than the basic RSI.

# The indicator uses the dominant cycle as input to optimize signal, smoothing and cyclic memory. To get more in-depth information on the cyclic-smoothed RSI indicator, please read Chapter 4 "Fine tuning technical indicators" of the book "Decoding the Hidden Market Rhythm, Part 1" available at your favorite book store.

declare lower;

def src = close;
input domcycle = 20;
def cyclelen = domcycle / 2;
def vibration = 10;
def leveling = 10.0;
def cyclicmemory = domcycle * 2;

input RSIOversold = 30;
input RSIOverbought = 70;

plot h1 = RSIOversold;
h1.SetDefaultColor(GetColor(8));
h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h1.SetLineWeight(2);

plot h2 = RSIOverbought;
h2.SetDefaultColor(GetColor(8));
h2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h2.SetLineWeight(2);

plot mid = 50;
mid.SetDefaultColor(Color.WHITE);
mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def torque = 2.0 / (vibration + 1.0);
def phasingLag = (vibration - 1.0) / 2.0;


def up = (1 / cyclelen) * (Max((src - src[1]), 0)) + (1 - (1 / cyclelen)) * (if IsNaN(up[1]) then 0 else up[1]);
def down = (1 / cyclelen) * (-Min((src - src[1]), 0)) + (1 - (1 / cyclelen)) * (if IsNaN(down[1]) then 0 else down[1]);

def rsi = if down == 0 then 100 else if up == 0 then 0 else 100 - 100 / (1 + up / down);
def crsi = torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * (if IsNaN(crsi[1]) then 0 else crsi[1]);


def memHigh = fold hx = 0 to cyclicmemory - 1
#def memHigh = fold hx = 0 to 60 -1
with lw = Double.NEGATIVE_INFINITY
do if high > lw then high else lw;

def memLow = fold lx = 0 to cyclicmemory - 1
#def memLow = fold lx = 0 to 60 -1
with hw = Double.POSITIVE_INFINITY
do if low < hw then low else hw;

def lm_hist = if crsi > memHigh and !IsNaN(lm_hist[1])
then crsi
else if -crsi < memLow and !IsNaN(lm_hist[1])
then -crsi
else 0;

def lmax = - (fold lmx = 0 to cyclicmemory - 1
#def lmax = - (fold lmx = 0 to 60 -1
with lwx = Double.NEGATIVE_INFINITY
do if GetValue(lm_hist, lmx) > lwx then GetValue(lm_hist, lmx) else lwx);

def lmin = - (fold lmn = 0 to cyclicmemory - 1
#def lmin = - (fold lmn = 0 to 60 -1
with lwn = Double.POSITIVE_INFINITY
do if GetValue(lm_hist, lmn) < lwn then GetValue(lm_hist, lmn) else lwn);


def mstep = (lmax - lmin) / 100;
def aperc = leveling / 100;


def db = fold dbx = 0 to 100
while (fold blx = 0 to cyclicmemory - 1
# while (fold blx = 0 to 60 - 1
with b
do b + if GetValue(crsi, blx) < lmin + mstep * dbx then 1 else 0 ) / cyclicmemory >= aperc
do lmin + mstep * dbx;

def ub = fold ubx = 0 to 100
while (fold ulx = 0 to cyclicmemory - 1
# while (fold ulx = 0 to getvalue(cyclicmemory, 0) - 1
# while (fold ulx = 0 to 60 - 1
with a
do a + if GetValue(crsi, ulx) >= lmax - mstep * ubx then 1 else 0 ) / cyclicmemory >= aperc
do lmax - mstep * ubx;


plot lowband = if db then db else Double.NaN;
lowband.SetDefaultColor(Color.CYAN);

plot highband = if ub then ub else Double.NaN;
highband.SetDefaultColor(Color.CYAN);

def C = crsi;

def sar = ParabolicSAR();
def dir = if sar < close then 1 else -1;
def s = ExpAverage(C, domcycle);
plot SigLine = s;

SigLine.SetLineWeight(2);
SigLine.AssignValueColor(if dir==1 then Color.GREEN else Color.RED);

AddCloud(lowband, highband, Color.DARK_GRAY, Color.DARK_GRAY);

###########################################################################
#TSItsiTSI
#Settings
#standard = 25,13,8
#quicker = 13,7,8
#daily, weekly & monthly = 40,20,8

#A quick review of the BUY signals:
#1. TSI crosses above zero.
#2. TSI crosses above moving average.
#3. TSI makes higher low (below zero) while price makes a lower low

#And the SELL signals:
#1. TSI crosses below zero
#2. TSI crosses below moving average
#3. TSI makes a lower high (above zero) while price makes a higher high
#4. Trend of TSI breaks down

def longLength = 25;
def shortLength = 13;
def signalLength = 8;
def averageType = AverageType.EXPONENTIAL;

def diff = close - close[1];
def doubleSmoothedAbsDiff = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diff), longLength), shortLength);

def TSI = if doubleSmoothedAbsDiff == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;

def Signal = MovingAverage(averageType, TSI, signalLength);
##########################################################################
#TSI Short Term

def longLengths = 8;
def shortLengths = 8;
def signalLengths = 3;

def diffs = close - close[1];
def doubleSmoothedAbsDiffs = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diffs), longLengths), shortLengths);

def TSIs;
TSIs = if doubleSmoothedAbsDiffs == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diffs, longLengths), shortLengths)) / doubleSmoothedAbsDiffs;
##########################################################################
#TSI Long Term
def longLengthl = 40;
def shortLengthl = 20;
def signalLengthl = 8;

def diffl = close - close[1];
def doubleSmoothedAbsDiffl = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diffl), longLengthl), shortLengthl);

def TSIl;
TSIl = if doubleSmoothedAbsDiffl == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diffl, longLengthl), shortLengthl)) / doubleSmoothedAbsDiffl;
######################################################################
#TSI Horizontal Line
def bullish = TSIl > TSIl[1] and TSIs > TSIs[1] and TSI > TSI[1];
def bearish = TSIl < TSIl[1] and TSIs < TSIs[1] and TSI < TSI[1];
def bar = BarNumber();

plot TSI_Dashboard = C;
TSI_Dashboard.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TSI_Dashboard.SetLineWeight(1);
TSI_Dashboard.AssignValueColor(if bullish then Color.GREEN else if bearish then Color.RED else Color.GRAY);
###############

AddLabel(yes, "Signal ", if dir==1 then Color.GREEN else Color.RED);
AddLabel(yes, "cRSI ", if bullish then Color.GREEN else if bearish then Color.RED else Color.GRAY);

###################

#EndofCode#
 
Last edited by a moderator:
This is my RSI that i combine TSI with cRSI, Can i have views on this, to make it better?
# Cyclic RSI
# Origanlly found on Tradingview: https://www.tradingview.com/v/TmqiR1jp/
# Shout out to WentToTrade for the amazing indicator.
# Written in ThinkScript by mfox

# The cyclic smoothed RSI indicator is an enhancement of the classic RSI , adding
# additional smoothing according to the market vibration,
# adaptive upper and lower bands according to the cyclic memory and
# using the current dominant cycle length as input for the indicator.

# The cRSI is used like a standard indicator. The chart highlights trading signals where the signal line # crosses above or below the adaptive lower/upper bands. It is much more responsive to market moves than the basic RSI.

# The indicator uses the dominant cycle as input to optimize signal, smoothing and cyclic memory. To get more in-depth information on the cyclic-smoothed RSI indicator, please read Chapter 4 "Fine tuning technical indicators" of the book "Decoding the Hidden Market Rhythm, Part 1" available at your favorite book store.

declare lower;

def src = close;
input domcycle = 20;
def cyclelen = domcycle / 2;
def vibration = 10;
def leveling = 10.0;
def cyclicmemory = domcycle * 2;

input RSIOversold = 30;
input RSIOverbought = 70;

plot h1 = RSIOversold;
h1.SetDefaultColor(GetColor(8));
h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h1.SetLineWeight(2);

plot h2 = RSIOverbought;
h2.SetDefaultColor(GetColor(8));
h2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h2.SetLineWeight(2);

plot mid = 50;
mid.SetDefaultColor(Color.WHITE);
mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def torque = 2.0 / (vibration + 1.0);
def phasingLag = (vibration - 1.0) / 2.0;


def up = (1 / cyclelen) * (Max((src - src[1]), 0)) + (1 - (1 / cyclelen)) * (if IsNaN(up[1]) then 0 else up[1]);
def down = (1 / cyclelen) * (-Min((src - src[1]), 0)) + (1 - (1 / cyclelen)) * (if IsNaN(down[1]) then 0 else down[1]);

def rsi = if down == 0 then 100 else if up == 0 then 0 else 100 - 100 / (1 + up / down);
def crsi = torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * (if IsNaN(crsi[1]) then 0 else crsi[1]);


def memHigh = fold hx = 0 to cyclicmemory - 1
#def memHigh = fold hx = 0 to 60 -1
with lw = Double.NEGATIVE_INFINITY
do if high > lw then high else lw;

def memLow = fold lx = 0 to cyclicmemory - 1
#def memLow = fold lx = 0 to 60 -1
with hw = Double.POSITIVE_INFINITY
do if low < hw then low else hw;

def lm_hist = if crsi > memHigh and !IsNaN(lm_hist[1])
then crsi
else if -crsi < memLow and !IsNaN(lm_hist[1])
then -crsi
else 0;

def lmax = - (fold lmx = 0 to cyclicmemory - 1
#def lmax = - (fold lmx = 0 to 60 -1
with lwx = Double.NEGATIVE_INFINITY
do if GetValue(lm_hist, lmx) > lwx then GetValue(lm_hist, lmx) else lwx);

def lmin = - (fold lmn = 0 to cyclicmemory - 1
#def lmin = - (fold lmn = 0 to 60 -1
with lwn = Double.POSITIVE_INFINITY
do if GetValue(lm_hist, lmn) < lwn then GetValue(lm_hist, lmn) else lwn);


def mstep = (lmax - lmin) / 100;
def aperc = leveling / 100;


def db = fold dbx = 0 to 100
while (fold blx = 0 to cyclicmemory - 1
# while (fold blx = 0 to 60 - 1
with b
do b + if GetValue(crsi, blx) < lmin + mstep * dbx then 1 else 0 ) / cyclicmemory >= aperc
do lmin + mstep * dbx;

def ub = fold ubx = 0 to 100
while (fold ulx = 0 to cyclicmemory - 1
# while (fold ulx = 0 to getvalue(cyclicmemory, 0) - 1
# while (fold ulx = 0 to 60 - 1
with a
do a + if GetValue(crsi, ulx) >= lmax - mstep * ubx then 1 else 0 ) / cyclicmemory >= aperc
do lmax - mstep * ubx;


plot lowband = if db then db else Double.NaN;
lowband.SetDefaultColor(Color.CYAN);

plot highband = if ub then ub else Double.NaN;
highband.SetDefaultColor(Color.CYAN);

def C = crsi;

def sar = ParabolicSAR();
def dir = if sar < close then 1 else -1;
def s = ExpAverage(C, domcycle);
plot SigLine = s;

SigLine.SetLineWeight(2);
SigLine.AssignValueColor(if dir==1 then Color.GREEN else Color.RED);

AddCloud(lowband, highband, Color.DARK_GRAY, Color.DARK_GRAY);

###########################################################################
#TSItsiTSI
#Settings
#standard = 25,13,8
#quicker = 13,7,8
#daily, weekly & monthly = 40,20,8

#A quick review of the BUY signals:
#1. TSI crosses above zero.
#2. TSI crosses above moving average.
#3. TSI makes higher low (below zero) while price makes a lower low

#And the SELL signals:
#1. TSI crosses below zero
#2. TSI crosses below moving average
#3. TSI makes a lower high (above zero) while price makes a higher high
#4. Trend of TSI breaks down

def longLength = 25;
def shortLength = 13;
def signalLength = 8;
def averageType = AverageType.EXPONENTIAL;

def diff = close - close[1];
def doubleSmoothedAbsDiff = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diff), longLength), shortLength);

def TSI = if doubleSmoothedAbsDiff == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diff, longLength), shortLength)) / doubleSmoothedAbsDiff;

def Signal = MovingAverage(averageType, TSI, signalLength);
##########################################################################
#TSI Short Term

def longLengths = 8;
def shortLengths = 8;
def signalLengths = 3;

def diffs = close - close[1];
def doubleSmoothedAbsDiffs = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diffs), longLengths), shortLengths);

def TSIs;
TSIs = if doubleSmoothedAbsDiffs == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diffs, longLengths), shortLengths)) / doubleSmoothedAbsDiffs;
##########################################################################
#TSI Long Term
def longLengthl = 40;
def shortLengthl = 20;
def signalLengthl = 8;

def diffl = close - close[1];
def doubleSmoothedAbsDiffl = MovingAverage(averageType, MovingAverage(averageType, AbsValue(diffl), longLengthl), shortLengthl);

def TSIl;
TSIl = if doubleSmoothedAbsDiffl == 0 then 0
else 100 * (MovingAverage(averageType, MovingAverage(averageType, diffl, longLengthl), shortLengthl)) / doubleSmoothedAbsDiffl;
######################################################################
#TSI Horizontal Line
def bullish = TSIl > TSIl[1] and TSIs > TSIs[1] and TSI > TSI[1];
def bearish = TSIl < TSIl[1] and TSIs < TSIs[1] and TSI < TSI[1];
def bar = BarNumber();

plot TSI_Dashboard = C;
TSI_Dashboard.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TSI_Dashboard.SetLineWeight(1);
TSI_Dashboard.AssignValueColor(if bullish then Color.GREEN else if bearish then Color.RED else Color.GRAY);
###############

AddLabel(yes, "Signal ", if dir==1 then Color.GREEN else Color.RED);
AddLabel(yes, "cRSI ", if bullish then Color.GREEN else if bearish then Color.RED else Color.GRAY);

###################

#EndofCode#

For anyone to provide you answers, there needs to be a specific question.
Are you having issues with your study. If so what are they?

Please provide a shared chart link, so members can see the issues that you are seeing.

These indicators are collinear. So why combine them? What is your goal?
https://usethinkscript.com/threads/...nt-to-successful-trading-in-thinkorswim.6114/

How to create a shared chart link:
https://usethinkscript.com/threads/how-to-share-a-chart-in-thinkorswim.14221/
 
Last edited:

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