该策略是一种典型的EMA趋势跟踪策略。它使用快速EMA和慢速EMA的金叉来判断行情进入上涨趋势,使用快速EMA和慢速EMA的死叉来判断行情进入下跌趋势,并相应做多做空。该策略追踪中长线趋势较为可靠,适合中长线持仓交易。
该策略的核心逻辑是:
通过计算不同速度的EMA,可以有效识别市场趋势的变化。快速EMA对价格变动更为敏感,有利于及早发现新的趋势;慢速EMA可以过滤虚假信号,确保趋势已被确认。两者配合使用,形成可靠的趋势判断体系。
当两条EMA发生金叉时,说明价格开始持续上涨,应建立做多方向;当发生死叉时,价格开始持续下跌,应建立做空方向。通过快速EMA的重新死叉来退出当前头寸,可以及时止损,避免亏损扩大。
应对方法:
该策略可以从以下几个方面进行扩展与优化:
采用机器学习方法自动优化EMA参数,提高参数适应性
增加基于波动率的持仓调整,根据市场波动性调整仓位
结合점数震荡指标等判断局部调整的时机,以便优化入场点位
增加移动止损、获利后调整止盈点等止损策略
研究交易量变化以判断资金流入流出,辅助趋势判断
与其他非相关策略组合,降低回撤,提高整体收益稳定性
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")