0bps

Strategy vault / Breakout

Zero Lag MACD DEMA Breakout Strategy

This strategy builds trading signals based on Toff's MACD DEMA indicator. The MACD DEMA indicator calculates the difference between DEMA fast line and DEMA slow line, with zero-lag processing, effectively eliminating…

Author
ChaoZhang
Complexity
Intermediate · 58 lines
Parameters
10
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

This strategy builds trading signals based on Toff's MACD DEMA indicator. The MACD DEMA indicator calculates the difference between DEMA fast line and DEMA slow line, with zero-lag processing, effectively eliminating the lagging issue of regular MACD.

The trading rules are: go long when zero-lag MACD crosses above 0 line, and go short when MACD crosses below 0 line. MACD 0-line crossovers are used to determine market sentiment.

The advantage of this zero-lag MACD strategy is it can capture trend changes more sensitively. Using DEMA instead of EMA also filters false breakouts. However, MACD itself has limited judging ability on complex price action, with some risk of false signals. Trend filters are needed to improve stability.

In summary, the zero-lag MACD DEMA breakout strategy works very well on strong trending moves, catching opportunities quickly. But it underperforms in range-bound periods, requiring cautious use. Only through continuous optimization and strict risk control can this strategy be applied successfully in the long run.

Parameters

NameDefaultWhat it controls
v_input_12000Backtest Start Year
v_input_2trueBacktest Start Month
v_input_3trueBacktest Start Day
v_input_42100Backtest Stop Year
v_input_512Backtest Stop Month
v_input_631Backtest Stop Day
v_input_712DEMA Courte
v_input_826DEMA Longue
v_input_99Signal
v_input_10trueLignes

Source Pine Script

/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy(title="Patron04 MACD DEMA Strategy",default_qty_type = strategy.percent_of_equity,default_qty_value = 3500, overlay=true)

testStartYear = input(2000, "Backtest Start Year") 
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2100, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false

sma = input(12,title='DEMA Courte')
lma = input(26,title='DEMA Longue')
tsp = input(9,title='Signal')
dolignes = input(true,title="Lignes")

MMEslowa = ema(close,lma)
MMEslowb = ema(MMEslowa,lma)
DEMAslow = ((2 * MMEslowa) - MMEslowb )

MMEfasta = ema(close,sma)
MMEfastb = ema(MMEfasta,sma)
DEMAfast = ((2 * MMEfasta) - MMEfastb)

LigneMACDZeroLag = (DEMAfast - DEMAslow)

MMEsignala = ema(LigneMACDZeroLag, tsp)
MMEsignalb = ema(MMEsignala, tsp)
Lignesignal = ((2 * MMEsignala) - MMEsignalb )

MACDZeroLag = (LigneMACDZeroLag - Lignesignal)

long = LigneMACDZeroLag > 0
short = LigneMACDZeroLag < 0

if testPeriod()

    strategy.entry("Long", strategy.long,when=long)
    strategy.entry("Short", strategy.short,when=short)





Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-11. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Zero-Lag-MACD-DEMA-Breakout-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open