Algorithm RSI Range Breakout Strategy
This strategy monitors the breakout of RSI indicator in different ranges to implement buying low and selling high. It goes long when RSI is in the low range and goes short when RSI is in the high range, thus…

Overview
This strategy monitors the breakout of RSI indicator in different ranges to implement buying low and selling high. It goes long when RSI is in the low range and goes short when RSI is in the high range, thus reversing position when overbought or oversold conditions appear.
Strategy Logic
Set RSI period to 14
Set RSI buy signal ranges:
- Range 1: RSI <= 27
- Range 2: RSI <= 18
Set RSI sell signal ranges:
- Range 1: RSI >= 68
- Range 2: RSI >= 80
When RSI enters buy range, go long:
- If RSI enters range 1 (below 27), go long 1 lot
- If RSI enters range 2 (below 18), go additional long 1 lot
When RSI enters sell range, go short:
- If RSI enters range 1 (above 68), go short 1 lot
- If RSI enters range 2 (above 80), go additional short 1 lot
Set fixed take profit to 2500 pips and stop loss to 5000 pips
Close position when RSI exits signal range
Advantage Analysis
The double range setting helps better identify overbought and oversold conditions, avoiding missing reversal opportunities
Adopting fixed take profit and stop loss in pips prevents chasing trends too much
RSI is a mature oscillator in identifying overbought and oversold levels with advantages over other indicators
With proper parameter tuning, this strategy can effectively catch trend reversal points and generate excess returns
Risk Analysis
RSI divergence may happen leading to consecutive losses from sustained short position
Fixed take profit and stop loss may not match market volatility, unable to profit or stopping out prematurely
Improper range setting may lead to missing trades or frequent unprofitable trades
This strategy relies much on parameter optimization based on backtests. Careful walk-forward analysis is needed.
Optimization Directions
Test effectiveness of RSI with different period lengths
Optimize buy and sell range values to fit characteristics of different products
Research dynamic take profit and stop loss to improve profitability and reasonability
Consider combining other indicators for ensemble trading to improve robustness
Explore machine learning techniques to auto-optimize parameter ranges for robustness
Conclusion
This strategy is based on RSI's overbought and oversold principles. By adopting double trading ranges, it utilizes RSI indicator effectively, capturing market extremes with decent stability. However, it has some parameter reliance and needs optimization across products. If tuned properly, this strategy can yield good excess returns. In summary, it is a simple yet effective trading strategy using a mature indicator, worth researching for improvements and providing insights for quantitative trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Length |
| v_input_2 | 27 | Buy Level 1 |
| v_input_3 | 18 | Buy Level 2 |
| v_input_4 | 68 | Sell Level 1 |
| v_input_5 | 80 | Sell Level 2 |
| v_input_6 | 2500 | target Pips |
| v_input_7 | 5000 | Stop Pips |
| v_input_8 | true | Lot Size |
Source Pine Script
/*backtest
start: 2023-09-16 00:00:00
end: 2023-10-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Rawadabdo
// Ramy's Algorithm
//@version=5
strategy("BTC/USD - RSI", overlay=false, initial_capital = 5000)
// User input
length = input(title = "Length", defval=14, tooltip="RSI period")
first_buy_level = input(title = "Buy Level 1", defval=27, tooltip="Level where 1st buy triggers")
second_buy_level = input(title = "Buy Level 2", defval=18, tooltip="Level where 2nd buy triggers")
first_sell_level = input(title = "Sell Level 1", defval=68, tooltip="Level where 1st sell triggers")
second_sell_level = input(title = "Sell Level 2", defval=80, tooltip="Level where 2nd sell triggers")
takeProfit= input(title="target Pips", defval=2500, tooltip="Fixed pip stop loss distance")
stopLoss = input(title="Stop Pips", defval=5000, tooltip="Fixed pip stop loss distance")
lot = input(title = "Lot Size", defval = 1, tooltip="Trading Lot size")
// Get RSI
vrsi = ta.rsi(close, length)
// Entry Conditions
long1 = (vrsi <= first_buy_level and vrsi>second_buy_level)
long2 = (vrsi <= second_buy_level)
short1= (vrsi >= first_sell_level and vrsi<second_sell_level)
short2= (vrsi >= second_sell_level)
// Entry Orders
// Buy Orders
if (long1 and strategy.position_size == 0)
strategy.entry("Long", strategy.long, qty=lot, comment="Buy")
if (long2 and strategy.position_size == 0)
strategy.entry("Long", strategy.long, qty=lot, comment="Buy")
// Short Orders
if (short1 and strategy.position_size == 0)
strategy.entry("Short", strategy.short,qty=lot, comment="Sell")
if (short2 and strategy.position_size == 0)
strategy.entry("Short", strategy.short,qty=lot, comment="Sell")
// Exit our trade if our stop loss or take profit is hit
strategy.exit(id="Long Exit", from_entry="Long",qty = lot, profit=takeProfit, loss=stopLoss)
strategy.exit(id="Short Exit", from_entry="Short", qty = lot, profit=takeProfit, loss=stopLoss)
// plot data to the chart
hline(first_sell_level, "Overbought Zone", color=color.red, linestyle=hline.style_dashed, linewidth = 2)
hline(second_sell_level, "Overbought Zone", color=color.green, linestyle=hline.style_dashed, linewidth = 2)
hline(first_buy_level, "Oversold Zone", color=color.red, linestyle=hline.style_dashed, linewidth = 2)
hline(second_buy_level, "Oversold Zone", color=color.green, linestyle=hline.style_dashed, linewidth = 2)
plot (vrsi, title = "RSI", color = color.blue, linewidth=2)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-17. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Algorithm-RSI-Range-Breakout-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Bollinger Band Channel Breakout Trading StrategyPine Script · Breakout · 1d
- Bollinger Bands Dynamic Breakout StrategyPine Script · Breakout · 1h
- Bull Market Tracking SystemPine Script · Breakout · 1h
- Cross boundary Dynamic Range Quantitative Trading Strategy Based on Bollinger BandsPine Script · Breakout · 3h
- Cross period Value Area Breakout StrategyPine Script · Breakout · 1d
- Darvas Box Breakout and Risk Management Strategy DarvasPine Script · Breakout · 1d