This strategy is based on the comparison of four EMA lines with different periods to implement trend-following trading. It goes long when the fast EMA line crosses above the medium EMA line, the medium EMA line crosses above the slow EMA line, and the slow EMA line crosses above the slowest EMA line. It goes short when the opposite crossing relationships happen. The strategy also incorporates date filter conditions, only trading within the specified date range.
The core logic of this strategy is based on the comparison of four EMA lines. The EMA lines can effectively smooth the price data and highlight the major trends. The fast EMA line reflects price change fastest, while the medium EMA has some lag, the slow EMA has more lag, and the slowest EMA has the most lag. When the fast EMA crosses above the medium EMA, the medium EMA crosses above the slow EMA, and the slow EMA crosses above the slowest EMA, it signals an uptrend, and the strategy will go long. When the opposite crossing sequence happens, it signals a downtrend and the strategy will go short.
The strategy also uses a date filter condition, only trading within the specified date range between 2018-06-01 and 2019-12-31. This avoids abnormal volatility outside this period affecting the strategy.
Specifically, the periods of the four EMA lines are 8, 13, 21, and 34 days respectively. They are relatively short-term to capture short-term and medium-term trends. The strategy will only generate trade signals when price data satisfy the EMA crossing relationships within the specified date range.
The advantages of this 4-EMA trend strategy are:
There are also some risks of this strategy:
To reduce the above risks, some optimization directions are:
The main optimization directions are:
Parameter Optimization: Adjust EMA periods to fit different cycles and products for better trend judgment.
Risk Control: Add reasonable stop loss like ATR or trend-based stop loss to control per trade and total risk.
Signal Filtering: Add other auxiliary indicators to avoid signals without a clear trend, e.g. RSI and MACD filters.
Profit Taking: Set proper profit taking rules to lock in profits and avoid retracements.
Automated Trading: Parameterize the strategy and integrate with auto-trading systems to expand applicability.
This is a simple and practical trend-following strategy based on 4-EMA line comparisons. It responds quickly and tracks short-term & medium-term trends effectively with good backtest results. We can optimize it by adjusting parameters, adding filters and stop losses to reduce risk and increase efficiency. Parameterization and automation are also important directions enabling wider applicability. In conclusion, the 4-EMA strategy is a robust and versatile quant trading strategy worthy of further research and optimization.
/*backtest start: 2022-12-19 00:00:00 end: 2023-12-25 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=3 strategy("4 EMA TREND Strategy ", overlay=true) length1 = input(8, minval=1) outFAST = ema(close,length1) plot(outFAST, color=green ,linewidth=3) length2 = input(13, minval=1) outM = ema(close, length2) plot(outM, color=yellow,linewidth=3) length3 = input(21, minval=1) outSLOW = ema(close, length3) plot(outSLOW, color=red,linewidth=3) length4 = input(34, minval=1) outSLOWEST = ema(close, length4) plot(outSLOWEST, color=black,linewidth=3) price = close yearfrom = input(2018) yearuntil =input(2019) monthfrom =input(6) monthuntil =input(12) dayfrom=input(1) dayuntil=input(31) if ( (outFAST>outM) and (outM > outSLOW) and(outSLOW>outSLOWEST)) strategy.entry("BUY", strategy.long, stop=close, oca_name="TREND", comment="BUY") else strategy.cancel(id="BUY") if ( (outFAST<outM) and (outM<outSLOW) and (outSLOW <outSLOWEST)) strategy.entry("SELL", strategy.short,stop=close, oca_name="TREND", comment="SELL") else strategy.cancel(id="SELL")