# Trend Strength Signals [AlgoAlpha] For ThinkOrSwim

##### New member
The author states:
Introducing the Trend and Strength Signals indicator by AlgoAlpha!

This indicator calculates the moving average and standard deviation of the closing price over a customizable period to identify the upper and lower bounds. When the price crosses these bounds, it signals an uptrend or downtrend. The gauge measures market strength by comparing the price to the moving average and scaling it over a customizable range, while the underlying logic uses concepts from the Bollinger Bands, this indicator gives a unique perspective on price behavior through added features and signals derived from it.

mod note:
find the ToS script in the next post

Last edited by a moderator:

indicator("Trend Strength Signals [AlgoAlpha]", "AlgoAlpha - 𝑻𝒓𝒆𝒏𝒅 𝑺𝒕𝒓𝒆𝒏𝒈𝒕𝒉", true)
c = input.bool(true, "Enable Cloud")
lenn = input.int(20, "Period")
mult = input.float(2.5, "Standard Deviation Multiplier for TP")
tc = input.int(25, "Gauge Size", minval = 3)
upColor = input.color(#00ffbb, "Up Color")
downColor = input.color(#ff1100, "Down Color")
// Guage Function
t = table.new(position.middle_right, 3, tc+1),
printTable(txt, col, row, color, txt1, col1, row1, color1) =>
table.cell(t, col, row, txt, bgcolor = color),
table.cell(t, col1, row1, txt1, bgcolor = color1, text_color = color.white)
len = lenn
src = close
basis = ta.sma(src, lenn)
upper = basis + ta.stdev(src, len, true)
lower = basis - ta.stdev(src, len, true)
upper1 = basis + ta.stdev(src, len, true) * mult
lower1 = basis - ta.stdev(src, len, true) * mult
var trend = 0
if src > basis and src > upper
trend := 1
if src < basis and src < lower
trend := -1
pu=plot(upper, "upper Line", color.new(chart.fg_color, 80), display = c ? display.all : display.none)
pl=plot(lower, "lower Line", color.new(chart.fg_color, 80), display = c ? display.all : display.none)
barcolor(src > upper ? upColor : src < lower ? downColor : chart.fg_color)
xMax = 100
xMin = 0
range_ = xMax - xMin
y = 1 - grad / range_
y := y > 100 ? 100 : y < 0 ? 0 : y
fill(pu, pl, color.new(chart.fg_color, ta.sma(grad1, 7)), "Trend Fill", display = c ? display.all : display.none)
plotshape(ta.crossover(trend, 0), "Bullish Trend", shape.labelup, location.belowbar, upColor, text = "▲", textcolor = chart.fg_color)
plotshape(ta.crossunder(trend, 0), "Bearish Trend", shape.labeldown, location.abovebar, downColor, text = "▼", textcolor = chart.fg_color)
plotchar(ta.crossover(src, lower1), "Short TP", "X", location.belowbar, upColor, size = size.tiny)
plotchar(ta.crossunder(src, upper1), "Long TP", "X", location.abovebar, downColor, size = size.tiny)
// Draw Gauge
for i = 1 to tc
color_ = chart.fg_color
color = color.from_gradient(i, 1, tc, src > basis ? upColor : downColor, color_)
printTable("", 1, i, color, ">", 1, math.round(y*tc), #ffffff00)
check the below:

CSS:
``````#indicator("Trend Strength Signals [AlgoAlpha]", "AlgoAlpha - 𝑻𝒓𝒆𝒏𝒅 𝑺𝒕𝒓𝒆𝒏𝒈𝒕𝒉", true)
# converted by Sam4Cok@Samer800    - 06/2024

input showGauge = yes; #, "Gauge Size", minval = 3)
input colorBars = yes;
input movAvgType = AverageType.SIMPLE;
input src = close;
input enableBand  = no;
input enableCloud = yes; #, "Enable Cloud")
input Period = 20; #, "Period")
input StandardDeviationMultiplier = 2.5; #, "Standard Deviation Multiplier for TP")

def na = Double.NaN;
def last = IsNaN(close);

def basis = MovingAverage(movAvgType, src, Period);
def stdv = StDev(src, Period);
def upper = basis + stdv;
def lower = basis - stdv;

def upper1 = basis + stdv * StandardDeviationMultiplier;
def lower1 = basis - stdv * StandardDeviationMultiplier;

def trend = if src > basis and src > upper then 1 else
if src < basis and src < lower then -1 else trend[1];

def bgCol = if src > upper then 1 else if src < lower then -1 else 0;

def pUp = if enableCloud then upper else na; # "upper Line"
def pLo = if enableCloud then lower else na; # "lower Line"

def trndBull = (trend crosses above 0); # "Bullish Trend"
def trndBear = (trend crosses below 0); # "Bearish Trend"
def exitShort = (src crosses above lower1); # "Short TP"
def exitLong  = (src crosses below upper1); # "Long TP",

def diff = basis - src;
def hDiff = Highest(diff, 200);
def grad = AbsValue(diff) / hDiff * 100;
def y0 = if isNaN(grad) then 0 else if grad > 100 then 100 else if grad < 0 then 0 else grad;
def y  = y0 * 2.55;
def rndY = Round(y0, 0) ;

#-- plots
plot upBand = if enableBand then upper1 else na;
plot dnBand = if enableBand then lower1 else na;
plot baseLine = if enableBand then basis else na;

upBand.SetDefaultColor(Color.DARK_GREEN);
dnBand.SetDefaultColor(Color.DARK_RED);
baseLine.SetDefaultColor(Color.GRAY);

#-- Signals
plot extLong = if exitLong then high else na;
plot extShort = if exitShort then low else na;
extLong.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
extShort.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
extLong.SetDefaultColor(Color.CYAN);
extShort.SetDefaultColor(Color.MAGENTA);

#-- bar color
AssignPriceColor(if !colorBars then Color.CURRENT else
if bgCol > 0 then Color.UPTICK else
if bgCol < 0 then Color.DOWNTICK else Color.WHITE);

AddLabel(showGauge , "Trend Strength: " + (if diff < 0 then "Up (" else "Dn (") + rndY + "%)",
if diff < 0 then CreateColor(255 - y, 255, 255) else CreateColor(255 , 255 - y, 255));
#-#-- end of CODE``````

Last edited by a moderator:
The author states:
Introducing the Trend and Strength Signals indicator by AlgoAlpha!

This indicator calculates the moving average and standard deviation of the closing price over a customizable period to identify the upper and lower bounds. When the price crosses these bounds, it signals an uptrend or downtrend. The gauge measures market strength by comparing the price to the moving average and scaling it over a customizable range, while the underlying logic uses concepts from the Bollinger Bands, this indicator gives a unique perspective on price behavior through added features and signals derived from it.

mod note:
find the ToS script in the next post

Last edited by a moderator:

You will find that the majority of the thousands of indicators on this forum, do not have a ToS link.
Most of the indicators have to be copied and then pasted into the study tab of the ToS desktop platform.
To find the code to be copied in this thread:

Here is a tutorial on how to copy & paste:

Come back and tell the community, how it goes? if you have any other difficulties? and what everyone wants to know!!!

Cheers,

Last edited by a moderator:

CSS:
``````input Period = 20;

input movAvgType = AverageType.exponential;
#input movAvgType = AverageType.SIMPLE;

def basis = MovingAverage(movAvgType, close, Period);
def stdv = StDev(close, Period);
def upper = basis + stdv;
def lower = basis - stdv;

def trend = if close > basis and close > upper then 1 else if close < basis and close < lower then -1 else trend[1];

def trndBull = (trend crosses above 0);
def trndBear = (trend crosses below 0);

def signal = if trndBull then 1 else if trndBear then -1 else 0;

if signal == 1 then "Buy" else
if signal == -1 then "Sell" else
if trend == 1 then "Bullish" else
if trend == -1 then "Bearish" else "Neutral",
if signal == 1 then Color.GREEN else
if signal == -1 then Color.RED else
if trend == 1 then Color.GREEN else
if trend == -1 then Color.RED else Color.GRAY
);``````

87k+ Posts
338 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?