该策略是一个结合了趋势跟踪和区间交易的自适应系统,通过波动指数(CI)来判断市场状态,并根据不同的市场环境采用相应的交易逻辑。在趋势市场中,策略利用EMA交叉和RSI超买超卖信号进行交易;在区间市场中,则主要依据RSI指标的极值进行交易。策略还包含了止损止盈机制,以控制风险和锁定利润。
策略的核心是通过波动指数(CI)将市场分为趋势市场(CI<38.2)和区间市场(CI>61.8)两种状态。在趋势市场中,当快速EMA(9周期)上穿慢速EMA(21周期)且RSI低于70时,开立多头;当慢速EMA上穿快速EMA且RSI高于30时,开立空头。在区间市场中,当RSI低于30时开立多头,高于70时开立空头。同时,策略设置了相应的平仓条件和2%的止损以及4%的止盈水平。
该策略通过结合多个技术指标构建了一个自适应的交易系统,能够在不同市场环境下保持稳定表现。策略的核心优势在于其市场适应性和完善的风险管理机制,但同时也需要注意参数优化和市场条件依赖性等问题。通过持续优化和改进,该策略有望在各种市场环境下实现更好的交易效果。
/*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))