Four DEMA Multi Timeframe Trend Strategy

Author: ChaoZhang, Date: 2024-02-26 14:14:48



The Four DEMA Multi Timeframe Trend Strategy is a trend-following strategy that uses 4 DEMA (Double Exponential Moving Average) lines of different periods to determine the trend direction across multiple timeframes. The strategy utilizes 10-day, 15-day, 21-day and 30-day DEMA lines to judge the price trend, filtering out false signals through multiple timeframe analysis to locate high-probability trend directions.

Strategy Logic

The strategy calculates the 10-day, 15-day, 21-day and 30-day DEMA lines and compares their magnitude relations to determine the market trend direction. The specific rules are:

  1. Calculate the 10-day, 15-day, 21-day and 30-day DEMA lines.

  2. When 10-day line crosses above 15-day line, 15-day line crosses above 21-day line, and 21-day line crosses above 30-day line, it is determined as an uptrend forming, go long.

  3. When 30-day line crosses below 21-day line, 21-day line crosses below 15-day line, and 15-day line crosses below 10-day line, it is determined as a downtrend forming, go short.

  4. Take profit or stop loss to exit.

By judging through multiple timeframes, this strategy can filter out some noise and lock in higher probability trend directions. Also, longer period DEMA lines have better filtering effect, so the strategy uses the 10-day, 15-day, 21-day and 30-day lines to construct the logic.


  • Multi timeframe design filters noise through longer timeframe DEMAs and catches high probability trends.

  • Utilizes the better trend following characteristic of DEMA indicator.

  • Simple and clear rules, easy to understand and implement, suitable for quant trading.

Risks and Solutions

  • Long stop loss or short stop loss risk. Use moving stop loss to control single position stop loss.

  • Relatively long drawdowns. Adjust position sizing to lower single position risk.

  • Limited optimization space for parameters. Add auxiliary signals to assist judgement.

Enhancement Space

  • Add stop loss strategy to further control risks.

  • Optimize DEMA period parameters. Add more auxiliary signals.

  • Combine with trend indicators to lower reversal probabilities.


The Four DEMA Multi Timeframe Trend Strategy determines the price trend direction by comparing the magnitude relations of 10-day, 15-day, 21-day and 30-day DEMA lines. It belongs to a typical trend following strategy. Compared to single MA lines, this strategy adopts multiple timeframe judgement to effectively filter some noise and improves accuracy. Also, the strategy rules are simple and clear, easy to understand and implement, suitable for quant trading. In conclusion, this strategy utilizes the advantages of DEMA indicator and designs multiple timeframe logic to capture high-probability precise trends, worth recommending.

start: 2023-02-19 00:00:00
end: 2024-02-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

//Author: HighProfit

strategy("dema10-15-21-30", shorttitle="4dema", overlay=true)

short = input(10, minval=1)
srcShort = input(close, title="Source Dema 1")

long = input(15, minval=1)
srcLong = input(close, title="Source Dema 2")

long2 = input(21, minval=1)
srcLong2 = input(close, title="Source Dema 3")

long3 = input(30, minval=1)
srcLong3 = input(close, title="Source Dema 4")

e1 = ema(srcShort, short)
e2 = ema(e1, short)
dema1 = 2 * e1 - e2
plot(dema1, color=green, linewidth = 2)

e3 = ema(srcLong, long)
e4 = ema(e3, long)
dema2 = 2 * e3 - e4
plot(dema2, color=blue, linewidth = 2)

e5 = ema(srcLong2, long2)
e6 = ema(e5, long2)
dema3 = 2 * e5 - e6
plot(dema3, color=black, linewidth = 2)

e7 = ema(srcLong3, long3)
e8 = ema(e7, long3)
dema4 = 2 * e7 - e8
plot(dema4, color=red, linewidth = 2)

longCondition = (dema1>dema2) and (dema1>dema3) and (dema1>dema4) and (dema2>dema3) and (dema2>dema4) and (dema3>dema4)

if (longCondition)

    strategy.entry("Long", strategy.long)

strategy.close("Long",  cross(dema1,dema2))

shortCondition = (dema4>dema3) and (dema4>dema2) and (dema4>dema1) and (dema3>dema2) and (dema3>dema1) and (dema2>dema1)
if (shortCondition)
    strategy.entry("Short", strategy.short)
strategy.close("Short", cross(dema1,dema2))

bgcolor(longCondition?green:white , transp=70, offset=1)
bgcolor(shortCondition?red:white , transp=70, offset=1)