The Dual Moving Average Trend Tracking Strategy is a quantitative trading strategy that uses two moving averages with different periods to determine the trend direction of the market. It uses the long/short status of fast and slow moving averages to identify the trend and make trades along the trend direction.
The strategy employs two moving averages, including a fast moving average (e.g. 10-period) and a slow moving average (e.g. 30-period). If both moving averages are pointing up, it indicates an uptrend. If both moving averages are pointing down, it indicates a downtrend.
Specifically, the strategy first calculates the fast and slow moving averages. Then it compares the current fast moving average with previous period to see if the current one is larger than the previous one. If yes, assign value 1 indicating up trend. Otherwise assign -1 for down trend. Do the same for the slow moving average.
Finally, determine the trend by the values of the two moving averages. If both values are 1, final decision is 1, indicating uptrend. If both are -1, final decision is -1, indicating downtrend. If the values are different, maintain previous trend decision.
Upon the identification of trend direction, the strategy will long at uptrend and short at downtrend.
The strategy has the following edges:
There are also some risks of the strategy:
To reduce the risks, parameters of moving averages can be set more reasonably, other indicators can be introduced, stop loss and take profit can be set, and position size can be adjusted accordingly.
The strategy can be further optimized in the following aspects:
The Dual Moving Average Trend Tracking Strategy has a clear logic of using dual moving averages to filter noise and identify trend, and trade along the trend direction. It’s a typical trend following strategy. Traders can choose long only or short only based on preference. There are still some risks of the strategy. Additional indicators, stop loss/take profit should be added to control risks. By doing so, long term steady profit can be achieved.
/*backtest start: 2022-12-12 00:00:00 end: 2023-12-18 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © noro // 2020 //@version=4 strategy(title = "Noro's TrendMA Strategy", shorttitle = "TrendMA str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0, commission_value = 0.1) //Settings needlong = input(true, title = "Long") needshort = input(true, title = "Short") fast = input(10, minval = 1, title = "MA Fast (red)") slow = input(30, minval = 2, title = "MA Slow (blue)") type = input(defval = "SMA", options = ["SMA", "EMA"], title = "MA Type") src = input(ohlc4, title = "MA Source") showma = input(true, title = "Show MAs") showbg = input(false, title = "Show Background") //MAs fastma = type == "EMA" ? ema(src, fast) : sma(src, fast) slowma = type == "EMA" ? ema(src, slow) : sma(src, slow) //Lines colorfast = showma ? color.red : na colorslow = showma ? color.blue : na plot(fastma, color = colorfast, title = "MA Fast") plot(slowma, color = colorslow, title = "MA Slow") //Trend trend1 = fastma > fastma[1] ? 1 : -1 trend2 = slowma > slowma[1] ? 1 : -1 trend = 0 trend := trend1 == 1 and trend2 == 1 ? 1 : trend1 == -1 and trend2 == -1 ? -1 : trend[1] //Backgrouns colbg = showbg == false ? na : trend == 1 ? color.lime : trend == -1 ? color.red : na bgcolor(colbg, transp = 80) //Trading if trend == 1 if needlong strategy.entry("Long", strategy.long) if needlong == false strategy.close_all() if trend == -1 if needshort strategy.entry("Short", strategy.short) if needshort == false strategy.close_all()