该策略的名称为“Trend Following with EMA”,即基于趋势和均线的量化交易策略。它结合了趋势跟踪和指数移动平均线(EMA)两种技术指标,用于识别股票或者其他金融产品的价格趋势,并据此进行买入和卖出操作。
该策略的主要逻辑是:
使用长度为180周期的低点和收盘价的交叉来判断价格上升趋势。当低点上穿收盘价时,表示价格开始上升,形成趋势,此时做多;
当价格从下降趋势转为上升趋势时,即收盘价上穿开盘价,并且EMA线下方时,也做多;
当价格从上升趋势转为下降趋势时,即收盘价下穿开盘价时,平掉多头仓位;
使用长度为180周期的高点和EMA的交叉来判断价格下降趋势。当高点下穿EMA线且高点低于EMA线时,做空;
当价格从上升趋势转为下降趋势时,即收盘价下穿开盘价,并且EMA线上方时,也做空;
当价格从下降趋势转为上升趋势时,即收盘价上穿开盘价时,平掉空头仓位。
该策略结合趋势跟踪和均线指标,可以有效捕捉价格趋势的转折点,具有以下优势:
该策略也存在一定的风险:
对应风险的解决方案是:
该策略可以从以下几个方面进行优化:
该策略整体来说是一种典型的趋势跟踪策略,利用价格本身的特征指标判断方向并跟踪趋势。它简单有效,容易实现,适合作为量化交易的入门策略。但也存在一些问题,比如指标滞后、参数敏感性等。这些问题都是可以通过引入更多数据源、使用机器学习等方式得到改进。所以该策略有很大的拓展与优化空间,是一种值得推荐的高频量化交易策略。
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("Trend + EMA", overlay=true, initial_capital=10000, currency=currency.USD, pyramiding=0)
tim=input("180", title="Period for trend")
ema_period=input(180, title="EMA period")
opn = request.security(syminfo.tickerid, tim, open)
cls = request.security(syminfo.tickerid, tim, close)
emaline = ema(close, ema_period)
plot(opn, color=red)
plot(cls, color=green)
plot(emaline, color=black)
if (crossover(low, emaline))
strategy.entry("long", strategy.long)
if (crossover(cls, opn) and emaline < opn and strategy.position_size == 0)
strategy.entry("long", strategy.long)
if (crossunder(cls, opn) and strategy.position_size > 0)
strategy.close_all()
if (crossunder(high, emaline) and high < emaline)
strategy.entry("short", strategy.short)
if (crossunder(cls, opn) and emaline > opn and strategy.position_size == 0)
strategy.entry("short", strategy.short)
if (crossover(cls, opn) and strategy.position_size < 0)
strategy.close_all()