Files
strategies/EMA交叉系统策略EMA-Crossover-Strategy.md
T
2023-10-31 12:29:56 +08:00

9.0 KiB

Name

EMA交叉系统策略EMA-Crossover-Strategy

Author

ChaoZhang

Strategy Description

[trans]

概述

该策略基于ema移动平均线交叉原理构建交易系统,以实现 capturing 市场趋势带的自动交易。主要通过快速ema线和慢速ema线交叉来判断买入卖出信号。

策略原理

该策略主要基于两个移动平均线ema的交叉原理构建。一个是20周期的ema慢速线,一个是9周期的ema快速线。 当快速线ema9上穿慢速线ema20时生成买入信号,当快速线ema9下穿慢速线ema20时生成卖出信号。

具体来说,策略通过计算两个ema线的值,并比较大小关系来判断线间交叉。当ema9大于ema20时表示golden cross出现,设置布尔变量bullish为true,表明产生买入信号;当ema9小于ema20时表示dead cross出现,设置布尔变量bearish为true,表明产生卖出信号。

同时,策略还使用cross函数检测ema9和ema20的交叉。当发生向上交叉时,即ema9上穿ema20,也会设置bullish为true;当发生向下交叉时,即ema9下穿ema20,也会设置bearish为true。

这样通过双重判断可以避免漏报信号的发生。最后根据bullish和bearish的值,进入做多或做空的逻辑,完成自动交易系统。

优势分析

该策略具有以下优势:

  1. 使用EMA交叉原理,可以有效判断市场趋势转折点,捕捉趋势

  2. 快慢EMA线组合,可以发挥平滑趋势和捕捉转折的作用

  3. 采用金叉买入死叉卖出的经典策略,简单易懂

  4. 增加了交叉检测逻辑,可以避免漏单问题

  5. 自动交易系统,无需人工干预,回测效果较好

  6. 可自定义EMA周期参数,优化策略

风险分析

该策略也存在一些风险:

  1. EMA交叉对趋势判断有时效性,可能出现错过反转点的情况

  2. 存在whipsaw效应,短期调整可能触发错误信号

  3. 固定的EMA周期无法适应市场的变化

  4. 无法判断趋势的力度,可能在震荡行情中被套住

  5. 没有止损措施,亏损可能扩大

  6. 自动交易系统存在回测过拟合问题,实盘效果存疑

对应风险,可以从以下方面进行优化:

  1. 结合其他指标判断趋势确认,避免whipsaw

  2. 加入止损机制规避巨额亏损

  3. 增加参数优化,使EMA周期动态调整

  4. 加入趋势力度判别,避免震荡行情交易

  5. 进行复式化组合,提高稳定性

优化方向

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

  1. 动态EMA周期:现在使用固定的20周期和9周期,可以引入自适应机制,让EMA周期动态变化,更好跟踪市场趋势变化。

  2. 多时间框架验证:现在只在一个时间框架观察EMA交叉,可以引入多个不同周期组合进行验证,避免错报。

  3. 结合其他指标:可以引入如MACD,KD等其他指标,对EMA交叉信号进行过滤,提高准确性。

  4. 止损策略:现在没有止损措施,可以设置移动止损或固定止损点,控制单笔亏损。

  5. 参数优化:可以对EMA周期参数进行优化,找到最佳参数组合。也可以做步进优化,让参数动态调整。

  6. 复式组合:利用多个子策略组合,不同的参数设置,形成复式策略,可以提高稳定性。

  7. 机器学习:使用神经网络等机器学习技术,对交叉信号进行训练和识别,实现智能EMA交叉策略。

总结

该策略基于经典的EMA交叉原理构建自动交易系统。整体思路简单清晰,易于实现。但也存在使用效果的不稳定性。通过引入动态调整参数、多指标组合、止损方式、复式组合等方式进行优化,可以大幅提高策略的稳定性和实盘表现。EMA交叉策略值得进一步研究与应用。

||

Overview

This strategy builds a trading system based on the EMA crossover principle to automatically trade and capture market trends. It mainly uses the crossover of fast EMA and slow EMA to determine buy and sell signals.

Strategy Logic

This strategy is mainly built on the crossover principle of two moving averages, EMAs. One is the 20-period slow EMA, and the other is the 9-period fast EMA. When the fast EMA (EMA9) crosses above the slow EMA (EMA20), a buy signal is generated. When EMA9 crosses below EMA20, a sell signal is generated.

Specifically, the strategy calculates the values of two EMAs and compares their magnitude relationship to determine if a crossover happens. When EMA9 is greater than EMA20, it indicates a golden cross happens and the boolean variable bullish is set to true, meaning a buy signal is generated. When EMA9 is less than EMA20, it indicates a dead cross happens and the boolean variable bearish is set to true, meaning a sell signal is generated.

At the same time, the strategy also uses the cross function to detect crossovers between EMA9 and EMA20. When an upward crossover happens, i.e. EMA9 crosses above EMA20, bullish is also set to true. When a downward crossover happens, i.e. EMA9 crosses below EMA20, bearish is also set to true.

This dual validation helps avoid missing signals. Finally, the strategy enters long or short logic based on the values of bullish and bearish to complete the automated trading system.

Advantage Analysis

This strategy has the following advantages:

  1. Using EMA crossover principle effectively detects market trend reversal points and captures trends.

  2. The fast and slow EMA combo smoothes out trends and catches reversals.

  3. The classic golden cross to buy and dead cross to sell is simple and intuitive.

  4. Added crossover detection logic avoids missing signals.

  5. Fully automated system, no manual intervention needed, good backtest results.

  6. Customizable EMA periods allows optimizing the strategy.

Risk Analysis

This strategy also has some risks:

  1. EMA crossover trend detection can be late and miss reversal points.

  2. Whipsaw effect can trigger false signals on short-term corrections.

  3. Fixed EMA periods cannot adapt to market changes.

  4. Unable to gauge trend strength, may get whipsawed in ranging markets.

  5. No stop loss means losses could expand.

  6. Backtest overfitting of automated systems, questionable live performance.

To address the risks, optimizations can be made in:

  1. Add other indicators for trend confirmation to avoid whipsaws.

  2. Implement stop loss to limit downside.

  3. Introduce parameter optimization for dynamic EMA periods.

  4. Add trend strength determination to avoid ranging market trades.

  5. Utilize ensemble models to improve robustness.

Optimization Directions

This strategy can be optimized in several aspects:

  1. Dynamic EMA Periods: The fixed 20 and 9 periods can be made adaptive to better track evolving market trends.

  2. Multi Timeframe Validation: Currently only one timeframe, can verify signals on multiple timeframes to avoid false signals.

  3. Combine Other Indicators: Incorporate indicators like MACD, KD to filter crossover signals and improve accuracy.

  4. Stop Loss: Currently no stop loss, can add fixed or trailing stop loss to limit downside.

  5. Parameter Optimization: Optimize EMA periods to find best combinations. Or walk-forward optimize for dynamic parameters.

  6. Ensemble Models: Build ensemble of sub-strategies with different parameters for robustness.

  7. Machine Learning: Use neural networks to train and recognize crossovers for an intelligent system.

Conclusion

This strategy builds an automated system based on the classical EMA crossover principle. The overall logic is simple and clear. But stability issues exist. By introducing dynamic parameters, multi-indicator combos, stop losses, ensemble models etc., significant improvements can be made in live performance and robustness. EMA crossover strategies warrant further research and application.

[/trans]

Source (PineScript)

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

//For TRI'ers with a stinky trading view account.
//Some reccomended moving averages including the institutional moving averages.
//Much love to Brian for changing our lives.
//@version=4




strategy (title="Crossing Ema 20:9 by Sedkur", overlay=false)

src = close

ema20 = ema(src, 20)
ema9 = ema(src, 9)

plot( ema20, color=color.orange, style=plot.style_line, title="EMA20", linewidth=2)
plot( ema9, color=color.blue, style=plot.style_line, title="EMA9", linewidth=2)

//bullish = (ema9>ema20)?true:false
bullish = cross(ema9, ema20) and (ema9>ema20)?true:false
bearish = cross(ema9, ema20) and (ema20>ema9)?true:false
plotshape(bullish, style=shape.triangleup , location=location.belowbar, color=color.lime,size=size.tiny)
plotshape(bearish, style=shape.triangledown , location=location.abovebar, color=color.red,size=size.tiny)
alertcondition(bullish, title="Bullish", message="AL verdi")

if (bullish)
    strategy.entry("buy", strategy.long, comment="al", when = year>2016)
if (bearish)
    strategy.entry("sell", strategy.short, comment="sat", when = year>2016)
plot(strategy.equity)

Detail

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

Last Modified

2023-09-28 11:22:39