本策略是一个基于商品通道指标(CCI)的动量交易系统,通过监测价格偏离均值的程度来捕捉市场超卖区域的交易机会。策略采用12个周期作为回溯期,在CCI指标跌破-90阈值时进场做多,当收盘价突破前期高点时平仓出场,并配备了可选的止损和获利了结机制。
策略核心是利用CCI指标来衡量价格与其均值之间的偏离程度。CCI的计算过程包括:首先计算典型价格(最高价、最低价和收盘价的算术平均值),然后计算典型价格的简单移动平均线(SMA),最后通过típical price减去SMA并除以平均偏差再乘以0.015得到最终的CCI值。当CCI值低于-90时,表明市场可能处于超卖状态,此时入场做多;当价格突破前期高点时,表明上涨趋势确立,此时平仓获利。策略还提供了止损和获利了结的参数设置选项,可根据交易者的风险偏好进行灵活调整。
该策略通过CCI指标捕捉市场超卖机会,配合止损和获利了结机制,实现了一个完整的交易系统。策略逻辑清晰,易于执行,具有良好的风险控制能力。通过引入信号过滤、动态阈值等优化手段,策略的稳定性和盈利能力还有提升空间。建议交易者在实盘使用前进行充分的回测,并根据具体市场特征调整参数设置。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("CCI Threshold Strategy", overlay=false, initial_capital=50000, pyramiding=0, commission_type=strategy.commission.cash_per_contract, commission_value=0.05, slippage=1)
// --- Input Parameters ---
// Lookback period for CCI calculation
lookbackPeriod = input.int(12, minval=1, title="CCI Lookback Period")
// Buy threshold for CCI; typically represents an oversold condition
buyThreshold = input.int(-90, title="CCI Buy Threshold")
// Stop loss and take profit settings
stopLoss = input.float(100.0, minval=0.0, title="Stop Loss in Points")
takeProfit = input.float(150.0, minval=0.0, title="Take Profit in Points")
// Checkboxes to enable/disable SL and TP
useStopLoss = input.bool(false, title="Enable Stop Loss")
useTakeProfit = input.bool(false, title="Enable Take Profit")
// --- Calculate CCI ---
// CCI (Commodity Channel Index) is used as a momentum indicator to identify oversold and overbought conditions
cci = ta.cci(close, length=lookbackPeriod)
// --- Define Buy and Sell Conditions ---
// Buy condition: CCI drops below -90, indicating potential oversold levels
longCondition = cci < buyThreshold
// Sell condition: Close price crosses above the previous day's high, signaling potential exit
sellCondition = close > ta.highest(close[1], 1)
// --- Strategy Execution ---
// Buy entry based on the long condition
if (longCondition)
strategy.entry("Buy", strategy.long)
// Close the long position based on the sell condition
if (sellCondition)
strategy.close("Buy")
// Optional: Add stop loss and take profit for risk management
if (longCondition)
strategy.exit("Sell", from_entry="Buy", loss=useStopLoss ? stopLoss : na, profit=useTakeProfit ? takeProfit : na)
// --- Plotting for Visualization ---
// Plot CCI with threshold levels for better visualization
plot(cci, title="CCI", color=color.blue)
hline(buyThreshold, "Buy Threshold", color=color.red, linestyle=hline.style_dotted)
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)