Strategy vault / Trend following
Hull Moving Average Trend Following Strategy 427271
This strategy is based on the Hull Moving Average indicator invented by Alan Hull, belonging to trend following strategies. The Hull MA can reduce lag of moving averages and respond to price changes more swiftly. The…
Overview
This strategy is based on the Hull Moving Average indicator invented by Alan Hull, belonging to trend following strategies. The Hull MA can reduce lag of moving averages and respond to price changes more swiftly. The strategy uses Hull MA to determine trend direction and additional filters to generate trading signals.
Strategy Principle
Calculate short period and long period Hull MAs. Short period for specific trade direction, long period for overall trend.
When short period Hull MAs cross over, determine trend reversal. Filter with long period trend direction.
Add price breakout through Hull MA condition to ensure successful breakout.
Add price change rate filter to avoid undesirable breakout entry.
Set stop loss and take profit to control risk.
Advantage Analysis
Compared to simple moving averages, advantages of this strategy include:
Hull MA responds to price changes faster, able to capture trend turns timely.
Dual Hull MA structure can determine trends on both long and short timeframes.
Price breakout and change rate filters help avoid false breakouts.
Dynamic stop loss and take profit locks in profit and controls risk.
Risk Analysis
Risks of this strategy:
Improper parameter setting may miss price trend turns.
Wrong overall trend judgement may cause counter trend trades.
Stop loss set too wide may lead to large losses.
Too frequent trading increases transaction costs and slippage risks.
Optimization Directions
It can be optimized in the following aspects:
Optimize Hull MA periods to balance sensitivity and smoothness.
Optimize entry and exit parameters to find optimum values.
Test parameter robustness across different instruments to improve adaptability.
Incorporate volume to avoid divergence risks.
Add conditions to improve stability.
Summary
Overall, this strategy leverages the responsiveness of Hull MA to timely follow trends, and has strong profitability under risk control. But parameter optimization is needed, and some unavoidable systemic risks should be guarded against.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | HullMA Short |
| v_input_2 | 14 | HullMA Long |
| v_input_3 | 0.001 | Decision Threshold |
| v_input_4 | -50000 | Stop Loss in $ |
| v_input_5 | 100000 | Target Point in $ |
Source Pine Script
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-12 22:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//SeaSide420
strategy("SS420FX", overlay=true, default_qty_type=strategy.percent_of_equity, max_bars_back=720, default_qty_value=100, calc_on_order_fills= true, calc_on_every_tick=true, pyramiding=0)
q=input(title="HullMA Short",defval=14)
z=input(title="HullMA Long",defval=14)
dt = input(defval=0.0010, title="Decision Threshold", type=float, step=0.0001)
SL = input(defval=-50000.00, title="Stop Loss in $", type=float, step=1)
TP = input(defval=100000.00, title="Target Point in $", type=float, step=1)
ot=1
n2ma=2*wma(close,round(q/2))
nma=wma(close,q)
diff=n2ma-nma
sqn=round(sqrt(q))
n2ma1=2*wma(close[1],round(q/2))
nma1=wma(close[1], q)
diff1=n2ma1-nma1
sqn1=round(sqrt(q))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
z2ma=2*wma(close[11],round(z/2))
zma=wma(close[11],z)
ziff=n2ma-nma
zqn=round(sqrt(z))
z2ma1=2*wma(close[12],round(z/2))
zma1=wma(close[12], z)
ziff1=n2ma1-nma1
zqn1=round(sqrt(z))
z1=wma(diff,sqn)
z2=wma(diff1,sqn)
z1e=z1>z2?green:black
z2e=z1>z2?black:red
z3e=z1>z2?green:red
n1e=plot(z1, title="HMA1", color=z1e, linewidth=2, offset=2)
n2e=plot(z2, title="HMA2", color=z2e, linewidth=2, offset=2)
fill(n1e, n2e, color=z3e, transp=80)
confidence=(security(syminfo.tickerid, 'D', close)-security(syminfo.tickerid, 'D', close[1]))/security(syminfo.tickerid, 'D', close[1])
closelong = n1<n2 and close<n2 and confidence<dt or strategy.openprofit<SL or strategy.openprofit>TP
if (closelong)
strategy.close("Long")
closeshort = n1>n2 and close>n2 and confidence>dt or strategy.openprofit<SL or strategy.openprofit>TP
if (closeshort)
strategy.close("Short")
longCondition = n1>n2 and z1>z2 and strategy.opentrades<ot and confidence>dt and close>n1
if (longCondition)
strategy.entry("Long",strategy.long)
shortCondition = n1<n2 and z1<z2 and strategy.opentrades<ot and confidence<dt and close<n1
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/Hull-Moving-Average-Trend-Following-Strategy-427271.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
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- Adaptive FVG Detection and MA Trend Trading Strategy with Dynamic ResistancePine Script · Trend following · 1d
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- Adaptive Volatility Based Trend Following Short Strategy with Time Delay and Stop Loss ProtectionPine Script · Trend following · 2m