True Strength [PINESCRIPTLABS]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PINE_LABS

//@version=5
indicator("True Strength [PINESCRIPTLABS]", shorttitle="True Strength [PINESCRIPTLABS]", format=format.price, precision=4, timeframe="", timeframe_gaps=true,overlay =false)
long = input(title="Long Length", defval=40)
short = input(title="Short Length", defval=40)
signal = input(title="Signal Length", defval=13)
buy_tsi_value = input(title="Buy TSI Value", defval=-40.0)
sell_tsi_value = input(title="Sell TSI Value", defval=40.0)
price = close
double_smooth(src, long, short) =>
    fist_smooth = ta.ema(src, long)
    ta.ema(fist_smooth, short)
pc = ta.change(price)
double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(math.abs(pc), long, short)
tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
plot(tsi_value, title="True Strength Index", color=#2962FF)
plot(ta.ema(tsi_value, signal), title="Signal", color=#E91E63)
hline(0, title="Zero", color=#787B86)

buySignal = tsi_value <= buy_tsi_value
sellSignal = tsi_value >= sell_tsi_value

plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(sellSignal, style=shape.triangledown, location=location.top, color=color.red, size=size.small)
plot(buy_tsi_value, style=plot.style_linebr, color=color.green)
plot(sell_tsi_value, style=plot.style_linebr, color=color.red)
