
The Simple Moving Average Crossover strategy is based on the crossover of two moving averages, a faster moving average (fast MA) and a slower moving average (slow MA). It goes long (buys) when the fast MA crosses above the slow MA, and closes the long position when the fast MA crosses below the slow MA.
The strategy uses two moving averages. One is a short-term fast MA that responds quickly to price changes. The other is a long-term slow MA that filters out short-term fluctuations and reflects long-term trends better. When the fast MA crosses above the slow MA, it signals an upward trend in the short-term and is considered a golden cross buy signal. When the fast MA crosses below the slow MA, it signals a short-term downward trend and is considered a death cross sell signal.
Risks can be controlled by setting stop loss. Choosing proper parameters can improve strategy performance.
In summary, the Simple Moving Average Crossover is a simple and practical trend following strategy. It identifies trend changes using the indicator properties of moving averages. The main advantages are easy implementation, understandability, and relatively small drawdowns. The main disadvantages are potential false signals, lagging nature. The strategy can be improved further through parameter optimization, stop loss setting, and combining with other indicators.
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Simple Moving Average Crossover", overlay=true)
// Input parameters
fastLength = input(10, title="Fast MA Length")
slowLength = input(30, title="Slow MA Length")
stopLossPercent = input(1, title="Stop Loss Percentage")
// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Buy condition: Fast MA crosses above Slow MA
buyCondition = ta.crossover(fastMA, slowMA)
// Sell condition: Fast MA crosses below Slow MA
sellCondition = ta.crossunder(fastMA, slowMA)
// Plot moving averages as lines
plot(fastMA, color=color.blue, title="Fast MA", linewidth=2)
plot(slowMA, color=color.red, title="Slow MA", linewidth=2)
// Execute trades based on conditions
if (buyCondition)
strategy.entry("Buy", strategy.long)
if (sellCondition)
strategy.close("Buy")
// Set stop loss level
stopLossLevel = close * (1 - stopLossPercent / 100)
strategy.exit("Sell", from_entry="Buy", loss=stopLossLevel)