
The RSI Trend Reversal Strategy is a quantitative trading strategy based on the Relative Strength Index (RSI) and Average True Range (ATR). It dynamically adjusts the take profit and stop loss (TP/SL) levels to adapt to rapid market fluctuations and capture trend reversal opportunities. The strategy centers around the RSI, combined with ATR to measure volatility, and constructs two adaptive dynamic bands as the basis for opening and closing positions. This strategy can be used independently or as a take profit and stop loss module for other strategies. It has been well-tested on 15-minute data of stocks such as Tesla (TSLA), Apple (AAPL), and Nvidia (NVDA).
The core of the RSI Trend Reversal Strategy lies in the construction of dynamic TP/SL bands. First, it uses custom highest_custom and lowest_custom functions to find the highest and lowest prices since the last crossover, forming the basis of the bands. Then, it calculates the RSI and ATR with a length specified by the user and performs the following calculations: 1. Lower Band = Highest Price × [1 - (ATR/Price + 1/(RSI Lower Band × multiplier))] 2. Upper Band = Lowest Price × [1 + (ATR/Price + 1/(RSI Upper Band × multiplier))]
Here, multiplier is a user-defined band expansion factor. If the price breaks above the upper band, it goes long; if it breaks below the lower band, it goes short. The colors of these two bands also change according to the position of the price relative to the bands, making it easy to observe.
The RSI Trend Reversal Strategy utilizes RSI and ATR to construct adaptive bands that can dynamically adjust TP/SL points and promptly respond to market changes. The strategy has clear logic, wide applicability, and can be a powerful tool for quantitative traders. However, in practical use, attention still needs to be paid to parameter selection and risk control, and it is recommended to use it in combination with other indicator signals to improve overall performance. The strategy has further room for optimization, such as adding trend filters and parameter optimization. Overall, the RSI Trend Reversal Strategy provides a simple yet effective approach to quantitative trading.
/*backtest
start: 2023-04-22 00:00:00
end: 2024-04-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("RSI Trend Reversal", overlay=true, max_bars_back = 4999, calc_on_every_tick = false)
//INPUTS
rsi_length = input.int(title = "Lenght", defval = 8)
rsi_mult = input.float(title = "Multiplier", defval = 1.5, step = .05)
lookback = input.int(title = "Delay to prevent idealization", defval = 1)
sltp = input.float(title = "Minimum Difference", defval = 10)
src = input.source(title = "Source Input", defval = close)
//PARAMETERS INITILIZATION
hclose = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, src)
//FUNCTION INITILIZATION
highest_custom(src, length) =>
x = src
for i = 0 to length
if src[i] > x
x := src[i]
x
lowest_custom(src, length) =>
x = src
for i = 0 to length
if src[i] < x
x := src[i]
x
rsilev(src, length, mult, sltp) =>
sl = (100 - sltp) / 100
tp = (100 + sltp) / 100
var bool crossup = na
var bool crossdown = na
var float dir = na
dir_change = ta.change(dir)
var float BearGuy = 0
BullGuy = ta.barssince(crossup or crossdown)
if na(BullGuy)
BearGuy += 1
else
BearGuy := BullGuy
var float upper = na
var float lower = na
rsilower = ta.rsi(src, length)
rsiupper = math.abs(ta.rsi(src, length) - 100)
atr = ta.atr(length) / src
lower := highest_custom(math.max(highest_custom(highest_custom(src, BearGuy) * (1 - (atr + ((1 / (rsilower) * mult)))), BearGuy), src * sl), BearGuy)
upper := lowest_custom(math.min(lowest_custom(lowest_custom(src, BearGuy) * (1 + (atr + ((1 / (rsiupper) * mult)))), BearGuy), src * tp), BearGuy)
var float thresh = na
if na(thresh)
thresh := lower
if na(dir)
dir := 1
if crossdown
dir := -1
if crossup
dir := 1
if dir == 1
thresh := lower
if dir == -1
thresh := upper
crossup := ta.crossover(src, thresh)
crossdown := ta.crossunder(src, thresh)
thresh
rsiclose = rsilev(hclose, rsi_length, rsi_mult, sltp)
//PLOTTING
var color col = color.lime
if hclose > rsiclose
col := color.lime
if hclose < rsiclose
col := color.red
plot(rsiclose, linewidth = 2, color = col)
//STRATEGY
buy = ta.crossover(hclose, rsiclose)
sell = ta.crossunder(hclose, rsiclose)
if buy[lookback]
strategy.entry("long", strategy.long)
if sell[lookback]
strategy.entry("Short", strategy.short)