This strategy calculates moving averages of different periods, sets stop-loss and take-profit points to implement automated trading. It goes long when the short period moving average crosses above the long period moving average, and goes short when the short period moving average crosses below the long period moving average. Meanwhile, it sets stop-loss and take-profit points to control risks.
This strategy is based on the moving average crossover principle. It calculates both 9-day and 55-day simple moving averages simultaneously. When the 9-day MA crosses above the 55-day MA, it signals that the short-term trend has reversed to upside, so goes long. When the 9-day MA crosses below the 55-day MA, it signals that the short-term trend has reversed to downside, so goes short.
In the meantime, this strategy utilizes the ATR indicator to set stop-loss and take-profit points. The ATR indicator can measure the degree of price volatility in the market. The stop-loss point is set at the close price minus the ATR value, so it can set a reasonable stop-loss based on market volatility. The take-profit point uses a risk-reward ratio, which is set at 2 here - take profit = close price + 2 * ATR value.
This is a very simple and practical short-term trading strategy with the following advantages:
There are also some risks with this strategy:
These risks can be reduced by optimizing parameters, strict stop-loss, and reasonable position sizing.
This strategy can be further optimized:
The overall logic of this strategy is clear and easy to implement, especially suitable for beginners to master. As a basic short-term trading strategy, it has the advantages of simple operation and easy optimization. When combined with COMPLETE or other frameworks, it can be further enhanced to become a practical quantitative trading system.
/*backtest start: 2022-12-14 00:00:00 end: 2023-12-20 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("MA Crossover Strategy with Stop-Loss and Take-Profit", overlay=true) // Input for selecting the length of the moving averages maShortLength = input(9, title="Short MA Length") maLongLength = input(55, title="Long MA Length") // Input for setting the risk-reward ratio riskRewardRatio = input(2, title="Risk-Reward Ratio") // Calculate moving averages maShort = ta.sma(close, maShortLength) maLong = ta.sma(close, maLongLength) // Buy condition: 9-period MA crosses above 55-period MA buyCondition = ta.crossover(maShort, maLong) // Sell condition: 9-period MA crosses below 55-period MA sellCondition = ta.crossunder(maShort, maLong) // Set stop-loss and take-profit levels atrValue = ta.atr(14) stopLossLevel = close - atrValue // Use ATR for stop-loss (adjust as needed) takeProfitLevel = close + riskRewardRatio * atrValue // Risk-reward ratio of 1:2 // Execute buy and sell orders with stop-loss and take-profit strategy.entry("Buy", strategy.long, when = buyCondition) strategy.exit("Sell", from_entry="Buy", loss=stopLossLevel, profit=takeProfitLevel) // Plot moving averages on the chart plot(maShort, color=color.blue, title="Short MA") plot(maLong, color=color.red, title="Long MA")