RSI Threshold Rules for Long Entries and Position Exits
Summary
This document describes a long-only RSI strategy. It enters when RSI crosses above 35, sets a stop below the entry price and a take-profit above it, then liquidates when RSI crosses below a configurable exit threshold or falls below 10. The accompanying implementation exposes RSI length, stop-loss, take-profit, and exit-threshold parameters, with defaults for the RSI length and thresholds. It sizes orders from account balance and price and checks available margin before entering.
The material supplies trading rules and implementation details but no backtest period, market specification, or performance evidence. It does not describe short entries, since shorting is disabled. The exit threshold can be tuned, and an emergency RSI exit is included, but the document does not evaluate how these choices behave across markets or regimes. The fixed price-based stop and target may therefore need separate validation, including transaction costs and risk sizing, before conclusions about performance can be drawn.
Key ideas
- A long position opens when RSI crosses above 35.
- The position has a price-based stop and take-profit set relative to entry.
- The strategy exits when RSI crosses below a configurable threshold or below 10.
- Short entries are disabled in the supplied implementation.
- No market-specific backtest or performance results are provided.
Tags
Full text
# TradingView_RSI
# TradingView_RSI
Based on https://www.tradingview.com/script/Ru7qOVtp-RSI-Trend-Crypto/
Default Trading Rules:
Long: RSI crosses over 35
Close Long: RSI crosses under 75
Emergency Exit: RSI crosses under 10
## Source (MIT)
```python
"""
Based on https://www.tradingview.com/script/Ru7qOVtp-RSI-Trend-Crypto/
Default Trading Rules:
Long: RSI crosses over 35
Close Long: RSI crosses under 75
Emergency Exit: RSI crosses under 10
"""
from jesse.strategies import Strategy
import jesse.indicators as ta
from jesse import utils
class TradingView_RSI(Strategy):
def hyperparameters(self):
return [
{'name':'rsi', 'type': int, 'min': 10, 'max':30, 'default': 5},
{'name':'stop_loss', 'type': float, 'min': .5, 'max': .99, 'default': .95},
{'name':'take_profit', 'type': float, 'min': 1.1, 'max': 1.2, 'default': 1.1},
{'name':'xparam', 'type':int, 'min': 60, 'max': 90, 'default': 75}
]
@property
def rsi(self):
return ta.rsi(self.candles, self.hp['rsi'], sequential=True)
def should_long(self):
qty = utils.size_to_qty(self.balance, self.price, 3, fee_rate=self.fee_rate)
if utils.crossed(self.rsi, 35, direction="above") and qty > 0 and self.available_margin > (qty * self.price):
return True
def should_short(self):
return False
def should_cancel_entry(self):
return False
def go_long(self):
qty = utils.size_to_qty(self.balance, self.price, 3, fee_rate=self.fee_rate)
self.buy = qty, self.price
self.stop_loss = qty, (self.price * self.hp['stop_loss']) # Willing to lose 5%
self.take_profit = qty, (self.price * self.hp['take_profit']) # Take profits at 10%
def go_short(self):
pass
def update_position(self):
if utils.crossed(self.rsi, self.hp['xparam'], direction="below") or utils.crossed(self.rsi, 10, direction="below"):
self.liquidate()
```Shown in full with attribution under the source's licence. Licence: MIT
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.