Trend Strength Signals [AlgoAlpha] For ThinkOrSwim

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.

NyoP1PO.png


please convert
https://www.tradingview.com/v/7NIERkQE/

mod note:
find the ToS script in the next post
 
Last edited by a moderator:

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

https://www.tradingview.com/v/7NIERkQE/

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)
grad = math.abs(basis-src)/(ta.highest(basis-src, 200))*100
grad1 = math.min(grad,40)
grad1 := 100-grad1
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)
///////Alerts
alertcondition(ta.crossover(trend, 0), "Bullish Trend")
alertcondition(ta.crossunder(trend, 0), "Bearish Trend")
alertcondition(ta.crossover(src, lower1), "Short TP")
alertcondition(ta.crossunder(src, upper1), "Long TP")
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);

AddCloud(pUp, pLo, Color.GRAY, Color.GRAY, no);

#-- 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);

AddChartBubble(trndBull, low, "B", Color.GREEN, no);
AddChartBubble(trndBear, high, "S", Color.RED);

#-- 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.

NyoP1PO.png


please convert
https://www.tradingview.com/v/7NIERkQE/

mod note:
find the ToS script in the next post
Can you please provide the TOS link / code...Thanks
 
Last edited by a moderator:
Can you please provide the TOS link...Thanks

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:
https://usethinkscript.com/threads/...-algoalpha-for-thinkorswim.18941/#post-143415

Here is a tutorial on how to copy & paste:
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/

Come back and tell the community, how it goes? if you have any other difficulties? and what everyone wants to know!!!
How does this indicator enhance your trading strategy?

Cheers,
 
Last edited by a moderator:
For your watchlist

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;

AddLabel(yes,
    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
);
 
For your watchlist

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;

AddLabel(yes,
    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
);
At the end of your code there is an invalid statement with “add label “

How can I edit in order to use the study ?
 
At the end of your code there is an invalid statement with “add label “

How can I edit in order to use the study ?

You did not provide enough information to determine where you went astray.
Using the below watchlist code in a chart as a label does not throw an error.

Here is another approach.
This is a shared chart link: http://tos.mx/!3ChxeynX
You must follow these instructions to load this link:
https://usethinkscript.com/threads/...ed-item-error-in-thinkorswim.5098/#post-57930

Importing the above link will open a chart with this label applied.
It also puts the indicator into your library.
zAzr2lB.png


Watchlist Column Script which can also be used as a chart label
Ruby:
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;

AddLabel(yes,
    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
);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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