The Dual Moving Average Crossover is a simple and effective scalping strategy that uses crossover signals between price and moving averages as entry and exit signals to capture short-term trend movements.
The strategy employs two moving averages of different periods - a shorter-term MA line and a longer-term MA line. It generates buy signals when the shorter period MA crosses above the longer period MA from below. Sell signals are generated when the shorter MA crosses below the longer MA from above.
The strategy first defines the variable ‘length’ to specify the period of the longer MA line as 50. It then defines ‘price’ as the closing price and calculates the MA value of length 50 and stores it in the ‘ma’ variable. It further defines ‘bcond’ to check if price is above ma value. If yes, ‘bcount’ is incremented by 1, otherwise reset to 0. When ‘bcond’ triggers ‘confirmBars’ times consecutively (default 2), a buy signal is generated. Sell signals are generated similarly when price falls below ma.
To filter out some invalid signals, additional filters like ‘clc’, ‘clc0’ and ‘clc1’ are added which check the price relationship between the current and previous bars. Trade signals are generated only when these conditions are met.
Finally, existing positions are closed out when price crosses the MA lines in reverse.
The risks can be mitigated by using dynamic MA periods based on volatility, trailing stops or percentage stops, etc.
The strategy can be improved in several ways:
Optimize MA parameters dynamically based on volatility.
Add extra filters like volume spike to improve signal quality.
Use floating or percentage stops to reduce premature stop outs.
Combine with other indicators like MACD, RSI for multicondition validation.
Add automated risk management like dynamic position sizing to control loss per trade.
Use machine learning for more accurate signal generation model.
The dual MA crossover strategy is an effective system for short-term trading. Fine tuning parameters, managing risks and combining with other tools can further enhance its profitability. Overall it is simple to understand and implement for scalping smaller intraday moves.
/*backtest start: 2023-09-29 00:00:00 end: 2023-10-29 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy("MovingAvg Cross", overlay=true) length = input(50) confirmBars = input(2) price = close ma = sma(price, length) bcond = price > ma bcount = 0 bcount := bcond ? nz(bcount[1]) + 1 : 0 clc=close[0]>close[1] clc0=close[0]>open[0] clc1=close[1]>open[1] if clc and clc0 and clc1 and (bcount == confirmBars) strategy.entry("buy", strategy.long) scond = price < ma scount = 0 scount := scond ? nz(scount[1]) + 1 : 0 csc=close[0]<close[1] csc0=close[0]<open[0] csc1=close[1]<open[1] if csc and csc0 and csc1 and (scount == confirmBars) strategy.entry("sell", strategy.short) strategy.close("buy", when=scond) strategy.close("sell",when=bcond) plot(ma, color=color.red) //plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)