This strategy is a trend-following strategy based on moving averages. It uses the crossover and crossunder of fast and slow moving averages to determine the trend direction for low-risk trend trading.
The strategy employs a fast moving average of period 9 and a slow moving average of period 21. When the fast MA crosses above the slow MA, it signals an uptrend in the market and a long position is taken. When the fast MA crosses below the slow MA, it signals a downtrend and any long position is closed.
Specifically, the strategy calculates the values of the fast and slow MAs and compares their relationship to determine the trend direction. In an uptrend, if the fast MA crosses above the slow MA, a long entry signal is triggered. In a downtrend, if the fast MA crosses below the slow MA, an exit signal is triggered to close the existing long position.
This way, the crossover and crossunder of the fast and slow MAs captures trend transitions for low-risk trend following trading.
Risks can be managed by tuning parameters, adding filters, stop loss/take profit.
As a simple trend following strategy, the core idea is to use fast and slow MAs to determine trend direction. The pros are simplicity, clear rules, and effective trend tracking. The cons are lag, false signals, and excessive trades. We can optimize it by adjusting parameters and adding other indicators to better adapt to market conditions. Overall, the dual MA strategy provides a simple and reliable approach to quantitative trading. With continuous improvements, its performance can become even better.
/*backtest start: 2023-09-01 00:00:00 end: 2023-09-20 23:59:59 period: 10m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Profitable Crypto Strategy", shorttitle="Profit Strategy", overlay=true) // Define strategy parameters fastLength = input.int(9, title="Fast MA Length", minval=1) slowLength = input.int(21, title="Slow MA Length", minval=1) stopLossPercent = input.float(1.0, title="Stop Loss %", step=0.1) takeProfitPercent = input.float(1.0, title="Take Profit %", step=0.1) // Calculate moving averages fastMA = ta.sma(close, fastLength) slowMA = ta.sma(close, slowLength) // Entry condition: Buy when fast MA crosses above slow MA longCondition = ta.crossover(fastMA, slowMA) // Exit condition: Sell when fast MA crosses below slow MA shortCondition = ta.crossunder(fastMA, slowMA) // Plot moving averages on the chart plot(fastMA, color=color.blue, title="Fast MA") plot(slowMA, color=color.orange, title="Slow MA") // Strategy entry and exit logic var stopLossPrice = 0.0 var takeProfitPrice = 0.0 if (longCondition) stopLossPrice := close * (1.0 - stopLossPercent / 100) takeProfitPrice := close * (1.0 + takeProfitPercent / 100) strategy.entry("Long", strategy.long) if (shortCondition) strategy.close("Long") // Set stop loss and take profit for open positions strategy.exit("Stop Loss/Profit", stop=stopLossPrice, limit=takeProfitPrice)