Strategy vault / Trend following
Zero Lag Hull EMA Combo Trend Following Strategy
This strategy uses a combination of Zero Lag EMA and Hull EMA to implement trend following. Zero Lag EMA eliminates the lag of regular EMA, and Hull EMA smooths the price curve. Their combination can more accurately…
Overview
This strategy uses a combination of Zero Lag EMA and Hull EMA to implement trend following. Zero Lag EMA eliminates the lag of regular EMA, and Hull EMA smooths the price curve. Their combination can more accurately capture trend movements for low-risk trend following trading.
Strategy Logic
First calculate the Zero Lag EMA:
EMA1 = ema(close, Period) EMA2 = ema(EMA1, Period) Difference = EMA1 - EMA2 ZeroLagEMA = EMA1 + Difference
Where ZeroLagEMA is the Zero Lag EMA. It eliminates the lag problem of regular EMA.
Then calculate the Hull EMA smoothed curve:
```
n2ma = 2*wma(ZeroLagEMA, round(S_period/2))
nma = wma(ZeroLagEMA, S_period)
n1 = wma(n2ma - nma, sqn)
```
Finally, determine the trend direction based on the magnitude relationship between the current Hull EMA (n1) and the previous period's Hull EMA (n2), and formulate the trading strategy.
Advantage Analysis
The biggest advantage of this strategy is the ability to accurately capture trend directions. There are two reasons:
Zero Lag EMA eliminates the lag problem of regular EMA and can capture price changes faster.
Hull EMA doubles smoothes prices and filters out some noise to capture trends more clearly.
Compared to using EMA or Hull EMA alone, the combination leverages the strengths of both for a more accurate and reliable strategy.
Risk Analysis
The main risks of this strategy are:
Improper Period and S_period parameter settings may cause the strategy to be insensitive to the market and miss trading opportunities.
In ranging markets, EMA and Hull EMA may produce more false crossover signals that require caution.
It cannot effectively handle overnight price gaps.
Therefore, careful parameter testing is needed, indicator signals should be interpreted prudently, and price gap risks guarded against.
Optimization Directions
The strategy can be optimized in the following aspects:
Test parameter combinations under different markets and timeframes for better adaptability.
Add other indicators to filter false breakout signals, such as KDJ, MACD etc, to improve stability.
Add stop loss to control single trade loss.
Optimize entry timing to further improve win rate, e.g. avoiding trades against the trend.
Summary
This strategy uses the Zero Lag Hull EMA combo to accurately and sensitively capture market trends for low-risk trend following trading. Further improvements in stability can be achieved through parameter optimization, signal filtering, stop loss etc. Overall, the strategy is simple, practical and suitable for trending currency pairs and indices.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 30 | Period |
| v_input_2 | 176 | Smoother Period |
Source Pine Script
/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
// Zero Lag EMA combined with Hull moving average for smoothing purposes.
// author: email: [email protected]
strategy("Ujanja", overlay=true)
Period = input(title="Period",defval=30, minval=1)
S_period=input(title="Smoother Period",defval=176)
EMA1= ema(close,Period)
EMA2= ema(EMA1,Period)
Difference= EMA1 - EMA2
ZeroLagEMA= EMA1 + Difference
n2ma=2*wma(ZeroLagEMA,round(S_period/2))
nma=wma(ZeroLagEMA,S_period)
diff=n2ma-nma
sqn=round(sqrt(S_period))
n2ma1=2*wma(ZeroLagEMA[1],round(S_period/2))
nma1=wma(ZeroLagEMA[1],S_period)
diff1=n2ma1-nma1
sqn1=round(sqrt(S_period))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
c=n1>n2?green:red
ma=plot(n1,color=c)
longCondition = n1>n2
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = longCondition != true
if (shortCondition)
strategy.entry("Short", strategy.short)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/Zero-Lag-Hull-EMA-Combo-Trend-Following-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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Advanced Multi Indicator Multi Dimensional Trend Cross Quantitative StrategyPine Script · Trend following · 3h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Crossover EMA Short term Trading StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual EMA Crossover Oscillation Tracking StrategyPine Script · Trend following · 5m