该策略基于商品通道指数(CCI)指标来识别市场的周期性和季节性特征,以捕捉周期的开始和结束。它通过合并移动平均线和能反映可能和实际交易范围的除数来形成最终的指数,从而测量正常水平的偏差,以指示主要的趋势变化。
商品通道指数(CCI)值显示工具相对于其平均价格的交易方式。当CCI值较高时,表示价格高于平均价格;当CCI值较低时,表示价格低于平均价格。CCI值通常不会超出-300至300的范围。
该策略使用长度为10的CCI指标及其长度为10和20的简单移动平均线。当慢速移动平均线低于快速移动平均线时做多;当慢速移动平均线高于快速移动平均线时做空。可以在输入设置中将做多做空反转。
可以通过调整CCI参数或移动平均线周期进行优化,或加入其他技术指标判断资金面。也可以在更高时间框架确定整体趋势,避免在大周期下被套。
该策略利用CCI指标和双移动平均线判断周期性特征,能有效识别短期趋势。优点是规则简单清晰, Parameters 调整灵活,风险容易把控。但也存在一些滞后、误判的可能。通过调整指标参数以及结合更多技术指标或基本面判断,可以获得更好的效果。
/*backtest start: 2023-01-22 00:00:00 end: 2024-01-28 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version = 2 //////////////////////////////////////////////////////////// // Copyright by HPotter v1.0 30/11/2016 // The Commodity Channel Index (CCI) is best used with markets that display cyclical or // seasonal characteristics, and is formulated to detect the beginning and ending of these // cycles by incorporating a moving average together with a divisor that reflects both possible // and actual trading ranges. The final index measures the deviation from normal, which indicates // major changes in market trend. // To put it simply, the Commodity Channel Index (CCI) value shows how the instrument is trading // relative to its mean (average) price. When the CCI value is high, it means that the prices are // high compared to the average price; when the CCI value is down, it means that the prices are low // compared to the average price. The CCI value usually does not fall outside the -300 to 300 range // and, in fact, is usually in the -100 to 100 range. // You can change long to short in the Input Settings // Please, use it only for learning or paper trading. Do not for real trading. //////////////////////////////////////////////////////////// strategy(title="CCI Strategy Reversed Backtest", shorttitle="CCI Strategy") FastMA = input(10, minval=1) SlowMA = input(20, minval=1) reverse = input(true, title="Trade reverse") hline(0, color=purple) xCCI = cci(close, 10) xSMA = sma(xCCI,SlowMA) xFMA = sma(xCCI,FastMA) pos = iff(xSMA < xFMA , 1, iff(xSMA > xFMA, -1, nz(pos[1], 0))) possig = iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos)) if (possig == 1) strategy.entry("Long", strategy.long) if (possig == -1) strategy.entry("Short", strategy.short) barcolor(pos == -1 ? red: pos == 1 ? green : blue) plot(xSMA, color=red, title="CCI MA Slow") plot(xFMA, color=blue, title="CCI MA FAST")