Files
strategies/趋势追踪EMA策略EMA-Trend-Following-Strategy.md
T
2024-03-03 22:27:55 +08:00

7.8 KiB

Name

趋势追踪EMA策略EMA-Trend-Following-Strategy

Author

ChaoZhang

Strategy Description

IMG

[trans]

概述

趋势追踪EMA策略是一种基于EMA指标的趋势跟踪策略。该策略通过计算指定周期的EMA线,判断价格趋势方向,实现趋势追踪。当价格上穿EMA线时做空,当价格下穿EMA线时做多,属于典型的趋势跟踪策略。

策略原理

该策略主要基于EMA指标来判断价格趋势。EMA指标是一种对价格的指数平滑移动平均,它对最近的价格赋予更高的权重,能更快地响应价格变化。策略通过计算EMA周期内的平均价格, Produce 平滑的曲线。当价格从下方上穿EMA线时,表示价格开始上涨,属于看涨信号;当价格从上方下穿EMA线时,表示价格开始下跌,属于看跌信号。

根据这个原理,该策略在价格上穿EMA时做空,下穿EMA时做多,通过追踪EMA线来跟踪价格趋势的变化。具体来说,它在代码中计算了一个8周期的EMA线,在关闭价上穿EMA线时开仓做空,下穿EMA线时开仓做多。并且设置了止损点来控制风险。

策略优势

  • 趋势跟踪性强。EMA线能平滑价格波动,过滤市场噪音,跟踪中长线趋势。
  • 操作频率适中。相比短周期指标,EMA线调整频率适中,避免过于频繁交易。
  • 实现简单。该策略仅基于一个EMA指标就能实现趋势跟踪,非常简单直接。
  • 可扩展性强。可通过优化EMA参数或加入其他指标来丰富策略。

风险及解决方案

  • 可能发生错过Tuning point的风险。当价格快速反转时,EMA线需要一定时间来做调整,可能错过最佳入场时机。解决方法是结合其他指标判断Tuning point。

  • 存在增大亏损的风险。EMA线起到的是趋势跟踪作用,不能准确判断Tuning point。如果价格反转,可能造成较大亏损。解决方法是设置合理的止损位。

  • 交易频率可能过高或过低。EMA周期不同,producage 策略的交易频率也不同。周期过短可能导致过度交易,周期过长可能错过机会。解决方法是测试不同EMA参数,找到最佳周期。

优化建议

  • 优化EMA参数,找到最佳平衡点。可以通过步进优化来确定最佳的EMA周期数值。

  • 加入其他指标判断Tuning point。例如结合RSI等超买超卖指标,可以更好地判断价格拐点。

  • 优化止损策略,找到最佳止损点。通过回测可以测试不同的止损点,找到最大限度锁住利润的止损位置。

  • 优化品种选择。根据不同品种的特点,调整EMA周期参数,产生最佳效果。

总结

趋势跟踪EMA策略是一个非常典型的基于指标的趋势跟踪策略。它简单直接,容易实现,适合初学者学习。同时也具有可扩展性,可通过加入其他指标或优化参数来进一步提升策略效果。通过不断优化与改进,该策略可以成为一个非常实用的趋势跟踪工具。

||

Overview

The EMA trend following strategy is a trend tracking strategy based on the EMA indicator. It judges the trend direction by calculating the EMA line of a specified period and follows the trend. It goes short when the price crosses above the EMA line and goes long when the price crosses below the EMA line. This is a typical trend following strategy.

Strategy Logic

The core of this strategy is to determine the trend using the EMA indicator. EMA is an exponential moving average that gives more weight to recent prices and responds faster to price changes. By calculating the average price over an EMA period, it produces a smoothed curve. When the price crosses above the EMA line from below, it signals an upward trend; when the price crosses below the EMA line from above, it signals a downward trend.

Based on this logic, the strategy shorts when price breaks out above the EMA and goes long when the price breaks out below the EMA, tracking the trend by following the EMA line. Specifically, it calculates an 8-period EMA on the closing price - shorting when the close breaks out above EMA and going long when the close breaks out below EMA. It also sets a stop loss to control risks.

Advantages

  • Effective trend following. EMA smoothes price fluctuations, filters out market noise and follows medium to long term trends.

  • Reasonable trading frequency. Compared to shorter-period indicators, EMA has a medium adjustment frequency, avoiding over-trading.

  • Simple to implement. The strategy relies solely on one EMA indicator yet achieves the goal of trend following.

  • Extendibility. The strategy can be enhanced by optimizing EMA parameters or adding other indicators.

Risks and Solutions

  • Missing tuning points. When prices reverse rapidly, EMA needs time to adjust and may miss best entry points. Solution is to combine with indicators that identify tuning points.

  • Increased losses. EMA follows trends and cannot accurately determine tuning points. Reversals may lead to large losses. Solution is to set reasonable stop loss.

  • Frequency too high or too low. Different EMA periods lead to different trading frequencies. Too short may over-trade, too long may miss opportunities. Solution is to test different EMA periods to find the optimal.

Enhancement Suggestions

  • Optimize EMA parameters to find the best balance. Stepwise optimization can determine the optimal EMA period.

  • Add other indicators to determine tuning points. Combine with indicators like RSI to better detect reversals.

  • Optimize stop loss strategy to find the best stop loss level through backtesting.

  • Optimize symbol selection. Adjust EMA periods based on symbol characteristics to achieve best results.

Summary

The EMA trend following strategy is a very typical trend tracking strategy based on an indicator. It is simple and easy to implement, suitable for beginners to learn. Meanwhile, it has extendibility to further improve the strategy by adding indicators or optimizing parameters. With continuous improvements, it can become a very practical trend following tool.

[/trans]

Strategy Arguments

Argument Default Description
v_input_1_close 0 EMA Source: close
v_input_2 8 EMA Period
v_input_3 2018 Backtest Start Year
v_input_4 true Backtest Start Month
v_input_5 true Backtest Start Day
v_input_6 30 Stop loss percentage(0.1%)
v_input_7 true UseStopLoss

Source (PineScript)

/*backtest
start: 2022-10-09 00:00:00
end: 2023-10-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy(title = "EMA Close Strategy", shorttitle = "EMA Close",calc_on_order_fills=true,calc_on_every_tick =true, initial_capital=21000,commission_value=.25,overlay = true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

EmaSource   = input(defval = close, title = "EMA Source")
EmaLength   = input(defval = 8, title = "EMA Period", minval = 1)

StartYear = input(2018, "Backtest Start Year")
StartMonth = input(1, "Backtest Start Month")
StartDay = input(1, "Backtest Start Day")
stopLoss = input(30, title = "Stop loss percentage(0.1%)") 
UseStopLoss = input(true,"UseStopLoss")

window() => time >=  timestamp(StartYear, StartMonth, StartDay,00,00) ? true : false



EMA = ema(EmaSource,EmaLength)

plot(EMA, title = "EMA", color = green, linewidth = 2, style = line, transp = 50)

long = crossunder(EMA, close)
short= crossover(EMA, close)

if (long)
    strategy.entry("LongId", strategy.long, when=window())
    
if (short)
    strategy.entry("ShortId", strategy.short, when=window())

if (UseStopLoss)
    strategy.exit("StopLoss", "LongId", loss = close * stopLoss / 1000 / syminfo.mintick)
    strategy.exit("StopLoss", "ShortId", loss = close * stopLoss / 1000 / syminfo.mintick)

Detail

https://www.fmz.com/strategy/429384

Last Modified

2023-10-16 15:54:41