The long-short moving average crossover trading strategy is a typical trend-following strategy. It uses the golden cross and death cross of the fast and slow moving averages to determine market trends and make corresponding long and short trades. When the fast moving average crosses above the slow moving average, it indicates an upward trend, so go long. When the fast moving average crosses below the slow moving average, it indicates a downward trend, so go short. This strategy works well for markets with strong mid- to long-term trends.
The core logic of the long-short MA strategy is based on the golden cross and death cross of moving averages. Moving averages can effectively filter out market noise and reflect trend direction. The fast MA reacts more quickly to price changes and captures short-term trends. The slow MA responds more slowly and tracks long-term trends.
When the fast MA crosses above the slow MA, it shows that the short-term trend has more upward momentum than the long-term trend, so go long. When the fast MA crosses below the slow MA, it indicates stronger downward momentum in the short-term trend, so go short.
Specifically, this strategy defines a fast MA (length 9) and a slow MA (length 21). It then uses ta.crossover
and ta.crossunder
to detect golden crosses and death crosses between them. It goes long on golden crosses and goes short on death crosses.
The long-short MA strategy has the following advantages:
The long-short MA strategy also has the following risks:
These risks can be reduced by optimizing MA parameters, adding filters, and setting stop losses.
The long-short MA strategy can be improved in the following aspects:
In summary, the long-short MA crossover strategy is a simple and practical trend following system. By combining fast and slow moving averages, it can effectively identify trend direction. But it also has some flaws. After optimizations and enhancements, it can become a core quantitative trading strategy.
/*backtest start: 2023-11-12 00:00:00 end: 2023-12-12 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("MA Strategy", overlay=true) // Input parameters fastLength = input(9, title="Fast MA Length") slowLength = input(21, title="Slow MA Length") // Calculate moving averages fastMA = ta.sma(close, fastLength) slowMA = ta.sma(close, slowLength) // Plot moving averages plot(fastMA, color=color.blue, title="Fast MA") plot(slowMA, color=color.red, title="Slow MA") // Strategy conditions longCondition = ta.crossover(fastMA, slowMA) shortCondition = ta.crossunder(fastMA, slowMA) // Strategy orders if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.entry("Short", strategy.short) // Plot entry signals plotshape(series=longCondition, title="Buy Signal", color=color.green, style=shape.triangleup, size=size.small) plotshape(series=shortCondition, title="Sell Signal", color=color.red, style=shape.triangledown, size=size.small)