Skip to content

Hull Suite

by MeMyselfAndI · 0 in use · published 3 months ago

Loading Hull Suite on BTC-USDT 1h…

Source

sha256 2149001a94748daf

1// Hull Suite by InSilico — VP Script port.
2
3indicator('Hull Suite by InSilico — VP', {
4 shortTitle: 'Hull Suite — VP',
5 pane: 'overlay',
6})
7
8const sourceName = input.string('Source', 'close', {
9 options: ['open', 'high', 'low', 'close', 'hl2', 'hlc3', 'ohlc4'],
10})
11const mode = input.string('Hull Variation', 'Hma', { options: ['Hma', 'Thma', 'Ehma'] })
12const length = input.int('Length', 55, { min: 1, max: 1000 })
13const lengthMult = input.float('Length multiplier', 1, { min: 0.1, max: 20 })
14const useHtf = input.bool('Show Hull MA from higher timeframe', false)
15const htf = input.string('Higher timeframe', '240', {
16 options: ['1', '5', '15', '30', '60', '120', '240', '1D', '1W'],
17})
18const switchColor = input.bool('Color Hull according to trend', true)
19const candleColor = input.bool('Color candles based on Hull trend', false)
20const showBand = input.bool('Show as a band', true)
21const thickness = input.int('Line thickness', 1, { min: 1, max: 8 })
22const bandTransparency = input.int('Band transparency', 40, { min: 0, max: 100 })
23
24const pickSource = (ctx, name) => {
25 if (name === 'open') return ctx.open
26 if (name === 'high') return ctx.high
27 if (name === 'low') return ctx.low
28 if (name === 'hl2') return ctx.hl2
29 if (name === 'hlc3') return ctx.hlc3
30 if (name === 'ohlc4') return ctx.ohlc4
31 return ctx.close
32}
33
34const hma = (src, len) => {
35 const half = Math.max(1, Math.round(len / 2))
36 const root = Math.max(1, Math.round(Math.sqrt(len)))
37 return ta.wma(math.sub(math.mul(ta.wma(src, half), 2), ta.wma(src, len)), root)
38}
39
40const ehma = (src, len) => {
41 const half = Math.max(1, Math.round(len / 2))
42 const root = Math.max(1, Math.round(Math.sqrt(len)))
43 return ta.ema(math.sub(math.mul(ta.ema(src, half), 2), ta.ema(src, len)), root)
44}
45
46const thma = (src, len) => {
47 const third = Math.max(1, Math.round(len / 3))
48 const half = Math.max(1, Math.round(len / 2))
49 const inner = math.sub(math.sub(math.mul(ta.wma(src, third), 3), ta.wma(src, half)), ta.wma(src, len))
50 return ta.wma(inner, len)
51}
52
53const calculateHull = (src, len) => {
54 if (mode === 'Ehma') return ehma(src, len)
55 if (mode === 'Thma') return thma(src, Math.max(1, Math.round(len / 2)))
56 return hma(src, len)
57}
58
59const effectiveLength = Math.max(1, Math.round(length * lengthMult))
60const localContext = { open, high, low, close, hl2, hlc3, ohlc4 }
61const localHull = calculateHull(pickSource(localContext, sourceName), effectiveLength)
62const hull = useHtf
63 ? request.security('', htf, (f) => calculateHull(pickSource(f, sourceName), effectiveLength))
64 : localHull
65const slowHull = math.shift(hull, 2)
66
67const bandHull = showBand ? slowHull : new Array(barCount).fill(null)
68const hullColors = new Array(barCount).fill(null)
69const bandColors = new Array(barCount).fill(null)
70const candleColors = new Array(barCount).fill(null)
71
72for (let i = 0; i < barCount; i++) {
73 const current = hull[i]
74 const slow = slowHull[i]
75 if (current === null || slow === null) continue
76 const color = !switchColor ? '#ff9800' : current > slow ? '#00ff00' : '#ff0000'
77 hullColors[i] = color
78 bandColors[i] = color
79 if (candleColor && switchColor) candleColors[i] = color
80}
81
82const alpha = Math.round((100 - bandTransparency) * 2.55).toString(16).padStart(2, '0')
83const fillColors = bandColors.map((color) => color === null ? null : color + alpha)
84const mainPlot = plot(hull, { title: 'Hull', color: hullColors, width: thickness })
85const bandPlot = plot(bandHull, { title: 'Hull band', color: bandColors, width: thickness })
86fill(mainPlot, bandPlot, { color: fillColors })
87
88if (candleColor && switchColor) barcolor(candleColors)
89
90alertcondition(ta.crossover(hull, slowHull), {
91 title: 'Hull trending up',
92 message: 'Hull trending up.',
93})
94alertcondition(ta.crossover(slowHull, hull), {
95 title: 'Hull trending down',
96 message: 'Hull trending down.',
97})
98

Versions

  • v1current2149001a3 months ago

This indicator runs in an isolated sandbox: it cannot reach your account, your data or the network, and if it stops responding it is stopped for you. That does not make it correct — nobody has checked whether it is any good, which is why its source is above.