The moving average crossover strategy is a quantitative trading strategy based on technical indicators. It judges the trend direction of the market by calculating the crossover relationship between two moving average lines, and generates corresponding trading signals.
The core indicators of this strategy are two moving average lines: a longer 40-period simple moving average (SMA) and the closing price of the stock. When the closing price breaks through the 40-period SMA from below, it indicates that the market trend may reverse and the stock may enter a new uptrend. At this point, the strategy will generate a long signal. When the closing price falls below the 40-period SMA, it indicates that the uptrend of the stock has ended and it may enter a downtrend channel. The strategy will close long positions at this time.
By comparing the breakthrough relationship between closing price and SMA, the turning points of the price trend can be captured to make trading decisions according to the trend direction.
The strategy has the following advantages:
There are also the following risks:
Risks can be controlled by adjusting SMA parameters, setting stop loss lines, etc.
The strategy can also be optimized in the following aspects:
The moving average crossover strategy judges trend reversal by comparing price changes with the SMA relationship. It is a relatively classic rule-based trading strategy. The strategy is simple to implement, easy to follow mid-to-long term trends for profit, while there are also certain risks of profit retracement and lagging identification. Risks can be controlled and decision effectiveness improved by parameter settings and incorporating other indicators.
/*backtest start: 2023-11-04 00:00:00 end: 2023-12-04 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy(title="MA Crossover (40)", overlay=true) // Input for the SMA length (24) sma_length = input(40, title="SMA Length") sma = ta.sma(close, sma_length) // Determine if the current candle crosses above the 24-period SMA longCondition = ta.crossover(close, sma) // Determine if the current candle crosses and closes below the 24-period SMA closeLongCondition = ta.crossunder(close, sma) // Plot the 24-period SMA plot(sma, color=color.blue, title="24-period SMA") // Long entry signal if (longCondition) strategy.entry("Long", strategy.long) // Close long position when the current candle crosses and closes below the 24-period SMA if (closeLongCondition) strategy.close("Long") // Create alerts alertcondition(longCondition, title="Candle Crosses Above SMA 40", message="Candle has crossed above SMA 40.") alertcondition(longCondition, title="Candle Closes Above SMA 40", message="Candle has closed above SMA 40.")