This strategy is a quantitative trading system based on MACD and multiple-period EMA indicators. It combines the trend-following characteristics of MACD with the support and resistance features of multiple EMA lines to create a complete trading decision system. The system includes not only signal generation but also real-time alerts to help traders capture market opportunities timely.
The core logic is built on two main technical indicators. First is the MACD indicator, composed of fast line (12 periods) and slow line (26 periods), generating trading signals through their crossovers. Buy signals are generated when the MACD line crosses above the signal line, and sell signals when it crosses below. Second, the strategy incorporates five different period EMAs (10/20/50/100/200) as references for trend confirmation and support/resistance levels. This multi-period EMA design helps traders better understand the current market trend environment.
This strategy constructs a relatively complete trading system by combining MACD and multi-period EMA indicators. Its strengths lie in clear signals, rich analytical dimensions, and good visualization. However, it also has inherent risks such as lag and false signals. Through optimization measures like adding volatility filtering and volume confirmation, the strategy’s stability and reliability can be further enhanced. This strategy is suitable for medium to long-term traders, particularly excelling in clear trend market environments.
/*backtest start: 2024-10-01 00:00:00 end: 2024-10-31 23:59:59 period: 1h basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("REEL TIME MACD Strategy with Alerts and EMAs", overlay=true) // --- Custom Indicator: MACD --- fastLength = input(12, title="MACD Fast Length") slowLength = input(26, title="MACD Slow Length") signalSmoothing = input(9, title="MACD Signal Smoothing") src = close [macdLine, signalLine, _] = ta.macd(src, fastLength, slowLength, signalSmoothing) histogram = macdLine - signalLine // Plot MACD components plot(macdLine, color=color.blue, linewidth=2, title="MACD Line") plot(signalLine, color=color.orange, linewidth=2, title="Signal Line") plot(histogram, style=plot.style_histogram, color=(histogram >= 0 ? color.green : color.red), title="Histogram") // --- Custom Indicator: EMAs --- ema10 = ta.ema(src, 10) ema20 = ta.ema(src, 20) ema50 = ta.ema(src, 50) ema100 = ta.ema(src, 100) ema200 = ta.ema(src, 200) // Plot EMAs on the chart plot(ema10, color=color.green, linewidth=1, title="EMA 10") plot(ema20, color=color.blue, linewidth=1, title="EMA 20") plot(ema50, color=color.purple, linewidth=1, title="EMA 50") plot(ema100, color=color.orange, linewidth=1, title="EMA 100") plot(ema200, color=color.red, linewidth=1, title="EMA 200") // --- Strategy: Buy and Sell conditions (MACD) --- buyCondition = ta.crossover(macdLine, signalLine) // Buy when MACD crosses above signal line sellCondition = ta.crossunder(macdLine, signalLine) // Sell when MACD crosses below signal line // Execute strategy based on buy/sell conditions if (buyCondition) strategy.entry("Buy", strategy.long) if (sellCondition) strategy.close("Buy") // --- Alerts --- alertcondition(buyCondition, title="MACD Buy Alert", message="MACD XUP - Buy") alertcondition(sellCondition, title="MACD Sell Alert", message="MACD XDN - Sell") // Optional: Visualization for Buy/Sell signals plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY") plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")