该策略结合了三个技术指标:顺势指标(CCI)、方向运动指数(DMI)和移动平均线聚散指标(MACD),用于判断市场的超买超卖状态以及趋势方向。当CCI从超卖区域向上突破,同时DI+大于DI-且MACD大于信号线时,产生买入信号;当CCI从超买区域向下突破,同时DI-大于DI+且MACD小于信号线时,产生卖出信号。
该策略通过将CCI、DMI和MACD三个技术指标结合起来,对市场的超买超卖状态、趋势方向和趋势强度进行综合判断,产生买卖信号。策略思路清晰,易于实现,但在实际应用中需要注意优化策略参数、控制交易频率和风险,以提高策略的稳定性和盈利能力。
/*backtest
start: 2024-03-01 00:00:00
end: 2024-03-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("CCI, DMI, and MACD Strategy", overlay=true)
// Define inputs
cci_length = input(14, title="CCI Length")
overbought_level = input(100, title="Overbought Level")
oversold_level = input(-100, title="Oversold Level")
// Calculate CCI
cci_value = ta.cci(close, cci_length)
// Calculate DMI
[di_plus, di_minus, _] = ta.dmi(14, 14)
// Calculate MACD
[macd_line, signal_line, _] = ta.macd(close, 24, 52, 9)
// Define buy and sell conditions
buy_signal = ta.crossover(cci_value, oversold_level) and di_plus > di_minus and macd_line > signal_line // CCI crosses above -100, Di+ > Di-, and MACD > Signal
sell_signal = ta.crossunder(cci_value, overbought_level) and di_minus > di_plus and macd_line < signal_line // CCI crosses below 100, Di- > Di+, and MACD < Signal
// Define exit conditions
buy_exit_signal = ta.crossover(cci_value, overbought_level) // CCI crosses above 100
sell_exit_signal = ta.crossunder(cci_value, oversold_level) // CCI crosses below -100
// Execute trades based on conditions
strategy.entry("Buy", strategy.long, when=buy_signal)
strategy.close("Buy", when=buy_exit_signal)
strategy.entry("Sell", strategy.short, when=sell_signal)
strategy.close("Sell", when=sell_exit_signal)
// Plot CCI
plot(cci_value, title="CCI", color=color.blue)
// Plot DMI
plot(di_plus, title="DI+", color=color.green)
plot(di_minus, title="DI-", color=color.red)
// Plot MACD and Signal lines
plot(macd_line, title="MACD", color=color.orange)
plot(signal_line, title="Signal", color=color.purple)
// Plot overbought and oversold levels
hline(overbought_level, "Overbought", color=color.red)
hline(oversold_level, "Oversold", color=color.green)