Trend Strength Gauge For ThinkOrSwim

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

https://www.tradingview.com/script/aJDdjBh6-Trend-Strength-Gauge/

Hi can anyone help convert this TradingView to thinkorswim indicator code below:

// @VanHe1sing

//@version=5
indicator("Trend Strength Gauge", 'HSMA',overlay = true)

length = input(20, "HSMA Length")

// Hma
wma = ta.wma(close, length)
wma1 = ta.wma(close, length)
a = 3 * wma - 2 * wma1

// Sma
a1 = ta.sma(close, length)

// Extract the difference (HMA - SMA)
diff = a - a1

// Table Function
printTable(txt, col, row, color, txt1, col1, row1, color1) => var table t = table.new(position.bottom_center, 60, 3),
table.cell(t, col, row, txt, bgcolor = color),
table.cell(t, col1, row1, txt1, bgcolor = color1, text_color = color.white)

// Normalize
x = diff
len = 100
xMax = ta.highest(x, len)
xMin = ta.lowest(x, len)
range_ = xMax - xMin
y = x / range_

// Convertation searies float to searies int with round()
g = math.round(y*40)

// Plot
color1 = color.from_gradient(g, -2, 2, color.white, color.teal)
p1 = plot(a, 'HEMA', color1, 2)
p2 = plot(a1, 'SMA', color1, 2)
fill(p1, p2, color = color1)

// Convertation negative values to positive
g := g < 0 ? g *- 1 : g

// Plot trend strength gauge
if barstate.islast
for i = 1 to 40
color_ = math.round(y*40) < 0 ? color.white : color.teal
color = color.from_gradient(i, 1, 50, color.rgb(0, 137, 123, 100), color_)
printTable("", i, 1, color, "V", g, 1, color.rgb(255, 255, 255, 100))
check the below - pls test it in live session.

CSS:
#// https://www.tradingview.com/v/aJDdjBh6/
#// @VanHe1sing
#indicator("Trend Strength Gauge", 'HSMA',overlay =  true)
# Converted and mod by Sam4Cok@Samer800    - 01/2024 - Not Typical
input movAvgType1 = AverageType.WEIGHTED;
input movAvgType2 = AverageType.SIMPLE;
input src = close;
input length = 20;    # "HSMA Length"
input GaugeLength = 40;
input trendGaugeDisplay = {Default "Top", "Bottom", "Top & Bottom", "Don't show"};

def na = Double.NaN;
def bar = CompoundValue(1, BarNumber(), 0);
def last = isNaN(close);
def lastBar = if !isNaN(close) then bar else lastBar[1];

DefineGlobalColor("teal", CreateColor(0, 137, 123));
#// Hma
def mov1  = MovingAverage(movAvgType1, src, length);
#// Sma
def mov2 = MovingAverage(movAvgType2, src, length);
#// Extract the difference (HMA - SMA)
def diff = mov1 - mov2;

#// Normalize
def x = diff;
def len = 100;
def xMax = highest(x, len);
def xMin = lowest(x, len);
def range_ = xMax - xMin;
def y = x / range_;

#// Convertation searies float to searies int with round()
def g = round(y * GaugeLength, 0);
def absG = AbsValue(g);
#/ Convertation negative values to positive
def g1 = if g < 0 then -g else absG;
def GCol = if g >= GaugeLength/2 then 255 else
           if g >=  GaugeLength/4 then 194 else 133;
def WCol = if g <= -GaugeLength/2 then 255 else
           if g <= - GaugeLength/4 then 194 else 133;

plot p1 = mov1;     # 'HEMA'
plot p2 = mov2;    # 'SMA'
p1.SetLineWeight(2);
p2.SetLineWeight(2);
p1.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
p2.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
AddCloud(p1, p2, GlobalColor("teal"), Color.WHITE);

#-- Trend Strength Gauge;
def p1Last = highestAll(inertiaAll(p1,2));
def p2Last = highestAll(inertiaAll(p2,2));
def cloudCond = p1Last > p2Last;
def nATR = atr(Length = 100) / 4;
def vCond = lastBar == highestAll(lastBar + g1) - GaugeLength;
def lineCod = !last and lastBar >= highestAll(lastBar) - GaugeLength;
def hh = highest(high, GaugeLength);
def ll = lowest(low, GaugeLength);

def gaugeT1; def gaugeT2; def gaugeB1; def gaugeB2;
Switch (trendGaugeDisplay) {
Case "Bottom" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Top & Bottom" :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Don't show" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = na;
    gaugeB2 = na;
Default :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = na;
    gaugeB2 = na;
}
def hhTop = highestAll(inertiaAll(gaugeT1, 2));
def hhBot = highestAll(inertiaAll(gaugeT2, 2));
def llTop = highestAll(inertiaAll(gaugeB1, 2));
def llBot = highestAll(inertiaAll(gaugeB2, 2));
def hiTopL =  if lineCod then hhTop else na;
def hiBotL =  if lineCod then hhBot else na;
def LoTopL =  if lineCod then llTop else na;
def LoBotL =  if lineCod then llBot else na;
def gaugeUp = (hiTopL + hiBotL) / 2;
def gaugeLo = (LoTopL + LoBotL) / 2;

plot gaugeTop = if vCond then gaugeUp else na;
plot gaugeBot = if vCond then gaugeLo else na;
gaugeTop.SetLineWeight(2);
gaugeTop.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeTop.SetDefaultColor(Color.YELLOW);
gaugeBot.SetLineWeight(2);
gaugeBot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeBot.SetDefaultColor(Color.YELLOW);


AddCloud(if vCond then hiTopL else na, hiBotL, Color.BLACK);
AddCloud(if vCond then loTopL else na, loBotL, Color.BLACK);

AddCloud(if cloudCond and !vCond then hiTopL else na, hiBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else hiTopL, hiBotL, Color.WHITE);

AddCloud(if cloudCond and !vCond then loTopL else na, loBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else loTopL, loBotL, Color.WHITE);

#-- END of CODE
 
check the below - pls test it in live session.

CSS:
#// https://www.tradingview.com/v/aJDdjBh6/
#// @VanHe1sing
#indicator("Trend Strength Gauge", 'HSMA',overlay =  true)
# Converted and mod by Sam4Cok@Samer800    - 01/2024 - Not Typical
input movAvgType1 = AverageType.WEIGHTED;
input movAvgType2 = AverageType.SIMPLE;
input src = close;
input length = 20;    # "HSMA Length"
input GaugeLength = 40;
input trendGaugeDisplay = {Default "Top", "Bottom", "Top & Bottom", "Don't show"};

def na = Double.NaN;
def bar = CompoundValue(1, BarNumber(), 0);
def last = isNaN(close);
def lastBar = if !isNaN(close) then bar else lastBar[1];

DefineGlobalColor("teal", CreateColor(0, 137, 123));
#// Hma
def mov1  = MovingAverage(movAvgType1, src, length);
#// Sma
def mov2 = MovingAverage(movAvgType2, src, length);
#// Extract the difference (HMA - SMA)
def diff = mov1 - mov2;

#// Normalize
def x = diff;
def len = 100;
def xMax = highest(x, len);
def xMin = lowest(x, len);
def range_ = xMax - xMin;
def y = x / range_;

#// Convertation searies float to searies int with round()
def g = round(y * GaugeLength, 0);
def absG = AbsValue(g);
#/ Convertation negative values to positive
def g1 = if g < 0 then -g else absG;
def GCol = if g >= GaugeLength/2 then 255 else
           if g >=  GaugeLength/4 then 194 else 133;
def WCol = if g <= -GaugeLength/2 then 255 else
           if g <= - GaugeLength/4 then 194 else 133;

plot p1 = mov1;     # 'HEMA'
plot p2 = mov2;    # 'SMA'
p1.SetLineWeight(2);
p2.SetLineWeight(2);
p1.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
p2.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
AddCloud(p1, p2, GlobalColor("teal"), Color.WHITE);

#-- Trend Strength Gauge;
def p1Last = highestAll(inertiaAll(p1,2));
def p2Last = highestAll(inertiaAll(p2,2));
def cloudCond = p1Last > p2Last;
def nATR = atr(Length = 100) / 4;
def vCond = lastBar == highestAll(lastBar + g1) - GaugeLength;
def lineCod = !last and lastBar >= highestAll(lastBar) - GaugeLength;
def hh = highest(high, GaugeLength);
def ll = lowest(low, GaugeLength);

def gaugeT1; def gaugeT2; def gaugeB1; def gaugeB2;
Switch (trendGaugeDisplay) {
Case "Bottom" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Top & Bottom" :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Don't show" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = na;
    gaugeB2 = na;
Default :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = na;
    gaugeB2 = na;
}
def hhTop = highestAll(inertiaAll(gaugeT1, 2));
def hhBot = highestAll(inertiaAll(gaugeT2, 2));
def llTop = highestAll(inertiaAll(gaugeB1, 2));
def llBot = highestAll(inertiaAll(gaugeB2, 2));
def hiTopL =  if lineCod then hhTop else na;
def hiBotL =  if lineCod then hhBot else na;
def LoTopL =  if lineCod then llTop else na;
def LoBotL =  if lineCod then llBot else na;
def gaugeUp = (hiTopL + hiBotL) / 2;
def gaugeLo = (LoTopL + LoBotL) / 2;

plot gaugeTop = if vCond then gaugeUp else na;
plot gaugeBot = if vCond then gaugeLo else na;
gaugeTop.SetLineWeight(2);
gaugeTop.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeTop.SetDefaultColor(Color.YELLOW);
gaugeBot.SetLineWeight(2);
gaugeBot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeBot.SetDefaultColor(Color.YELLOW);


AddCloud(if vCond then hiTopL else na, hiBotL, Color.BLACK);
AddCloud(if vCond then loTopL else na, loBotL, Color.BLACK);

AddCloud(if cloudCond and !vCond then hiTopL else na, hiBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else hiTopL, hiBotL, Color.WHITE);

AddCloud(if cloudCond and !vCond then loTopL else na, loBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else loTopL, loBotL, Color.WHITE);

#-- END of CODE
@samer800 ,,,,
Hi I have been using this and compared to the tradingview version I'd say yours is a lot better ,thank you
Just curious if is possible to make the cloud optional on settings , leave only the lines bottom and top I noticed those works pretty good as support and resistance , I have other studies up and do not want to clutter the chart to much ,thanks in advance.
 
@samer800 ,,,,
Hi I have been using this and compared to the tradingview version I'd say yours is a lot better ,thank you
Just curious if is possible to make the cloud optional on settings , leave only the lines bottom and top I noticed those works pretty good as support and resistance , I have other studies up and do not want to clutter the chart to much ,thanks in advance.
check the below:

CSS:
#// https://www.tradingview.com/v/aJDdjBh6/
#// @VanHe1sing
#indicator("Trend Strength Gauge", 'HSMA',overlay =  true)
# Converted and mod by Sam4Cok@Samer800    - 01/2024 - Not Typical

input higlightTrend = yes;
input movAvgType1 = AverageType.WEIGHTED;
input movAvgType2 = AverageType.SIMPLE;
input src = close;
input length = 20;    # "HSMA Length"
input GaugeLength = 40;
input trendGaugeDisplay = {Default "Top", "Bottom", "Top & Bottom", "Don't show"};

def na = Double.NaN;
def bar = CompoundValue(1, BarNumber(), 0);
def last = isNaN(close);
def lastBar = if !isNaN(close) then bar else lastBar[1];

DefineGlobalColor("teal", CreateColor(0, 137, 123));
#// Hma
def mov1  = MovingAverage(movAvgType1, src, length);
#// Sma
def mov2 = MovingAverage(movAvgType2, src, length);
#// Extract the difference (HMA - SMA)
def diff = mov1 - mov2;

#// Normalize
def x = diff;
def len = 100;
def xMax = highest(x, len);
def xMin = lowest(x, len);
def range_ = xMax - xMin;
def y = x / range_;

#// Convertation searies float to searies int with round()
def g = round(y * GaugeLength, 0);
def absG = AbsValue(g);
#/ Convertation negative values to positive
def g1 = if g < 0 then -g else absG;
def GCol = if g >= GaugeLength/2 then 255 else
           if g >=  GaugeLength/4 then 194 else 133;
def WCol = if g <= -GaugeLength/2 then 255 else
           if g <= - GaugeLength/4 then 194 else 133;

plot HEMA = mov1;   # 'HEMA'
plot SMA = mov2;    # 'SMA'
HEMA.SetLineWeight(2);
SMA.SetLineWeight(2);
HEMA.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
SMA.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
AddCloud(if higlightTrend then HEMA else na, SMA, GlobalColor("teal"), Color.WHITE);

#-- Trend Strength Gauge;
def p1Last = highestAll(inertiaAll(HEMA,2));
def p2Last = highestAll(inertiaAll(SMA,2));
def cloudCond = p1Last > p2Last;
def nATR = atr(Length = 100) / 4;
def vCond = lastBar == highestAll(lastBar + g1) - GaugeLength;
def lineCod = !last and lastBar >= highestAll(lastBar) - GaugeLength;
def hh = highest(high, GaugeLength);
def ll = lowest(low, GaugeLength);

def gaugeT1; def gaugeT2; def gaugeB1; def gaugeB2;
Switch (trendGaugeDisplay) {
Case "Bottom" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Top & Bottom" :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Don't show" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = na;
    gaugeB2 = na;
Default :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = na;
    gaugeB2 = na;
}
def hhTop = highestAll(inertiaAll(gaugeT1, 2));
def hhBot = highestAll(inertiaAll(gaugeT2, 2));
def llTop = highestAll(inertiaAll(gaugeB1, 2));
def llBot = highestAll(inertiaAll(gaugeB2, 2));
def hiTopL =  if lineCod then hhTop else na;
def hiBotL =  if lineCod then hhBot else na;
def LoTopL =  if lineCod then llTop else na;
def LoBotL =  if lineCod then llBot else na;
def gaugeUp = (hiTopL + hiBotL) / 2;
def gaugeLo = (LoTopL + LoBotL) / 2;

plot gaugeTop = if vCond then gaugeUp else na;
plot gaugeBot = if vCond then gaugeLo else na;
gaugeTop.SetLineWeight(2);
gaugeTop.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeTop.SetDefaultColor(Color.YELLOW);
gaugeBot.SetLineWeight(2);
gaugeBot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeBot.SetDefaultColor(Color.YELLOW);


AddCloud(if vCond then hiTopL else na, hiBotL, Color.BLACK);
AddCloud(if vCond then loTopL else na, loBotL, Color.BLACK);

AddCloud(if cloudCond and !vCond then hiTopL else na, hiBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else hiTopL, hiBotL, Color.WHITE);

AddCloud(if cloudCond and !vCond then loTopL else na, loBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else loTopL, loBotL, Color.WHITE);

#-- END of CODE
 
check the below:

CSS:
#// https://www.tradingview.com/v/aJDdjBh6/
#// @VanHe1sing
#indicator("Trend Strength Gauge", 'HSMA',overlay =  true)
# Converted and mod by Sam4Cok@Samer800    - 01/2024 - Not Typical

input higlightTrend = yes;
input movAvgType1 = AverageType.WEIGHTED;
input movAvgType2 = AverageType.SIMPLE;
input src = close;
input length = 20;    # "HSMA Length"
input GaugeLength = 40;
input trendGaugeDisplay = {Default "Top", "Bottom", "Top & Bottom", "Don't show"};

def na = Double.NaN;
def bar = CompoundValue(1, BarNumber(), 0);
def last = isNaN(close);
def lastBar = if !isNaN(close) then bar else lastBar[1];

DefineGlobalColor("teal", CreateColor(0, 137, 123));
#// Hma
def mov1  = MovingAverage(movAvgType1, src, length);
#// Sma
def mov2 = MovingAverage(movAvgType2, src, length);
#// Extract the difference (HMA - SMA)
def diff = mov1 - mov2;

#// Normalize
def x = diff;
def len = 100;
def xMax = highest(x, len);
def xMin = lowest(x, len);
def range_ = xMax - xMin;
def y = x / range_;

#// Convertation searies float to searies int with round()
def g = round(y * GaugeLength, 0);
def absG = AbsValue(g);
#/ Convertation negative values to positive
def g1 = if g < 0 then -g else absG;
def GCol = if g >= GaugeLength/2 then 255 else
           if g >=  GaugeLength/4 then 194 else 133;
def WCol = if g <= -GaugeLength/2 then 255 else
           if g <= - GaugeLength/4 then 194 else 133;

plot HEMA = mov1;   # 'HEMA'
plot SMA = mov2;    # 'SMA'
HEMA.SetLineWeight(2);
SMA.SetLineWeight(2);
HEMA.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
SMA.AssignValueColor(if g >0 then CreateColor(0, GCol, GCol) else
                    if g <0 then CreateColor(WCol, WCol,WCol) else Color.GRAY);
AddCloud(if higlightTrend then HEMA else na, SMA, GlobalColor("teal"), Color.WHITE);

#-- Trend Strength Gauge;
def p1Last = highestAll(inertiaAll(HEMA,2));
def p2Last = highestAll(inertiaAll(SMA,2));
def cloudCond = p1Last > p2Last;
def nATR = atr(Length = 100) / 4;
def vCond = lastBar == highestAll(lastBar + g1) - GaugeLength;
def lineCod = !last and lastBar >= highestAll(lastBar) - GaugeLength;
def hh = highest(high, GaugeLength);
def ll = lowest(low, GaugeLength);

def gaugeT1; def gaugeT2; def gaugeB1; def gaugeB2;
Switch (trendGaugeDisplay) {
Case "Bottom" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Top & Bottom" :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = ll;
    gaugeB2 = ll - nATR;
Case "Don't show" :
    gaugeT1 = na;
    gaugeT2 = na;
    gaugeB1 = na;
    gaugeB2 = na;
Default :
    gaugeT1 = hh + nATR;
    gaugeT2 = hh;
    gaugeB1 = na;
    gaugeB2 = na;
}
def hhTop = highestAll(inertiaAll(gaugeT1, 2));
def hhBot = highestAll(inertiaAll(gaugeT2, 2));
def llTop = highestAll(inertiaAll(gaugeB1, 2));
def llBot = highestAll(inertiaAll(gaugeB2, 2));
def hiTopL =  if lineCod then hhTop else na;
def hiBotL =  if lineCod then hhBot else na;
def LoTopL =  if lineCod then llTop else na;
def LoBotL =  if lineCod then llBot else na;
def gaugeUp = (hiTopL + hiBotL) / 2;
def gaugeLo = (LoTopL + LoBotL) / 2;

plot gaugeTop = if vCond then gaugeUp else na;
plot gaugeBot = if vCond then gaugeLo else na;
gaugeTop.SetLineWeight(2);
gaugeTop.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeTop.SetDefaultColor(Color.YELLOW);
gaugeBot.SetLineWeight(2);
gaugeBot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
gaugeBot.SetDefaultColor(Color.YELLOW);


AddCloud(if vCond then hiTopL else na, hiBotL, Color.BLACK);
AddCloud(if vCond then loTopL else na, loBotL, Color.BLACK);

AddCloud(if cloudCond and !vCond then hiTopL else na, hiBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else hiTopL, hiBotL, Color.WHITE);

AddCloud(if cloudCond and !vCond then loTopL else na, loBotL, GlobalColor("teal"));
AddCloud(if cloudCond or vCond then na else loTopL, loBotL, Color.WHITE);

#-- END of CODE
wow thank you that is exactly what i wanted ,you are the best..
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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