资源加载中... loading...

Merged Short Term and Long Term EMA Decision Strategy

Author: ChaoZhang, Date: 2024-01-05 16:07:58
Tags:

img

Overview

The main idea of this strategy is to use the crossovers between short-term EMA and long-term EMA as buy and sell signals. Specifically, when the short-term EMA crosses above the long-term EMA from below, a buy signal is generated. When the short-term EMA crosses below the long-term EMA from above, a sell signal is generated.

Strategy Principle

The strategy first defines the short-term EMA period as 3 days and the long-term EMA period as 30 days. Then it calculates the values of these two EMAs. The short-term EMA reflects recent price changes and the long-term EMA reflects long-term price trends. When the short-term EMA crosses above the long-term EMA, it indicates that recent prices have started to rise, outperforming the long-term trend. This is the signal to establish a long position. When the short-term EMA crosses below the long-term EMA, it indicates that recent prices have started to fall, underperforming the long-term trend. This is the timing to establish a short position.

Specifically, the strategy defines a difference to judge the crossover of EMAs. When the difference is greater than the threshold of 0.0005, a buy signal is generated. When it is less than the threshold of -0.0005, a sell signal is generated. The positivity and negativity of the difference represents that the short-term EMA is above or below the long-term EMA. Traders use this to determine the opening direction.

The strategy also marks triangle up and triangle down graphics on the candlestick chart to visually display buy and sell signals.

Advantage Analysis

The biggest advantage of this strategy is that it is simple and effective. It uses the most basic indicator EMA to judge market structure and avoids the risk of overfitting from overly complicated models.

As a trend tracking indicator, EMA can effectively smooth random noise and determine long and short term trend directions. Compared with other common indicators such as long and short term moving average crossovers, EMA has an exponential smoothing feature in its calculation that can respond to price changes more quickly.

In addition, by combining multiple EMA cycles, the crossover between long and short term EMAs can filter false breakouts to some extent compared to single EMA cycle strategies, making it more robust.

Risk Analysis

The biggest risk of this strategy lies in the lag of EMA itself. When there are rapid gaps or price reversals, EMA crossover signals often lag, failing to reflect market changes in time. This may lead to missing the best opening opportunities or failing to stop loss in time.

In addition, the choice of EMA periods also affects strategy performance. If the cycles are improperly selected, it will lead to too many false signals. For example, excessively short term cycles may cause oversensitivity to market noise, while excessively long term cycles cannot capture trend turns in time.

Finally, fixed incremental entry and exit thresholds can also lead to improper position control. Thresholds should be adjusted appropriately to control positions when volatility is high.

Optimization Directions

The strategy can be optimized in the following aspects:

  1. Dynamically optimize EMA cycles. Select or automatically optimize the best short and long term EMA combinations according to market conditions to improve strategy robustness.

  2. Introduce adaptive stop loss mechanism. Set reasonable moving stop-loss lines based on market volatility while ensuring effective stop loss.

  3. Combine with other indicators to filter signals. For example, position control indicators, volatility indicators, etc., to avoid significant losses caused by EMA crossover signals during high volatility.

  4. Introduce machine learning techniques. Train models to predict optimal EMA parameter combinations. Models can also be used to predict EMA differences to obtain more accurate trading signals.

Conclusion

In summary, this short-term and long-term EMA merged decision strategy is very simple and direct. By using the basic EMA indicator to determine bullish and bearish market structures, it avoids excessive optimization and model risks. Meanwhile, combining multiple EMA cycles also improves signal quality. However, we also need to pay attention to the lag risk EMA itself may bring, which needs subsequent proper optimization to solve.


/*backtest
start: 2023-12-05 00:00:00
end: 2024-01-04 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Merged EMA Strategy", shorttitle="MergedEMA", overlay=true)

// Define EMA periods
shortEMA = ta.ema(close, 3)
longEMA = ta.ema(close, 30)

// Plot EMAs on the chart
plot(shortEMA, color=color.blue, title="3 EMA")
plot(longEMA, color=color.red, title="30 EMA")

// Calculate the difference between short and long EMAs
emaDifference = shortEMA - longEMA

// Set threshold for buy and sell signals
buyThreshold = 0.0005
sellThreshold = -0.0005

// Define buy and sell conditions
buyCondition = emaDifference > buyThreshold
sellCondition = emaDifference < sellThreshold

// Plot buy and sell signals on the chart
plotshape(series=buyCondition, title="Buy Signal", color=color.green, style=shape.triangleup, location=location.belowbar)
plotshape(series=sellCondition, title="Sell Signal", color=color.red, style=shape.triangledown, location=location.abovebar)

// Strategy logic
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.close("Buy", when = sellCondition)

strategy.entry("Sell", strategy.short, when = sellCondition)
strategy.close("Sell", when = buyCondition)

More