This strategy is an improved version of the MACD indicator-based trading strategy. It combines the trend-following characteristics of the MACD indicator with the ideas of momentum trading, generating trading signals by analyzing the differences between the fast and slow moving averages. Meanwhile, the strategy also introduces optimization methods such as trend confirmation, signal delay confirmation, fixed percentage stop-loss and take-profit, to improve the robustness and profitability of the strategy.
The core of this strategy is the MACD indicator, which consists of the difference between the fast moving average (EMA) and the slow moving average (EMA). When the fast EMA crosses the slow EMA, it generates a buy or sell signal. Specifically, when the MACD line breaks through the signal line from bottom to top, it generates a buy signal; when the MACD line falls below the signal line from top to bottom, it generates a sell signal.
In addition to the basic MACD crossover signals, the strategy also introduces a trend confirmation mechanism. It compares with the simple moving average (SMA) to determine whether the current market is in an uptrend or a downtrend. Only when a buy signal appears in an uptrend, or a sell signal appears in a downtrend, will the trading operation be executed. This effectively avoids false signals generated in a oscillating market.
Moreover, the strategy extends the signal confirmation time window. That is, only when the current candlestick satisfies the buying or selling conditions and the previous candlestick also satisfies the same conditions, the corresponding transaction will be executed. This further improves the reliability of the signals.
Finally, the strategy sets fixed percentage stop-loss and take-profit levels. Once a trade is carried out, the stop-loss and take-profit prices will be calculated based on the entry price, and the position will be automatically closed once these prices are reached. This helps to control the risk and return of a single transaction.
This strategy is an improved trading strategy based on the MACD indicator. Through trend confirmation, signal delay confirmation, fixed stop-loss and take-profit, and other methods, it improves the robustness and profit potential of the strategy. However, it also faces risks in parameter optimization, trend recognition, single indicators, backtesting data, and other aspects. In the future, we can consider optimizing the strategy from aspects such as combining other indicators, dynamic stop-loss and take-profit, position management, and machine learning to further improve its practical application effect.
/*backtest start: 2023-05-08 00:00:00 end: 2024-05-13 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © sligetit //@version=5 strategy("Improved MACD_VXI Strategy", overlay=true) // Calculate MACD and Signal Line fastLength = input.int(13, title="Fast Length") slowLength = input.int(21, title="Slow Length") signalLength = input.int(8, title="Signal Length") fastMA = ta.ema(close, fastLength) slowMA = ta.ema(close, slowLength) macd = fastMA - slowMA signal = ta.sma(macd, signalLength) // Plot MACD and Signal Line plot(macd, color=color.red, linewidth=1) plot(signal, color=color.blue, linewidth=2) // Calculate Cross Signals with Trend Confirmation smaPeriod = input.int(50, title="SMA Period") sma = ta.sma(close, smaPeriod) trendUp = close > sma trendDown = close < sma crossOver = ta.crossover(signal, macd) crossUnder = ta.crossunder(signal, macd) buySignal = crossOver and trendUp sellSignal = crossUnder and trendDown // Execute Buy/Sell Operations if buySignal strategy.entry("Buy", strategy.long) if sellSignal strategy.entry("Sell", strategy.short) // Extend Signal Confirmation Time Window longSignal = crossOver[1] and trendUp[1] shortSignal = crossUnder[1] and trendDown[1] if longSignal strategy.entry("Buy", strategy.long) if shortSignal strategy.entry("Sell", strategy.short) // Set Fixed Percentage Stop Loss and Take Profit stopLossPercent = input.float(1, title="Stop Loss (%)") / 100 takeProfitPercent = input.float(2, title="Take Profit (%)") / 100 stopLossPrice = strategy.position_avg_price * (1 - stopLossPercent) takeProfitPrice = strategy.position_avg_price * (1 + takeProfitPercent) strategy.exit("Stop Loss/Profit", "Buy", stop=stopLossPrice, limit=takeProfitPrice) strategy.exit("Stop Loss/Profit", "Sell", stop=stopLossPrice, limit=takeProfitPrice)