1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
96 lines of Pine Script v5 from strategies/momentum/tsi_strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
tsi_strategy.pine
//@version=5
strategy("TSI Strategy - Eterna MCP",
shorttitle="TSI",
overlay=false,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
initial_capital=1000)
// ============================================
// PARAMETERS
// ============================================
longLength = input.int(25, "Long Length", minval=1)
shortLength = input.int(13, "Short Length", minval=1)
signalLength = input.int(13, "Signal Length", minval=1)
overboughtLevel = input.int(25, "Overbought", minval=10, maxval=50)
oversoldLevel = input.int(-25, "Oversold", minval=-50, maxval=-10)
leverageSize = input.float(5.0, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, maxval=1)
// ============================================
// TSI CALCULATION
// ============================================
// Price change
pc = ta.change(close)
// Double smoothed momentum
double_smoothed_pc = ta.ema(ta.ema(pc, longLength), shortLength)
double_smoothed_abs_pc = ta.ema(ta.ema(math.abs(pc), longLength), shortLength)
// TSI
tsi = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
// Signal line
signal = ta.ema(tsi, signalLength)
// ============================================
// SIGNAL GENERATION
// ============================================
// Crossover signals
bullishCross = ta.crossover(tsi, signal)
bearishCross = ta.crossunder(tsi, signal)
// Zero-line cross (trend change)
bullishZero = ta.crossover(tsi, 0)
bearishZero = ta.crossunder(tsi, 0)
// Oversold/Overbought with momentum
bullishOB = tsi < oversoldLevel and tsi > tsi[1] and bullishCross
bearishOS = tsi > overboughtLevel and tsi < tsi[1] and bearishCross
// Combined entry signals
buySignal = (bullishCross and tsi < 0) or bullishOB
sellSignal = (bearishCross and tsi > 0) or bearishOS
// ============================================
// STRATEGY LOGIC
// ============================================
if buySignal and strategy.position_size == 0
strategy.entry("Long", strategy.long)
alert('{"action":"buy","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)
if sellSignal and strategy.position_size == 0
strategy.entry("Short", strategy.short)
alert('{"action":"sell","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)
// Exit on opposite signal
if sellSignal and strategy.position_size > 0
strategy.close("Long")
if buySignal and strategy.position_size < 0
strategy.close("Short")
// ============================================
// PLOTTING
// ============================================
plot(tsi, "TSI", color=color.blue, linewidth=2)
plot(signal, "Signal", color=color.orange, linewidth=1)
hline(overboughtLevel, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed)
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_solid, linewidth=2)
// Histogram
histogram = tsi - signal
plot(histogram, "Histogram", color=histogram > 0 ? color.green : color.red, style=plot.style_histogram, linewidth=2)
// Signals
plotshape(buySignal, "Buy", shape.triangleup, location.bottom, color.green, size=size.normal)
plotshape(sellSignal, "Sell", shape.triangledown, location.top, color.red, size=size.normal)
// Trend markers
plotshape(bullishZero, "Bull Trend", shape.circle, location.bottom, color.lime, size=size.tiny)
plotshape(bearishZero, "Bear Trend", shape.circle, location.top, color.orange, size=size.tiny)
// Background coloring
bgcolor(tsi > overboughtLevel ? color.new(color.red, 95) :
tsi < oversoldLevel ? color.new(color.green, 95) : na)
Overview
TSI Strategy - Eterna MCP opens long positions on bullish signal line crossovers occurring below zero or in oversold territory, and short positions on bearish crossovers above zero or in overbought territory. Open trades are closed when an opposing entry signal triggers. The strategy emits JSON webhook alerts configured for automated execution and plots the oscillator, signal line, histogram, and threshold levels in a separate pane. It contains no built-in stop-loss mechanism.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Long Length
int
25
longLength
Short Length
int
13
shortLength
Signal Length
int
13
signalLength
Overbought
int
25
overboughtLevel
Oversold
int
-25
oversoldLevel
Leverage
float
5.0
leverageSize
Position Size
float
0.01
positionSize
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra
This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und
This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr
This strategy estimates price behavior using ordinary least squares regression between higher-timeframe data and a generated dataset, smoothed by a Karobein oscillator. It enters long positions when the oscillator turns upward and short positions when it turns
This strategy executes mean-reversion trades based on Bollinger Bands and the Stochastic Oscillator. Long orders trigger when price dips below the lower band alongside a bullish Stochastic crossover, with an optional oversold threshold. Short orders execute on
This strategy calculates a 20-period Relative Strength Index (RSI) and generates entry orders based on crossovers and crossunders of the 50 level. When RSI crosses above 50, it places a long stop entry at the current high price with a custom alert message. Whe