Strategy
This strategy is backtested on daily OHLCV price data across major US equity indices and ETFs. Entry and exit signals are generated from the strategy's indicators with no lookahead bias — trades execute at the open of the bar following the signal.
Performance metrics are computed per symbol and shown individually. The parameter optimization section (where available) runs a grid search over the strategy's key parameters, optimizing for Sharpe ratio. Transaction costs and slippage are not modeled.
The signal logic and indicator code for this strategy is shown in the methodology code section below.
True Strength Index double-smooths price momentum to reduce noise. Enters long when TSI crosses above its signal line, exits on the reverse. Values above zero indicate bullish momentum.
class TSIStrategy(Strategy):
long_n = 25
short_n = 13
signal_n = 7
def init(self):
tsi, signal = _tsi(self.data.Close, self.long_n, self.short_n, self.signal_n)
self.tsi = self.I(lambda: tsi, name="TSI")
self.signal = self.I(lambda: signal, name="Signal")
def next(self):
if crossover(self.tsi, self.signal) and not self.position:
self.buy()
elif crossover(self.signal, self.tsi) and self.position:
self.position.close()| Total return | +11.888% |
| Net profit | $118,885 |
| Gross profit | $662,989 |
| Gross loss | $566,060 |
| CAGR | +0.521% |
| Annualized return | +0.521% |
| Monthly average return | +0.087% |
| Median monthly return | -1.413% |
| Best month return | +5.205% |
| Worst month return | -10.201% |
| Rolling 1-month return | +11.914% |
| Return per trade | +0.057 |
| Log return CAGR | +11.639% |
| Compounded vs simple return difference | -13.242% |
35 trades · green dashes = buy entries · red dashes = sell exits
| Total return | +34.201% |
| Net profit | $342,010 |
| Gross profit | $708,440 |
| Gross loss | $375,210 |
| CAGR | +9.249% |
| Annualized return | +9.249% |
| Monthly average return | +0.766% |
| Median monthly return | +1.903% |
| Best month return | +4.311% |
| Worst month return | -10.339% |
| Rolling 1-month return | +12.491% |
| Return per trade | +0.846 |
| Log return CAGR | -3.533% |
| Compounded vs simple return difference | -35.618% |