EMA追踪趋势交易策略


创建日期: 2023-09-19 19:38:53 最后修改: 2023-09-19 19:38:53
复制: 0 点击次数: 559
avatar of ChaoZhang ChaoZhang
1
关注
1259
关注者

概述

该策略是一种典型的EMA趋势跟踪策略。它使用快速EMA和慢速EMA的金叉来判断行情进入上涨趋势,使用快速EMA和慢速EMA的死叉来判断行情进入下跌趋势,并相应做多做空。该策略追踪中长线趋势较为可靠,适合中长线持仓交易。

策略原理

该策略的核心逻辑是:

  1. 计算快速EMA,例如12周期EMA
  2. 计算慢速EMA,例如26周期EMA
  3. 当快速EMA上穿慢速EMA时,判断为上涨趋势,做多入场
  4. 当快速EMA下穿慢速EMA时,判断为下跌趋势,做空入场
  5. 在反向趋势来临前,快速EMA重新与慢速EMA发生死叉时,平掉当前持仓

通过计算不同速度的EMA,可以有效识别市场趋势的变化。快速EMA对价格变动更为敏感,有利于及早发现新的趋势;慢速EMA可以过滤虚假信号,确保趋势已被确认。两者配合使用,形成可靠的趋势判断体系。

当两条EMA发生金叉时,说明价格开始持续上涨,应建立做多方向;当发生死叉时,价格开始持续下跌,应建立做空方向。通过快速EMA的重新死叉来退出当前头寸,可以及时止损,避免亏损扩大。

策略优势

  • 使用EMA可有效识别市场中长线趋势
  • 快慢EMA配合形成可靠的趋势判断体系
  • 策略理解简单,易于实施
  • 可配置EMA参数,适应不同交易品种
  • 快速EMA死叉止损,有效控制风险

策略风险及应对

  • 无法提前预测趋势反转点,存在一定亏损
  • EMA参数设置不当可能错过趋势转换点
  • 需要适时调整EMA参数以匹配市场变化

应对方法:

  1. 配置区间止损,避免单笔大亏损
  2. 结合其他指标探测潜在的趋势反转
  3. 优化参数配置,提高对趋势的识别能力

策略优化方向

该策略可以从以下几个方面进行扩展与优化:

  1. 采用机器学习方法自动优化EMA参数,提高参数适应性

  2. 增加基于波动率的持仓调整,根据市场波动性调整仓位

  3. 结合점数震荡指标等判断局部调整的时机,以便优化入场点位

  4. 增加移动止损、获利后调整止盈点等止损策略

  5. 研究交易量变化以判断资金流入流出,辅助趋势判断

  6. 与其他非相关策略组合,降低回撤,提高整体收益稳定性

总结

EMA追踪趋势策略是一个简单实用的趋势跟随策略。它使用快慢EMA跟踪中长线趋势,通过EMA金叉死叉来判断入场时机。策略易于实施,也可进行多维度扩展与优化,使之适应更多市场环境。该策略非常适合中长线持仓追踪趋势性行情。

策略源码
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-18 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HomoDeus666

//@version=5

strategy("EMA12/26 with date backtest range (BTCpair)", overlay=true,initial_capital = 1,commission_type = strategy.commission.percent,currency = currency.BTC)

//input date and time
useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
     group="Backtest Time Period")
backtestStartDate = input(timestamp("1 Jan 2021"), 
     title="Start Date", group="Backtest Time Period",
     tooltip="This start date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")
backtestEndDate = input(timestamp("1 Jan 2022"),
     title="End Date", group="Backtest Time Period",
     tooltip="This end date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")
     
//check date and time option
inTradeWindow =  true
/// plot and indicator
fastEMA = ta.ema(close,12), slowEMA=ta.ema(close,26)
plot(fastEMA,color=color.green,linewidth = 2)
plot(slowEMA,color=color.red,linewidth=2)

//entry when condition
longCondition = ta.crossover(fastEMA,slowEMA)
if (longCondition) and inTradeWindow
    strategy.entry("buy", strategy.long)

if ta.crossunder(ta.ema(close, 12), ta.ema(close, 26)) and inTradeWindow
    strategy.close("buy")
    
// trades and cancel all unfilled pending orders
if not inTradeWindow and inTradeWindow[1]
    strategy.cancel_all()
    strategy.close_all(comment="Date Range Exit")