
This strategy is a trading system that combines the RSI2 indicator with a moving average. It primarily captures potential long opportunities by monitoring RSI reversal signals in oversold territories while using moving averages as trend filters to improve trading accuracy. The strategy employs a fixed exit mechanism that automatically closes positions after reaching a preset period.
The core logic includes several key elements: 1. Uses RSI with period 2 to identify oversold conditions, entering observation mode when RSI falls below the set buy threshold (default 25) 2. Confirms entry signals when the RSI indicator breaks upward 3. Optionally incorporates moving average filtering, requiring price to be above the moving average for entry 4. Adopts a fixed holding period exit mechanism (default 5 candles) 5. Draws trade lines on the chart connecting buy and sell points, with different colors indicating profit/loss status
This is a well-structured trading strategy with clear logic, capturing market opportunities through RSI oversold reversal signals combined with moving average trend filtering. The strategy’s strengths lie in its flexible parameters and reasonable risk control, but attention must be paid to false breakout risks and parameter sensitivity issues. Through the suggested optimization directions, the strategy has significant room for improvement to enhance its adaptability in different market environments.
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("RSI 2 Strategy with Fixed Lines and Moving Average Filter", overlay=true)
// Input parameters
rsiPeriod = input.int(2, title="RSI Period", minval=1)
rsiBuyLevel = input.float(25, title="RSI Buy Level", minval=0, maxval=100)
maxBarsToHold = input.int(5, title="Max Candles to Hold", minval=1)
maPeriod = input.int(50, title="Moving Average Period", minval=1) // Moving Average Period
useMAFilter = input.bool(true, title="Use Moving Average Filter") // Enable/Disable MA Filter
// RSI and Moving Average calculation
rsi = ta.rsi(close, rsiPeriod)
ma = ta.sma(close, maPeriod)
// Moving Average filter conditions
maFilterCondition = useMAFilter ? close > ma : true // Condition: price above MA
// Buy conditions
rsiIncreasing = rsi > rsi[1] // Current RSI greater than previous RSI
buyCondition = rsi[1] < rsiBuyLevel and rsiIncreasing and strategy.position_size == 0 and maFilterCondition
// Variables for management
var int barsHeld = na // Counter for candles after purchase
var float buyPrice = na // Purchase price
// Buy action
if buyCondition and na(barsHeld)
strategy.entry("Buy", strategy.long)
barsHeld := 0
buyPrice := close
// Increment the candle counter after purchase
if not na(barsHeld)
barsHeld += 1
// Sell condition after the configured number of candles
sellCondition = barsHeld >= maxBarsToHold
if sellCondition
strategy.close("Buy")
// Reset variables after selling
barsHeld := na
buyPrice := na