Bjorgum True Strength Index For ThinkorSwim

samer800

Moderator - Expert
VIP
Lifetime
Author states:
-This script utilizes simple color changes of the TSI output signals to aid in interpretation of the classic TSI indicator.
-Crosses of the TSI value line and signal line are a bullish or bearish indication. Helps identify that the TSI value line is either dropping or rising, while over or under the signal line.
-This can help anticipate a cross, or significant points in the trend. TSI signal line changes color when rising or falling, which can help to identify larger prevailing trends.
-Generally, a rising signal line can be an overall bullish move, while falling more bearish regardless of crosses.
nhCAok2.png

Code:
#//@Bjorgum on Stocktwits
#//@version=5
#indicator ( "Bjorgum TSI", "BJ TSI" )
#https://www.tradingview.com/script/VX852ekB-Bjorgum-TSI/
# Converted by SAM4COk - Not Exact Convert :)
# ================================== //
# ---------> User Input <----------- //
# ================================== //
declare lower;

def Na = Double.NaN;
def RTH = SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0;

input strat = {default Fast, Slow};

#// TSI Colors //
DefineGlobalColor("tsiBull", CreateColor( 23, 255, 0 ));
DefineGlobalColor("tsiMid", CreateColor(149, 152, 161));
DefineGlobalColor("tsiBear", CreateColor(243, 255, 0 ));
DefineGlobalColor("tslBull", CreateColor(100, 181, 246));
DefineGlobalColor("tslBear", CreateColor(211, 47 , 47 ));
DefineGlobalColor("fillBull", CreateColor(100, 181, 246));
DefineGlobalColor("fillBear", CreateColor(211, 47 , 47 ));
DefineGlobalColor("oBot", CreateColor(255, 0 , 0 ));
DefineGlobalColor("oSold", CreateColor(100, 181, 246));
DefineGlobalColor("oZero", CreateColor(178, 181, 190));
DefineGlobalColor("obBar", CreateColor(255, 0 , 0 ));
DefineGlobalColor("neBar", CreateColor(255, 255, 255));
DefineGlobalColor("osBar", CreateColor( 23, 255, 0 ));

input FastLong = 25; # "Long Length"
input FastShort = 5; # "Short Length"
input FastSignal = 14; # "Signal Length"

input SlowLong = 25; # "Long Length"
input Slowshort = 13; # "Short Length"
input Slowsignal = 13; # "Signal Length"

input OBValue = 30; # "Ob Value"
input OSValue = -30; # "Os Value"
input OBOSLines = yes; # "Show Ob/Os Lines"
input ZeroLine = yes; # "Show Zero Line"
input BarColor = no; # "Ob/Os Curl Color"

# ================================== //,
# ---> Functional Declarations <---- //
# ================================== //

#// TSI Scripts //
script nz
{
input data1 = 0;
input data2 = close;
def ret_val = if IsNaN(data1) then data1 else data2;
plot return = ret_val;
}

script _doubleSmooth {
input src = 0;
input longvar = 0;
input shortvar = 0;
def fist_smooth = ExpAverage(src, longvar);
def smooth = ExpAverage(fist_smooth, shortvar);
plot return = smooth;
}
# ================================== //
# ----> Variable Calculations <----- //
# ================================== //

def tsifast = strat == strat.Fast;
def tsislow = strat == strat.Slow;

def shortvar = if tsifast then FastShort else if tsislow then Slowshort else Na;
def longvar = if tsifast then FastLong else if tsislow then SlowLong else Na;
def signalvar = if tsifast then FastSignal else if tsislow then Slowsignal else Na;

def pc = close - close[1];
def dSmoothPc = _doubleSmooth(pc, longvar, shortvar);
def dSmoothAbs = _doubleSmooth(AbsValue(pc), longvar, shortvar);
def tsi = 100 * (dSmoothPc / dSmoothAbs);
def tsl = ExpAverage(tsi, signalvar);

# ================================== //
# ----> Conditional Parameters <---- //
# ================================== //

def data = tsi > tsi[1] and tsi < tsl;
def dtat = tsi < tsi[1] and tsi > tsl;

def lot1 = tsl >= tsl[1];
def lot2 = tsl < tsl[1];

def data1 = tsi >= tsl;
def data2 = tsi < tsl;

def obcol = tsi > OBValue and tsi < tsi[1] and tsi[1] > tsl[1];
def oscol = tsi < OSValue and tsi > tsi[1] and tsi[1] < tsl[1];

Plot obcol1 = if RTH and obcol then tsl else na;
obcol1.SetPaintingStrategy(PaintingStrategy.POINTS);
obcol1.AssignValueColor(GlobalColor("tslBear"));
obcol1.SetLineWeight(3);

Plot oscol1 = if RTH and oscol then tsl else na;
oscol1.SetPaintingStrategy(PaintingStrategy.POINTS);
oscol1.AssignValueColor(GlobalColor("tsiBull"));
oscol1.SetLineWeight(3);

def buy = Crosses (tsi, tsl , CrossingDirection.ABOVE);
def sell = Crosses (tsi, tsl , CrossingDirection.BELOW);
def cross = Crosses (tsi, tsl , CrossingDirection.ANY);

def tsixup = Crosses (tsi, OBValue, CrossingDirection.ABOVE);
def tsixdwn = Crosses (tsi, OSValue, CrossingDirection.BELOW);

# ================================== //
# ------> Graphical Display <------- //
# ================================== //

plot p1 = tsi; # "TSI Value Line"
p1.AssignValueColor(if data then GlobalColor("tsiBull") else
if dtat then GlobalColor("tsiBear") else GlobalColor("tsiMid"));

plot p2 = tsl; # "TSI Signal Line"
p2.AssignValueColor(if lot1 then GlobalColor("tslBull") else
if lot2 then GlobalColor("tslBear") else color.current);

plot p3 = if OBOSLines then OBValue else Na; # "Overbought"
P3.SetPaintingStrategy(PaintingStrategy.DASHES);
p3.AssignValueColor(GlobalColor("oBot"));

plot p4 = if OBOSLines then OSValue else Na; # "Oversold"
P4.SetPaintingStrategy(PaintingStrategy.DASHES);
p4.AssignValueColor(GlobalColor("oSold"));

plot p5 = if ZeroLine then 0 else Na; # "Zero"
P5.SetPaintingStrategy(PaintingStrategy.DASHES);
p5.AssignValueColor(GlobalColor("oZero"));

Def jercol = if obcol then -1 else if oscol then 1 else 0;

AssignPriceColor ( if BarColor then if jercol > 0 then GlobalColor("osBar") else
if jercol < 0 then GlobalColor("obBar") else
GlobalColor("neBar")else Color.CURRENT);

AddCloud(p1, p2, GlobalColor("fillBull") , GlobalColor("fillBear"));
 
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
216 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