This strategy combines three technical indicators: Commodity Channel Index (CCI), Directional Movement Index (DMI), and Moving Average Convergence Divergence (MACD) to determine the overbought and oversold conditions of the market and the trend direction. When CCI breaks above the oversold area, DI+ is greater than DI-, and MACD is above the signal line, a buy signal is generated. When CCI breaks below the overbought area, DI- is greater than DI+, and MACD is below the signal line, a sell signal is generated.
By combining the three technical indicators of CCI, DMI, and MACD, this strategy makes a comprehensive judgment on the overbought and oversold conditions, trend direction, and trend strength of the market to generate buy and sell signals. The strategy is clear and easy to implement, but in practical applications, attention needs to be paid to optimizing strategy parameters, controlling trading frequency and risk to improve the stability and profitability of the strategy.
/*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)