This strategy combines the MACD and DEMA dual-rail indicators to generate trading signals from crossovers. It captures turning points of the MACD indicator and uses DEMA for filtering to achieve better entries.
Calculate fast line DEMAfast as DEMA value of price with period length fastmacd.
Calculate slow line DEMAslow as DEMA value of price with period length slowmacd.
MACD Line is difference between fast and slow lines: DEMAfast - DEMAslow.
Signal line is DEMA value of MACD line with period signalmacd.
Crossovers between MACD and signal lines generate trade signals: long on golden cross, short on death cross.
Add date filters to only generate signals within specified date range.
The main advantages of this strategy are:
Combining MACD and DEMA complements the indicators. MACD captures turns, DEMA filters to improve signal quality.
DEMA dual rails design reduces lagging and noise of MACD indicator.
MACD crossover signals are easy to interpret, clean and simple.
Flexible setting of date filters caters to different strategy needs.
MACD parameters can be optimized for flexibility across market conditions.
Main risks of this strategy:
MACD struggles as trend following indicator in choppy sideways markets.
Crossovers may generate false signals, needs effective filtering.
Stop loss strategy not robust, prone to oversized stops.
Parameter optimization not comprehensive enough, big performance difference across products.
Date filters too rigid, needs dynamic adjustment.
Solutions:
Add momentum indicator to avoid sideways market.
Add price conditions to filter out false crosses.
Set reasonable initial and trailing stop loss.
Test parameters across products, dynamic optimization.
Adjust filter dates based on real-time conditions.
Some potential improvements for the strategy:
Add volume filter for crossover signals.
Optimize MACD parameter combinations across different products.
Add stop strategies like fixed or trailing stop loss.
Dynamically adjust stop loss based on market volatility.
Track trend strength for position sizing.
The MACD DEMA strategy combines the strengths of both indicators, using crossovers to capture trends. But MACD is inherently lagging, beware of false signals. Also optimize stops to avoid unreasonable liquidation. For live trading, cautious entry based on optimized parameters and continuous improvements are recommended.
/*backtest start: 2023-01-01 00:00:00 end: 2023-09-18 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy(" MACD DEMA STRATEGY ", overlay=true) source=close price=source fastmacd = input(12,title='MACD Fast Line Length') slowmacd = input(26,title='MACD Slow Line Length') signalmacd = input(9,title='Signal Line Length') macdslowline1 = ema(close,slowmacd) macdslowline2 = ema(macdslowline1,slowmacd) DEMAslow = ((2 * macdslowline1) - macdslowline2 ) macdfastline1 = ema(close,fastmacd) macdfastline2 = ema(macdfastline1,fastmacd) DEMAfast = ((2 * macdfastline1) - macdfastline2) MACDLine = (DEMAfast - DEMAslow) SignalLine1 = ema(MACDLine, signalmacd) SignalLine2 = ema(SignalLine1, signalmacd) SignalLine = ((2 * SignalLine1) - SignalLine2 ) MACDSignal = SignalLine-MACDLine colorbar= MACDSignal>0?green:red yearfrom = input(2018) yearuntil =input(2019) monthfrom =input(1) monthuntil =input(12) dayfrom=input(1) dayuntil=input(31) if ( crossover(MACDLine,SignalLine) ) strategy.entry("MMAL", strategy.long, stop=close, oca_name="TREND", comment="AL") else strategy.cancel(id="MMAL") if ( crossunder(MACDLine,SignalLine) ) strategy.entry("MMSAT", strategy.short,stop=close, oca_name="TREND", comment="SAT") else strategy.cancel(id="MMSAT")