Strategy vault / Trend following
Four DEMA Multi Timeframe Trend Strategy
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…

Overview
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:
Calculate the 10-day, 15-day, 21-day and 30-day DEMA lines.
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.
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.
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.
Advantages
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.
Conclusion
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.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 10 | short |
| v_input_2_close | 0 | Source Dema 1: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_3 | 15 | long |
| v_input_4_close | 0 | Source Dema 2: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_5 | 21 | long2 |
| v_input_6_close | 0 | Source Dema 3: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_7 | 30 | long3 |
| v_input_8_close | 0 | Source Dema 4: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
Source Pine Script
/*backtest
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"}]
*/
//@version=3
//Author: HighProfit
//Lead-In
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)
//Conditions
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)Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-26. 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/Four-DEMA-Multi-Timeframe-Trend-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
- 200 EMA VWAP MFI Trend Following StrategyPine Script · Trend following · 1d
- 4 EMA Trend StrategyPine Script · Trend following · 1d
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m