双重时间框架动态支撑位交易系统

SMA EMA
创建日期: 2024-12-05 16:44:56 最后修改: 2024-12-05 16:44:56
复制: 0 点击次数: 179
avatar of ChaoZhang ChaoZhang
1
关注
1259
关注者

双重时间框架动态支撑位交易系统

概述

该策略是一个基于双重时间框架的动态支撑位交易系统,通过在周线和日线时间框架上结合SMA和EMA均线的交叉信号来进行交易。系统利用了均线之间形成的支撑带来识别市场趋势和交易机会,通过两个不同时间周期的信号确认来提高交易的准确性。策略采用了百分比仓位管理方式,并考虑了交易成本和滑点因素。

策略原理

策略的核心原理是通过监测两个时间周期内均线的交叉和位置关系来确定交易信号: 1. 长周期(周线)使用20周SMA和21周EMA,短周期(日线)使用50日SMA和51日EMA 2. 在长周期中,当EMA向上穿越SMA时产生做多信号,向下穿越时产生平仓信号 3. 在短周期中,当EMA向上穿越SMA且短周期EMA位于长周期EMA之上时产生做多信号 4. 当短周期出现做空信号或长周期均线交叉向下时,系统会平掉所有多单 5. 策略在指定的时间范围内运行,超出范围自动平仓

策略优势

  1. 多重确认机制:通过两个时间周期的信号确认,降低虚假信号的影响
  2. 动态支撑带:均线之间形成的支撑带能够动态适应市场变化
  3. 风险管理完善:包含了交易成本和滑点的考虑,使用百分比仓位管理
  4. 自适应性强:支撑带会随市场波动自动调整位置
  5. 操作规则明确:入场和出场条件清晰,易于执行和回测

策略风险

  1. 震荡市场风险:在横盘震荡市场中可能产生频繁的虚假信号
  2. 滞后性风险:均线指标本身具有一定滞后性,可能错过最佳入场点
  3. 参数敏感性:均线周期的选择对策略表现影响较大
  4. 市场环境依赖:策略在趋势市场表现较好,但在剧烈波动市场中可能表现欠佳
  5. 资金管理风险:固定百分比仓位可能在某些市况下风险过大

策略优化方向

  1. 引入波动率指标:考虑添加ATR等波动率指标来动态调整仓位大小
  2. 优化参数选择:可以通过回测不同时间周期的均线参数来优化系统表现
  3. 增加市场环境过滤:添加趋势强度指标来过滤不适合的市场环境
  4. 完善止损机制:考虑添加移动止损或固定止损来进一步控制风险
  5. 优化仓位管理:可以根据信号强度和市场波动来动态调整仓位大小

总结

该策略通过结合不同时间周期的均线交叉信号来构建一个相对稳健的交易系统。通过支撑带的概念来识别市场趋势,利用多重确认机制来提高交易的准确性。策略的设计考虑了实际交易中的各种因素,包括交易成本、滑点和时间管理等。虽然存在一些固有的风险,但通过提供的优化方向可以进一步提升策略的稳定性和盈利能力。

策略源码
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-04 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Demo GPT - Bull Market Support Band", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.1, slippage=3)

start_date = input(timestamp("2018-01-01 00:00 +0000"), title="Start Date")
end_date = input(timestamp("2069-12-31 00:00 +0000"), title="End Date")

lsmaLength = input.int(20, title="Long SMA Length", minval=1)
lemaLength = input.int(21, title="Long EMA Length", minval=1)
customLongTimeframe = input.timeframe("W", title="Long Timeframe")  // Khung thời gian dài
ssmaLength = input.int(50, title="Short SMA Length", minval=1)
semaLength = input.int(51, title="Short EMA Length", minval=1)
customShortTimeframe = input.timeframe("D", title="Short Timeframe")  // Khung thời gian ngắn

source = close

// Tính toán SMA và EMA cho khung thời gian dài
smaLong = ta.sma(source, lsmaLength)
emaLong = ta.ema(source, lemaLength)
outSmaLong = request.security(syminfo.tickerid, customLongTimeframe, smaLong)
outEmaLong = request.security(syminfo.tickerid, customLongTimeframe, emaLong)

// Tính toán SMA và EMA cho khung thời gian ngắn
smaShort = ta.sma(source, ssmaLength)
emaShort = ta.ema(source, semaLength)
outSmaShort = request.security(syminfo.tickerid, customShortTimeframe, smaShort)
outEmaShort = request.security(syminfo.tickerid, customShortTimeframe, emaShort)

// Plot các chỉ báo trên biểu đồ
smaPlotLong = plot(outSmaLong, color=color.new(color.red, 0), title='20w SMA (Long)')
emaPlotLong = plot(outEmaLong, color=color.new(color.green, 0), title='21w EMA (Long)')
smaPlotShort = plot(outSmaShort, color=color.new(color.red, 0), title='20d SMA (Short)')
emaPlotShort = plot(outEmaShort, color=color.new(color.green, 0), title='21d EMA (Short)')

// Fill vùng giữa các đường SMA và EMA
fill(smaPlotLong, emaPlotLong, color=color.new(color.orange, 75), fillgaps=true)
fill(smaPlotShort, emaPlotShort, color=color.new(color.orange, 75), fillgaps=true)

// Điều kiện long và short cho khung thời gian dài
longConditionLong = ta.crossover(outEmaLong, outSmaLong)
shortConditionLong = ta.crossunder(outEmaLong, outSmaLong)

// Điều kiện long và short cho khung thời gian ngắn
longConditionShort = ta.crossover(outEmaShort, outSmaShort) and (outEmaShort > outEmaLong)
shortConditionShort = ta.crossunder(outEmaShort, outSmaShort) and (outEmaShort > outEmaLong) // Điều kiện short khi EMA ngắn hạn cắt xuống dưới SMA ngắn hạn và EMA ngắn hạn cao hơn EMA dài hạn

// Kiểm tra điều kiện trong khoảng thời gian được chỉ định
inDateRange = true

// Nếu khung ngắn hạn xuất hiện tín hiệu short, ưu tiên đóng tất cả các lệnh Long
if shortConditionShort and inDateRange
    strategy.close_all()

// Nếu khung dài có tín hiệu short, đóng tất cả các lệnh Long
if shortConditionLong and inDateRange
    strategy.close_all()

// Nếu khung ngắn hạn có tín hiệu long và không có tín hiệu short từ khung dài, vào lệnh Long
if longConditionShort and not shortConditionLong and not shortConditionShort and inDateRange
    strategy.entry("Long", strategy.long)

// Đóng tất cả các lệnh khi không trong khoảng thời gian được chọn
if not inDateRange
    strategy.close_all()
相关推荐