0
votes

I am pretty new to the coding world and I am trying to build a simple strategy in Tradingview.

I just want build a buy and sell strategy based on the true strength indicator. So whenever the "slow" line crosses the signal line upwards I want to buy and when the slow line crosses the signal line downwards i want to sell.

Can anyone provide me with the code for that? I have the code for the TSI indicator for just displaying the indicator but not for trading signals.

Thanks very much.

1

1 Answers

0
votes

Create a new Pinscript. Select True Strength Indicator With a small modification, the script would look like this:

//@version=4
study("True Strength Indicator", shorttitle="TSI", format=format.price, precision=4)
long = input(title="Long Length", type=input.integer, defval=25)
short = input(title="Short Length", type=input.integer, defval=13)
signal = input(title="Signal Length", type=input.integer, defval=13)
price = close
double_smooth(src, long, short) =>
    fist_smooth = ema(src, long)
    ema(fist_smooth, short)
pc = change(price)
double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(abs(pc), long, short)
tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
tsi_ema = ema(tsi_value, signal)
plot(tsi_ema, color=#FF006E)
plot(tsi_value, color=#3BB3E4)
hline(0, title="Zero")

Now create your own expression, with the variables tsi_value & tsi_ema

Try whit crossunder or crossover