You are on page 1of 1

//@version=5

indicator("True Strength Index", shorttitle="TSI", format=format.price,


precision=4)
long = input(title="Long Length", defval=25)
short = input(title="Short Length", defval=13)
signal = input(title="Signal Length", defval=13)
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)

if ta.crossover(tsi_value,ta.ema(tsi_value, signal)) and tsi_value and


ta.ema(tsi_value, signal) < 0
alert('Buy', freq = alert.freq_once_per_bar_close)

if ta.crossunder(tsi_value,ta.ema(tsi_value, signal)) and tsi_value and


ta.ema(tsi_value, signal) > 0
alert('Sell', freq = alert.freq_once_per_bar_close)

You might also like