这个策略基于商品通道指数(CCI)指标,旨在在超卖情况下做多,在超买情况下做空。它还可选地使用指数移动平均线(EMA) filter,以控制只在趋势方向交易。该策略还提供基于固定百分比或平均真实范围(ATR)的止损止盈方式。
使用CCI指标判断市场趋势
CCI通过比较当前价格与一定周期内的平均价格来度量动量
CCI above 150为超买,below -100为超卖
可选使用EMA filter
仅在价格高于EMA时做多,价格低于EMA时做空
使用EMA判断趋势方向,避免反趋势交易
提供两种止损止盈方式
基于固定百分比的止损止盈:使用入场价的固定百分比来设置止损止盈
基于ATR的止损止盈: 使用ATR的倍数来设置止损,再根据风险回报比率计算止盈
入场条件
CCI上穿-100线时做多
CCI下穿150线时做空
如果启用EMA,仅在价格高于EMA时做多,价格低于EMA时做空
出场条件
价格触及止损止盈平仓
CCI重新进入超买超卖区域时平仓
绘图
使用CCI判断超买超卖情况,这是CCI指标的经典用法
可选EMA可确保只在趋势方向交易,避免反转
提供两种止损止盈方式,可以根据市场调整止损止盈的参数
根据CCI指标再次进入超买超卖区域来平仓,可锁定趋势反转利润
绘图突出CCI信号,易于判读
策略逻辑清晰简单,容易理解和优化
CCI指标存在滞后,可能出现错过反转或产生假信号
EMA参数设置不当可能错过趋势或使策略无效
百分比止损止盈难以适应市场变化,应设较宽参数
ATR止损止盈对间隔周期敏感,应调整至最佳参数
回撤风险较大,应适当调整仓位管理
效果随市场环境变化,应适时评估指标参数
评估不同周期的CCI参数,找到最佳参数组合
测试不同EMA周期,确定最合适的趋势判断周期
调整止损止盈参数,取得最佳风险收益比
增加其他filter条件,如交易量,进一步过滤假信号
结合趋势线或图形进行形态判断,提高效果
增加仓位管理策略,如固定仓位,来控制回撤风险
全面回测不同市场环境数据,动态调整参数
该策略运用CCI指标的经典超买超卖原理进行入场。加入EMA filter可控制趋势方向。提供两种止损止盈方式便于调整。绘图突出信号易判读。策略逻辑简单清晰,易于理解和优化。通过参数调整、增加filter条件、风险控制等方面可进一步提高效果。
/*backtest start: 2023-09-24 00:00:00 end: 2023-10-24 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/ // © alifer123 //@version=5 // strategy("CCI+EMA Strategy with Percentage or ATR TP/SL [Alifer]", shorttitle = "CCI_EMA_%/ATR_TP/SL", overlay=false, // initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.045) length = input(14, "CCI Length") overbought = input.int(150, step = 10, title = "Overbought") oversold = input.int(-140, step = 10, title = "Oversold") src = hlc3 ma = ta.sma(src, length) cci = (src - ma) / (0.015 * ta.dev(src, length)) // EMA useEMA = input(true, "Use EMA", tooltip = "Only enters long when price is above the EMA, only enters short when price is below the EMA") emaLength = input(55, "EMA Length") var float ema = na if useEMA ema := ta.ema(src, emaLength) // Take Profit and Stop Loss Method tpSlMethod_percentage = input(true, "Percentage TP/SL", group="TP/SL Method") tpSlMethod_atr = input(false, "ATR TP/SL", group="TP/SL Method") // Percentage-based Take Profit and Stop Loss tp_percentage = input.float(10.0, title="Take Profit (%)", step=0.1, group="TP/SL Method") sl_percentage = input.float(10.0, title="Stop Loss (%)", step=0.1, group="TP/SL Method") // ATR-based Take Profit and Stop Loss atrLength = input(20, title="ATR Length", group="TP/SL Method") atrMultiplier = input(4, title="ATR SL Multiplier", group="TP/SL Method") riskRewardRatio = input(2, title="Risk Reward Ratio", group="TP/SL Method") // Calculate TP/SL levels based on the selected method, or leave them undefined if neither method is selected longTP = tpSlMethod_percentage ? strategy.position_avg_price * (1 + tp_percentage / 100) : na longSL = tpSlMethod_percentage ? strategy.position_avg_price * (1 - sl_percentage / 100) : na shortTP = tpSlMethod_percentage ? strategy.position_avg_price * (1 - tp_percentage / 100) : na shortSL = tpSlMethod_percentage ? strategy.position_avg_price * (1 + sl_percentage / 100) : na if tpSlMethod_atr longSL := strategy.position_avg_price - ta.atr(atrLength) * atrMultiplier longTP := ((strategy.position_avg_price - longSL) * riskRewardRatio) + strategy.position_avg_price shortSL := strategy.position_avg_price + ta.atr(atrLength) * atrMultiplier shortTP := ((strategy.position_avg_price - shortSL) * riskRewardRatio) - strategy.position_avg_price // Enter long position when CCI crosses below oversold level and price is above EMA longCondition = ta.crossover(cci, oversold) and (not useEMA or close > ema) if longCondition strategy.entry("Buy", strategy.long) // Enter short position when CCI crosses above overbought level and price is below EMA shortCondition = ta.crossunder(cci, overbought) and (not useEMA or close < ema) if shortCondition strategy.entry("Sell", strategy.short) // Close long positions with Take Profit or Stop Loss if strategy.position_size > 0 strategy.exit("Long Exit", "Buy", limit=longTP, stop=longSL) // Close short positions with Take Profit or Stop Loss if strategy.position_size < 0 strategy.exit("Short Exit", "Sell", limit=shortTP, stop=shortSL) // Close positions when CCI crosses back above oversold level in long positions or below overbought level in short positions if ta.crossover(cci, overbought) strategy.close("Buy") if ta.crossunder(cci, oversold) strategy.close("Sell") // Plotting color_c = cci > overbought ? color.red : (cci < oversold ? color.green : color.white) plot(cci, "CCI", color=color_c) hline(0, "Middle Band", color=color.new(#787B86, 50)) obband = hline(overbought, "OB Band", color=color.new(#78867a, 50)) osband = hline(oversold, "OS Band", color=color.new(#867878, 50)) fill(obband, osband, color=color.new(#787B86, 90))