0bps

Strategy vault / Trend following

Double HULL Moving Average Strategy

The Double HULL Moving Average Strategy is a trading strategy based on the HULL Moving Average (HMA) indicator created by Alan HULL. The strategy utilizes two HMA lines, a longer-term line and a shorter-term line, to…

Author
ChaoZhang
Complexity
Intermediate · 40 lines
Parameters
8
Backtest bar
15m · intraday
Tested on
BTC/USDT · futures

Strategy Overview:

The Double HULL Moving Average Strategy is a trading strategy based on the HULL Moving Average (HMA) indicator created by Alan HULL. The strategy utilizes two HMA lines, a longer-term line and a shorter-term line, to determine entry and exit points. The HMA is an improved moving average that reduces lag by applying weighted averaging to the price data. The crossover of the shorter-term and longer-term lines is used to generate buy and sell signals.

The calculation formula for the HMA is as follows:

HmaL = wma(2 * wma(close, round(PDL/2)) - wma(close, PDL), round(sqrt(PDL)))
HmaS = wma(2 * wma(close, round(PDS/2)) - wma(close, PDS), round(sqrt(PDS)))

Here, PDL represents the longer-term period, and PDS represents the shorter-term period. The strategy compares the values of the shorter-term and longer-term lines to determine the conditions for buying and selling.

Advantages:

  1. Reduced lag: The HMA has less lag compared to traditional moving averages, enabling it to respond faster to changes in price trends and provide more accurate signals for buying and selling.
  2. Simplicity: The strategy uses two moving average lines for crossover analysis, making it relatively simple to understand and implement.
  3. High customization: The strategy's period parameters can be adjusted based on specific markets and trading instruments, making it more adaptable to different market conditions.

Risks:

  1. Market volatility: During periods of market volatility, the moving average lines may cross frequently, resulting in frequent signals that can generate false signals and lead to excessive trading and losses.
  2. Slippage and latency: The execution of the strategy is subject to slippage and latency, especially in high-frequency trading, which can cause executed prices to deviate from expected prices and affect trading outcomes.
  3. Dependency on a single indicator: The strategy relies solely on the HMA indicator without incorporating other technical indicators or market intelligence, which may limit its ability to capture the full range of market changes and trends.

Conclusion:

The Double HULL Moving Average Strategy is a trading strategy based on the HULL Moving Average indicator. It utilizes the crossover of shorter-term and longer-term HMA lines to determine entry and exit points. The strategy offers advantages such as reduced lag, simplicity, and high customization. However, it also carries risks related to market volatility, slippage and latency, and reliance on a single indicator. In practical applications, the strategy can be adjusted and optimized based on specific circumstances, incorporating other technical indicators and risk management methods to enhance trading success and profitability.

Parameters

NameDefaultWhat it controls
v_input_121LongerPeriod
v_input_28ShorterPeriod
v_input_32019From Year
v_input_4trueFrom Month
v_input_5trueFrom Day
v_input_69999To Year
v_input_712To Month
v_input_831To Day

Source Pine Script

/*backtest
start: 2023-09-07 00:00:00
end: 2023-09-14 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Credit Indicator from KIVANC
// author and idea: KIVANC @fr3762 on twitter
// creator: Alan HULL
// 
strategy("Double HULL Moving Average Strategy", overlay=true)
PDL=input(title="LongerPeriod", defval=21, minval=1,maxval=500)
PDS=input(title="ShorterPeriod",  defval=8, minval=1,maxval=500)

// === INPUT BACKTEST RANGE ===
FromYear  = input(defval = 2019, title = "From Year", minval = 2009)
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
ToYear    = input(defval = 9999, title = "To Year", minval = 2009)
ToMonth   = input(defval = 12, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 31, title = "To Day", minval = 1, maxval = 31)

// === FUNCTION EXAMPLE ===
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => true // create function "within window of time"

HmaL=wma(2*wma(close,round(PDL/2))-wma(close,PDL),round(sqrt(PDL)))
HmaS=wma(2*wma(close,round(PDS/2))-wma(close,PDS),round(sqrt(PDS)))
plot(HmaL,color=red, linewidth=2)
plot(HmaS,color=blue, linewidth=2)

Buy = HmaS > HmaL
Sell = HmaS < HmaL

strategy.entry("Buy",true,when=window() and Buy)
strategy.close_all(when=window() and Sell)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-15. 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/Double-HULL-Moving-Average-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