Strategy vault / Trend following
Dual Moving Average Trading Strategy Based on Detrended Synthetic Price
This is a dual moving average trading strategy based on the Detrended Synthetic Price (DSP). DSP is a function that is in phase with the dominant cycle of real price data, obtained by subtracting a half-cycle EMA…
Overview
This is a dual moving average trading strategy based on the Detrended Synthetic Price (DSP). DSP is a function that is in phase with the dominant cycle of real price data, obtained by subtracting a half-cycle EMA from the quarter-cycle EMA. When DSP crosses above the upper band or below the lower band, unilateral trades are taken.
Strategy Logic
Calculate the 1/2-cycle HL average xHL2 of price.
Compute the 1/4-cycle EMA (xEMA1) and 1/2-cycle EMA (xEMA2) of xHL2 based on Length.
Obtain DSP by subtracting xEMA2 from xEMA1.
Set upper and lower band parameters, go long when DSP crosses above upper band, and go short when crossing below lower band.
The reverse parameter can switch between long and short direction.
Advantage Analysis
Advantages of this strategy:
DSP captures the dominant price cycle, avoiding misdirection from minor cycles.
The dual EMA design effectively tracks dominant cycle changes.
Simple upper/lower bands avoid over-trading.
Easily switch between long/short using reverse parameter, adaptable to different market environments.
No complex parameter optimization required, simple and practical.
Risk Analysis
Main risks:
Improper DSP cycle setting may miss the dominant cycle.
Band width needs optimization, otherwise over-trading may occur.
Fixed cycle design has poor adaptability to violent market changes.
Trading on DSP alone leaves strategy vulnerable to whipsaws.
Lack of stop loss may lead to significant losses.
Optimization Directions
Improvements:
Optimize parameters to find best cycle combination.
Add dynamic bands based on volatility.
Incorporate trend and volatility filters to reduce false signals.
Add stop loss or trailing stop mechanisms to control risk.
Test across multiple instruments for universality.
Introduce machine learning for adaptive DSP cycle optimization.
Summary
Overall this is a very simple and practical dual moving average trading strategy. It is built on solid cycle analysis foundations, with DSP effectively tracking the dominant cycle. With refinements in parameter optimization, stop losses, filter conditions and more, it can become a reliable quantitative trading strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Length |
| v_input_2 | 25 | SellBand |
| v_input_3 | -25 | BuyBand |
| v_input_4 | false | Trade reverse |
Source Pine Script
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-13 02:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 20/03/2017
// Detrended Synthetic Price is a function that is in phase with the
// dominant cycle of real price data. This DSP is computed by subtracting
// a half-cycle exponential moving average (EMA) from the quarter cycle
// exponential moving average.
// See "MESA and Trading Market Cycles" by John Ehlers pages 64 - 70.
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy(title="D_DSP (Detrended Synthetic Price)", shorttitle="D_DSP")
Length = input(14, minval=1)
SellBand = input(25)
BuyBand = input(-25)
reverse = input(false, title="Trade reverse")
hline(0, color=blue, linestyle=line)
hline(SellBand, color=red, linestyle=line)
hline(BuyBand, color=green, linestyle=line)
xHL2 = hl2
xEMA1 = ema(xHL2, Length)
xEMA2 = ema(xHL2, 2 * Length)
xEMA1_EMA2 = xEMA1 - xEMA2
pos = iff(xEMA1_EMA2 > SellBand, 1,
iff(xEMA1_EMA2 < BuyBand, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(xEMA1_EMA2, color=blue, title="D_DSP")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/Dual-Moving-Average-Trading-Strategy-Based-on-Detrended-Synthetic-Price.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