该策略是基于CCI指标进行反转交易的策略。它会在CCI指标出现超买超卖区时,进行反向交易。整体来说,该策略利用CCI指标的超买超卖特征,捕捉价格反转机会进行交易。
首先,该策略基于CCI指标。其中CCI指标的计算公式为:
CCI = (Typical Price - 简单移动平均) / (0.015 * 均方差)
其中, Typical Price = (最高价 + 最低价 + 收盘价)/3 简单移动平均 = 过去N天的Typical Price的移动平均 均方差 = 过去N天Typical Price偏差的平方和的均值
该策略使用长度为11的CCI指标。并设置了-150为超卖区,150为超买区。
在每根K线收盘时,会对长度为11的CCI指标进行检测。如果CCI下穿-150,则发出做多信号;如果CCI上穿150,则发出做空信号。
收到信号后,以市价单开仓。并设置了1%的止盈,0.5%的止损。
4小时CCI反转策略整体来说是一个利用CCI指标进行反转交易的简单策略。它具有策略逻辑清晰,易于实现的优点。但也存在CCI信号不稳定,止盈止损不够灵活等缺点。通过优化CCI参数,加入过滤指标,以及开发动态止盈止损等,可以进一步增强该策略的效果。总体上,该策略为量化交易提供了一个基于CCI指标的思路,但需要进一步优化方能实盘应用。
/*backtest
start: 2023-09-12 00:00:00
end: 2023-10-12 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("4H CCI Strategy", overlay=true)
length = input( 11 )
overSold = input( -150 )
overBought = input( +150 )
price1 = high
price2 = low
ucci = cci(price1, length)
dcci = cci(price2, length)
vcci = cci(ohlc4, 11)
resCustom = input(title="Timeframe", defval="15")
Length = input(16, minval=1)
xPrice = request.security(syminfo.tickerid, resCustom, hlc3)
xvnoise = abs(xPrice - xPrice[1])
nfastend = 0.666
nslowend = 0.0645
nsignal = abs(xPrice - xPrice[Length])
nnoise = sum(xvnoise, Length)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMA = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
basis1 = nAMA
slope = change(basis1,1)
if (not na(vcci))
if (crossover(dcci, overSold))
strategy.entry("CCILE", strategy.long, comment="CCILE")
strategy.exit("exit", "CCILE", profit = 0.01, loss = 0.005)
if (crossunder(ucci, overBought))
strategy.entry("CCISE", strategy.short, comment="CCISE")
strategy.exit("exit", "CCISE", profit = 0.01, loss = 0.005)
//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)