资源加载中... loading...

CCI+双均线交叉回撤买入策略

Author: ChaoZhang, Date: 2024-05-24 17:45:49
Tags: CCIMA

CCI+双均线交叉回撤买入策略

概述

CCI+双均线交叉回撤买入策略是一种综合利用顺势指标(CCI)和双均线交叉信号的量化交易策略。该策略在双均线金叉形成后,等待价格回撤到快线附近同时CCI指标超卖时买入,在死叉形成后价格反弹到快线附近同时CCI指标超买时卖出。通过结合CCI和双均线交叉信号,该策略可以更好地捕捉趋势性机会,同时通过等待回撤买入和反弹卖出来获得更优的入场和出场时机,从而提高策略的风险收益比。

策略原理

  1. 计算CCI指标,根据用户设置的CCI参数(源数据、周期、移动平均类型、超买超卖阈值)计算当前CCI值。
  2. 判断CCI超买超卖,当CCI大于超买阈值时将背景色设为红色,小于超卖阈值时将背景色设为绿色。
  3. 计算快慢均线,根据用户设置的快慢均线参数(源数据、周期、移动平均类型)分别计算当前快慢均线值。
  4. 判断金叉死叉,当快线上穿慢线形成金叉时绘制多头信号,快线下穿慢线形成死叉时绘制空头信号。
  5. 进行交易决策:
    • 多头入场:当快线在慢线上方,且前一根K线收盘价在快线下方,当前K线为阳线,同时CCI小于超卖阈值时买入开多仓
    • 空头入场:当快线在慢线下方,且前一根K线收盘价在快线上方,当前K线为阴线,同时CCI大于超买阈值时卖出开空仓

策略优势

  1. 趋势跟踪:通过双均线交叉信号来判断趋势方向,能更好地顺应市场趋势。
  2. 逆势入场:在趋势确立后等待价格回撤买入或反弹卖出,可以获得相对更优的入场价格,提高风险收益比。
  3. 降低假信号:将CCI指标与均线交叉信号相结合,能有效降低单一指标产生的假信号。
  4. 参数灵活:用户可根据自己偏好灵活设置CCI和均线参数,以优化策略表现。

策略风险

  1. 震荡市风险:在震荡市场中,频繁的金叉死叉可能导致策略产生较多的亏损交易。
  2. 参数风险:不恰当的参数设置可能导致策略表现欠佳,需要对不同市场状况下的最优参数组合进行充分回测和分析。
  3. 趋势风险:当市场趋势反转时,策略可能会延迟出场而承担更大的回撤风险。

策略优化方向

  1. 引入仓位管理,根据当前市场趋势强度和波动率来动态调整每笔交易的仓位,以更好地控制风险。
  2. 优化入场条件,如加入交易量指标或其它辅助判断指标,提高入场信号的可靠性。
  3. 优化出场条件,如设置移动止损或时间止损,降低单笔交易的最大亏损。
  4. 对不同市场和品种分别进行参数优化,提高策略的适应性和稳健性。

总结

CCI+双均线交叉回撤买入策略是一个兼具趋势跟踪和逆势入场优点的量化交易策略。通过双均线捕捉趋势方向,并利用CCI指标来甄别超买超卖区间,同时等待价格回撤和反弹来获取更优入场价格,可以在一定程度上提高策略的盈利潜力和风险收益比。但该策略同样面临参数优化、震荡市和趋势突变等风险,需要通过进一步优化和改进来增强策略的稳健性和盈利能力。策略思路清晰,代码结构完整,整体适合进行实盘交易。


/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradedots

//@version=5
strategy("CCI + MA Crossover Pullback Buy Strategy [TradeDots]", overlay=true)


ma(source, length, type) =>
  type == "SMA" ? ta.sma(source[1], length) :
  type == "EMA" ? ta.ema(source[1], length) :
  type == "SMMA (RMA)" ? ta.rma(source[1], length) :
  type == "WMA" ? ta.wma(source[1], length) :
  type == "VWMA" ? ta.vwma(source[1], length) :
  na

//CCI settings
cci_coloring  = input.bool(true, "CCI Background Color", group = "Commodity channel index")
cci_length    = input.int(20,"CCI Length", group = "Commodity channel index")
cci_ma_type   = input.string("EMA","CCI MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "Commodity channel index")
cci_soruce    = input(hlc3, "CCI Source", group = "Commodity channel index")
cci_threshold = input.int(100, "CCI Threshold", group = "Commodity channel index")
cci_ma = ma(cci_soruce, cci_length, cci_ma_type)
cci = (cci_soruce - cci_ma) / (0.015 * ta.dev(cci_soruce, cci_length))

bgcolor(cci > cci_threshold and cci_coloring ? color.new(#f9396a, 80) : cci < -cci_threshold and cci_coloring? color.new(#9cff87, 80) : na, title = "CCI Overbought / Oversold")

//ma crossover settings
input_crossover_labels = input.bool(true, "Show Crossover Labels", group="Moving average")

fastma_type   = input.string("EMA","", inline="fastma", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving average")
fastma_source = input(close, "", inline="fastma", group="Moving average")
fastma_length = input.int(10, "", inline="fastma", minval=1,group="Moving average")
fastma_color  = input(#e2fdff, "", inline="fastma",group="Moving average")
fastma = ma(fastma_source, fastma_length, fastma_type)
fastmaPlot = plot(fastma, color = #b7e4c7, linewidth = 2, title = "Fast MA")

slowma_type   = input.string("EMA","", inline="slowma", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving average")
slowma_source = input(close, "", inline="slowma", group="Moving average")
slowma_length = input.int(30, "", inline="slowma", minval=1,group="Moving average")
slowma_color  = input(#e2fdff, "", inline="slowma",group="Moving average")
slowma = ma(slowma_source, slowma_length, slowma_type)
slowmaPlot = plot(slowma, color = #2d6a4f, linewidth = 2, title = "Slow MA")

bullish_crossover = ta.crossover(fastma, slowma)
bearish_crossover = ta.crossunder(fastma, slowma)

// // strategy
// if bullish_crossover and input_crossover_labels
//     line.new(bar_index, close, bar_index, close * 1.01, extend = extend.both, color = color.new(#9cff87, 30), style = line.style_dotted, width = 3)
//     label.new(bar_index,low, "Bullish Crossover", style = label.style_label_up, color = #9cff87)

// else if bearish_crossover and input_crossover_labels
//     line.new(bar_index, close, bar_index, close * 1.01, extend = extend.both, color = color.new(#f9396a, 30), style = line.style_dotted, width = 3)
//     label.new(bar_index, high, "Bearish Crossover", style = label.style_label_down, color = #f9396a, textcolor = color.white)

if fastma > slowma and close[1] < fastma and close > open and cci < -cci_threshold
    strategy.entry("Long", strategy.long)
    // if strategy.opentrades == 0 or strategy.opentrades.size(strategy.opentrades -1) < 0
    //     label.new(bar_index,low, "🟢 Long", style = label.style_label_up, color = #9cff87)

if fastma < slowma and close[1] > fastma and close < open and cci > cci_threshold
    strategy.entry("Short", strategy.short)
    // if strategy.opentrades == 0 or strategy.opentrades.size(strategy.opentrades -1) > 0
    //     label.new(bar_index, high, "🔴 Short", style = label.style_label_down, color = #f9396a, textcolor = color.white)

相关内容

更多内容