This strategy is an adaptive system combining trend following and range trading, using the Choppiness Index (CI) to determine market conditions and applying corresponding trading logic. In trending markets, the strategy utilizes EMA crossovers and RSI overbought/oversold signals for trading; in ranging markets, it primarily relies on RSI extreme values. The strategy also includes stop-loss and take-profit mechanisms to control risk and lock in profits.
The core of the strategy lies in using the Choppiness Index (CI) to classify the market into trending (CI<38.2) and ranging (CI>61.8) states. In trending markets, long positions are opened when the fast EMA (9-period) crosses above the slow EMA (21-period) and RSI is below 70, while short positions are opened when the slow EMA crosses above the fast EMA and RSI is above 30. In ranging markets, long positions are opened when RSI is below 30, and short positions when RSI is above 70. The strategy includes corresponding exit conditions with 2% stop-loss and 4% take-profit levels.
This strategy builds an adaptive trading system by combining multiple technical indicators, maintaining stable performance across different market environments. Its core advantages lie in market adaptability and comprehensive risk management mechanisms, while attention must be paid to parameter optimization and market condition dependencies. Through continuous optimization and improvement, the strategy shows promise for achieving better trading results across various market conditions.
/*backtest start: 2024-12-19 00:00:00 end: 2024-12-26 00:00:00 period: 45m basePeriod: 45m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © nopology //@version=6 strategy("CI, EMA, RSI", overlay=false) // Input parameters lengthCI = input(14, title="CI Length") lengthRSI = input(14, title="RSI Length") fastLength = input(9, title="Fast EMA Length") slowLength = input(21, title="Slow EMA Length") // Calculate CI atr = ta.atr(lengthCI) highLowRange = math.log10(math.max(high[lengthCI], high) - math.min(low[lengthCI], low)) sumATR = math.sum(atr, lengthCI) ci = 100 * (math.log10(sumATR / highLowRange) / math.log10(lengthCI)) // Calculate RSI rsi = ta.rsi(close, lengthRSI) // Calculate EMAs fastEMA = ta.ema(close, fastLength) slowEMA = ta.ema(close, slowLength) // Define conditions trendingMarket = ci < 38.2 rangingMarket = ci > 61.8 bullishSignal = ta.crossover(fastEMA, slowEMA) and rsi < 70 bearishSignal = ta.crossover(slowEMA, fastEMA) and rsi > 30 // Plot indicators for visualization plot(ci, title="Choppiness Index", color=color.purple, linewidth=2) plot(fastEMA, title="Fast EMA", color=color.blue) plot(slowEMA, title="Slow EMA", color=color.red) // Strategy Execution if (trendingMarket) if (bullishSignal) strategy.entry("Long", strategy.long) if (bearishSignal) strategy.entry("Short", strategy.short) else if (rangingMarket) if (rsi < 30) strategy.entry("Long", strategy.long) if (rsi > 70) strategy.entry("Short", strategy.short) // Close positions when conditions no longer met or reverse if (trendingMarket and not bullishSignal) strategy.close("Long") if (trendingMarket and not bearishSignal) strategy.close("Short") if (rangingMarket and rsi > 40) strategy.close("Long") if (rangingMarket and rsi < 60) strategy.close("Short") // Optional: Add stop loss and take profit stopLossPerc = input.float(2, title="Stop Loss (%)", minval=0.1, step=0.1) / 100 takeProfitPerc = input.float(4, title="Take Profit (%)", minval=0.1, step=0.1) / 100 strategy.exit("Exit Long", "Long", stop=close*(1-stopLossPerc), limit=close*(1+takeProfitPerc)) strategy.exit("Exit Short", "Short", stop=close*(1+stopLossPerc), limit=close*(1-takeProfitPerc))