0bps

Strategy vault / Trend following

Hull Moving Average Swing Trader

Hull Moving Average Strategy 2 X HMA's, 1st HMA on current price (recommended source OPEN) 2nd HMA on previous candle. signal on crossover. Buy and Sell signals on chart, red & green view pane (Green Buy, Red Sell)…

Pine ScriptTrend following
Author
ChaoZhang
Complexity
Intermediate · 75 lines
Parameters
8
Backtest bar
15m · intraday
Tested on
BTC/USDT · futures

Hull Moving Average Strategy 2 X HMA's, 1st HMA on current price (recommended source OPEN) 2nd HMA on previous candle. signal on crossover. Buy and Sell signals on chart, red & green view pane (Green Buy, Red Sell)

backtest

IMG

Parameters

NameDefaultWhat it controls
v_input_1210HullMA Period
v_input_2_open0Price data: open | high | low | close | hl2 | hlc3 | hlcc4 | ohlc4
v_input_3trueFrom Month
v_input_4trueFrom Day
v_input_52020From Year
v_input_6trueTo Month
v_input_7trueTo Day
v_input_89999To Year

Source Pine Script

/*backtest
start: 2022-04-25 00:00:00
end: 2022-05-24 23:59:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//                               Hull Moving Average Swing Trader by SEASIDE420
strategy("Hull Moving Average Swing Trader", shorttitle="HMA_Swing_Trader", default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=true, calc_on_every_tick=true, pyramiding=0)
hullperiod = input(title="HullMA Period", type=input.integer, defval=210, minval=1)
price = input(open, type=input.source, title="Price data")
FromMonth = input(defval=1, title="From Month", minval=1, maxval=12)
FromDay = input(defval=1, title="From Day", minval=1, maxval=31)
FromYear = input(defval=2020, title="From Year", minval=2017)
ToMonth = input(defval=1, title="To Month", minval=1, maxval=12)
ToDay = input(defval=1, title="To Day", minval=1, maxval=31)
ToYear = input(defval=9999, title="To Year", minval=2017)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() =>true
n2ma = 2 * wma(price, round(hullperiod / 2))
nma = wma(price, hullperiod)
diff = n2ma - nma
sqn = round(sqrt(hullperiod))
n2ma1 = 2 * wma(price[1], round(hullperiod / 2))
nma1 = wma(price[1], hullperiod)
diff1 = n2ma1 - nma1
n1 = wma(diff, sqn)
n2 = wma(diff1, sqn)
Hull_Line = n1 / n1 * n2
Hull_retracted = if n1 > n2
    Hull_retracted = Hull_Line - 2
else
    Hull_retracted = Hull_Line + 2
c1 = Hull_retracted + n1 - price
c2 = Hull_retracted - n2 + price
c4 = n1 > n2 ? color.green : color.red
c2p = plot(c2, color=color.black, linewidth=1)
c3p = plot(price, color=color.black, linewidth=1)
fill(c3p, c2p, color=c4, transp=75)
//plot(cross(c1, c2) ? c1 : na, style=plot.style_circles, color=c4, linewidth=4)
if price < c2
    strategy.close("BUY", when=window())
if price > c2
    strategy.close("SELL", when=window())
if price > c2 and price[1] > c1
    strategy.entry("BUY", strategy.long, when=window())
if price < c1 and price[1] < c2
    strategy.entry("SELL", strategy.short, when=window())  //        /L'-, 
//                               ,'-.      `   ````                 /  L '-, 
//     .                    _,--dMMMM\        `   ` ` '`..         /       '-, 
//     :             _,--,  )MMMMMMMMM),.      `     ,<>          /_      '-,' 
//     ;     ___,--. \MM(    `-'   )M//MM\          ,',.;      .-'* ;     .' 
//     |     \MMMMMM) \MM\       ,dM//MMM/     ___ < ,; `.      )`--'    / 
//     |      \MM()M   MMM)__   /MM(/MP'  ___, \  \ `  `. `.   /__,    ,' 
//     |       MMMM/   MMMMMM( /MMMMP'__, \     | /      `. `-,_\     / 
//     |       MM     /MMM---' `--'_ \     |-'  |/         `./ .\----.___ 
//     |      /MM'   `--' __,-  \""   |-'  |_,               `.__) . .F. )-. 
//     |     `--'       \   \    |-'  |_,     _,-/            J . . . J-'-. `-., 
//     |         __  \`. |   |   |         \    / _           |. . . . \   `-.  F 
//     |   ___  /  \  | `|   '      __  \   |  /-'            F . . . . \     '` 
//     |   \  \ \  /  |        __  /  \  |  |,-'        __,- J . . . . . \ 
//     |    | /  |/     __,-  \  ) \  /  |_,-     __,--'     |. .__.----,' 
//     |    |/    ___     \    |'.  |/      __,--'           `.-;;;;;;;;;\ 
//     |     ___  \  \     |   |  `   __,--'                  /;;;;;;;;;;;;. 
//     |     \  \  |-'\    '    __,--'                       /;;;;;;;;;;;;;;\ 
// \   |      | /  |      __,--'                             `--;;/     \;-'\ 
//  \  |      |/    __,--'                                   /  /         \  \ 
//   \ |      __,--'                                        /  /           \  \ 
//    \|__,--'                                          _,-;M-K,           ,;-;\ 
//                                                     <;;;;;;;;           '-;;;; 
//                                                                                  :D

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-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.

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/Hull-Moving-Average-Swing-Trader.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