Tags: MACDEMADIFDEA

This strategy uses the crossover of the DIF line and DEA line in the MACD indicator to generate trading signals. When the DIF line crosses above the DEA line, it generates a long signal; when the DIF line crosses below the DEA line, it generates a short signal. The backtesting results of this strategy show that on the BTCUSDT trading pair, the win rate is about 40%, and the annualized return is 1.05. However, it will cause the number of assets held to increase continuously, so it cannot be used as an independent arbitrage strategy.

- Calculate the fast exponential moving average (EMA) and slow exponential moving average (EMA).
- Calculate the DIF line, which is the difference between the fast EMA and the slow EMA.
- Calculate the DEA line, which is the EMA of the DIF line.
- Calculate the MACD histogram, which is the difference between the DIF line and the DEA line.
- When the DIF line crosses above the DEA line, generate a long signal and open a long position.
- When the DIF line crosses below the DEA line, generate a short signal, close the long position, and open a short position.
- When the opposite crossover signal appears again, close the current position and open a position in the opposite direction.

- This strategy uses the widely used MACD indicator, which is easy to understand and implement.
- The strategy logic is clear, and the trading signals are explicit.
- It is suitable for trending markets and can track the main trends of the market.

- The win rate of this strategy is low, only 40%, which means that 60% of the trades may be losing.
- This strategy will cause the number of assets held to increase continuously, which may bring additional risk exposure.
- In a fluctuating market, this strategy may generate frequent trading signals, leading to high trading costs.
- This strategy does not consider risk management, such as stop-loss and position management, which may lead to significant losses.

- Introduce trend filters, such as long-term moving averages, to avoid trading in fluctuating markets.
- Optimize the parameters of the MACD indicator, such as the period of the fast EMA, slow EMA, and signal line, to adapt to different market conditions.
- Add risk management measures, such as stop-loss and position management, to control potential losses.
- Combine with other technical indicators or fundamental analysis to improve the reliability of trading signals.

The MACD golden cross and death cross strategy is a simple and easy-to-understand trading strategy that is suitable for trending markets. However, the win rate of this strategy is low, and it lacks risk management measures, so it needs further optimization and improvement. By introducing trend filters, optimizing parameters, adding risk management, and combining with other analysis methods, the performance and reliability of this strategy can be improved. Nevertheless, this strategy still cannot be used as an independent arbitrage strategy and needs to be combined with other strategies to obtain better trading results.

/*backtest start: 2024-03-01 00:00:00 end: 2024-03-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // @version=5 // @description 该策略使用 MACD DIF 线与 EDA 线产生金叉与死叉时进行入场与出场操作, 回测后发现胜率约 40%, BTCUSDT 年化利率 1.05, 同时会导致持有的资产数量不断上升, 无法作为一个独立的套利策略进行使用. strategy("MACD 金叉策略", overlay=true) fastLength = input(12, "快线长度") slowLength = input(26, "慢线长度") MACDLength = input(9, "MACD 均线长度") deltaIncreaseOver0 = input(color.green,'MACD 柱在 0 线以上增长') deltaIncreaseUnder0 = input(color.rgb(153, 230, 156),'MACD 柱在 0 线以下增长') deltaDecreaseOver0 = input(color.orange,'MACD 柱在 0 线以上下跌') deltaDecreaseUnder0 = input(color.red,'MACD 柱在 0 线以下下跌') buySellEnabled = input(true, '是否显示入场与出场信号') // @variable 做多轮数 var longRound = 0 // @variable 做空轮数 var shortRound = 0 DIF = ta.ema(close, fastLength) - ta.ema(close, slowLength) // 快慢均线差值 EDA = ta.ema(DIF, MACDLength) // DIF 线的 EMA 均线 delta = DIF - EDA // MACD 柱高度 // plot(0, 'Zero', color.black) plot(DIF,'DIF', color.yellow) plot(EDA, "EDA", color.purple) isDeltaIncreasing = delta[1] < delta isDeltaOver0 = delta > 0 deltaColor = isDeltaIncreasing ? (isDeltaOver0? deltaIncreaseOver0: deltaIncreaseUnder0) :( isDeltaOver0? deltaDecreaseOver0: deltaDecreaseUnder0) plot(delta, "Delta", deltaColor, style = plot.style_columns) isDeltaV = delta > delta[1] and delta[2] > delta[1] isDeltaA = delta < delta[1] and delta[2] < delta[1] longBuy(round) => entry = str.format("做多买入 {0}",round) // log.info(str.format("{0} {1}",entry,close)) strategy.entry(entry, strategy.long, comment=entry) longSell(round) => entry = str.format("做多买入 {0}",round) exit = str.format("做多卖出 {0}",round) // log.info(str.format("{0} {1}",exit,close)) strategy.close(entry, comment=exit) shortSell(round) => entry = str.format("做空卖出 {0}",round) // log.info(str.format("{0} {1}",entry,close)) strategy.entry(entry, strategy.short, comment= entry) shortBuy(round) => entry = str.format("做空卖出 {0}",round) exit = str.format("做空买入 {0}",round) // log.info(str.format("{0} {1}",exit,close)) strategy.close(entry, comment=exit) if (buySellEnabled) if (ta.crossunder(DIF, EDA)) longSell(longRound) if (ta.crossover(DIF, EDA)) longRound := longRound + 1 longBuy(longRound)

- Trading Strategy Based on Consecutive MACD Golden and Death Crosses
- Sentiment Oscillator
- Schaff Trend Cycle
- Triple EMA + MACD
- EMA, MACD, and RSI Triple Indicator Momentum Strategy
- BONK Multi-Factor Trading Strategy
- ZeroLag MACD Long Short Strategy
- AK MACD BB INDICATOR V 1.00
- Zero Lag MACD Dual Crossover Trading Strategy - High-Frequency Trading Based on Short-Term Trend Capture
- CM MACD Custom Indicator - Multiple Time Frame - V2

- Stochastic Crossover Indicator Momentum Trading Strategy
- RSI and Dual EMA Crossover Signal Quantitative Strategy
- Elliott Wave Theory 4-9 Impulse Wave Automatic Detection Trading Strategy
- Stochastic Oscillator and Moving Average Crossover Strategy with Stop Loss and Stochastic Filter
- Intraday Scalable Volatility Trading Strategy
- KRK aDa Stochastic Slow Mean Reversion Strategy with AI Enhancements
- Real-time Trendline Trading Based on Pivot Points and Slope
- EMA23/EMA50 Double Moving Average Crossover Quantitative Trading Strategy
- Trend-Capturing Strategy with Horizontal Line Breakout
- Moving Average Crossover with Multiple Take Profits Strategy
- MACD-V and Fibonacci Multi-Timeframe Dynamic Take Profit Strategy
- Trend Catcher Strategy
- Quantitative Trading Strategy Based on Moving Averages and Bollinger Bands
- Bollinger Bands Breakout Strategy
- Dual Timeframe Momentum Strategy
- MACD BB Breakout Strategy
- Wavetrend Large Amplitude Oversold Rebound Grid Trading Strategy
- MACD Crossover Strategy
- Optimized MACD Trend-Following Strategy with ATR-based Risk Management
- ZeroLag MACD Long Short Strategy