MACD DEMA Trading Strategy
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.
Overview
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.
Strategy Principle
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.
Advantage Analysis
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.
Risk Analysis
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.
Optimization Directions
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.
Summary
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.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 12 | MACD Fast Line Length |
| v_input_2 | 26 | MACD Slow Line Length |
| v_input_3 | 9 | Signal Line Length |
| v_input_4 | 2018 | yearfrom |
| v_input_5 | 2019 | yearuntil |
| v_input_6 | true | monthfrom |
| v_input_7 | 12 | monthuntil |
| v_input_8 | true | dayfrom |
| v_input_9 | 31 | dayuntil |
Source Pine Script
/*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")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-19. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/MACD-DEMA-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- KST EMA Momentum Trend Following StrategyPine Script · Momentum · 1d
- Multi Indicator Trend Momentum Trading Strategy with Dynamic Risk Management SystemPine Script · Momentum · 1h
- Multi Level Technical Indicator Momentum Trading Strategy Based on Enhanced MACD Volume Strength and EMA Signal SystemPine Script · Momentum · 1h
- Multi Momentum Indicator Trend Tracking Quantitative Trading StrategyPine Script · Momentum · 1d
- Multi Technical Indicator Based Trend Following and Momentum StrategyPine Script · Momentum · 1d
- Multi Trend Momentum Crossover Strategy with Volatility Optimization SystemPine Script · Momentum · 1d