// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © julzen2

//@version=5
indicator("TSI", overlay=false)

First_R = input.int(5, title="First EMA Period")
Second_S = input.int(8, title="Second EMA Period")

// Momentum (MTM)
mtm = close - close[1]
abs_mtm = math.abs(mtm)

// First smoothing
ema_mtm = ta.ema(mtm, First_R)
ema_abs_mtm = ta.ema(abs_mtm, First_R)

// Second smoothing
ema2_mtm = ta.ema(ema_mtm, Second_S)
ema2_abs_mtm = ta.ema(ema_abs_mtm, Second_S)

// TSI Calculation
tsi = 100 * ema2_mtm / ema2_abs_mtm

plot(tsi, title="TSI", color=color.yellow, linewidth=2)
hline(0, "Zero Line", color=color.gray)
