This strategy uses two moving averages (MAs) with different periods to generate trading signals. When the short-term MA crosses above the long-term MA from below, it generates a buy signal; when the short-term MA crosses below the long-term MA from above, it generates a sell signal. The main idea behind this strategy is to utilize the trend-tracking characteristics of MAs and capture trend changes through MA crossovers for trading purposes.
The dual moving average crossover strategy is a simple and easy-to-use trend-tracking strategy that captures trend changes through the crossover of two MAs with different periods. The strategy’s advantages are clear logic, explicit signals, and suitability for trending markets. However, in choppy markets, the strategy may generate more false signals and losing trades. Therefore, in practical applications, the strategy’s performance can be improved by adding trend filters, optimizing take profit and stop loss, dynamically optimizing parameters, and combining with other signals to enhance its adaptability and stability.
/*backtest start: 2023-05-22 00:00:00 end: 2024-05-27 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Combined Strategy", overlay=true) // Moving Averages Length Inputs short_length = input.int(20, "Short MA Length") long_length = input.int(50, "Long MA Length") // Moving Averages ma_short = ta.sma(close, short_length) ma_long = ta.sma(close, long_length) // Buy Condition (Moving Average Crossover) buy_condition = ta.crossover(ma_short, ma_long) plotshape(series=buy_condition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) // Sell Condition (Moving Average Crossover) sell_condition = ta.crossunder(ma_short, ma_long) plotshape(series=sell_condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small) // Strategy Entry and Exit if (buy_condition) strategy.entry("Buy", strategy.long) if (sell_condition) strategy.entry("Sell", strategy.short) // Debug statements if (buy_condition) label.new(x=bar_index, y=low, text="Buy Signal", color=color.green, style=label.style_label_up) if (sell_condition) label.new(x=bar_index, y=high, text="Sell Signal", color=color.red, style=label.style_label_down)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6