The name of this strategy is “Trend Following with EMA”, which is a quantitative trading strategy based on trend following and exponential moving average (EMA) technical indicators. It combines trend tracking and EMA to identify the price trend of stocks or other financial products, and makes buy and sell decisions accordingly.
The main logic of this strategy is:
Use the crossover between the 180-period low and close price to determine the upward trend. When the low crosses above the close price, it indicates the price starts to rise and a trend is formed, a long position will be opened at this point;
When the price changes from a downward trend to an upward trend, that is, the close price crosses above the open price and the EMA line is below, a long position will also be opened;
When the price changes from an upward trend to a downward trend, that is, the close price crosses below the open price, the existing long position will be closed;
Use the crossover between the 180-period high and EMA to determine the downward trend. When the high crosses below the EMA and the high is lower than the EMA, a short position will be opened;
When the price changes from an upward trend to a downward trend, that is, the close price crosses below the open price and the EMA line is above, a short position will also be opened;
When the price changes from a downward trend to an upward trend, that is, the close price crosses above the open price, the existing short position will be closed.
This strategy combines trend following and moving average indicators, which can effectively capture the turning points of price trends. The advantages are:
This strategy also has some risks:
The solutions to the risks are:
The strategy can be optimized in the following aspects:
In general, this is a typical trend following strategy that uses the characteristics of price itself to determine direction and track trends. It is simple, effective, easy to implement, and suitable as a beginner quantitative trading strategy. However, there are some problems like indicator lag and parameter sensitivity. These issues can be improved by introducing more data sources and using machine learning. So there is great potential for expansion and optimization of this strategy. It is a recommended high-frequency quantitative trading strategy.
/*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()