Hull Suite
by MeMyselfAndI · 0 in use · published 3 months ago
Source
sha256 2149001a94748daf
1// Hull Suite by InSilico — VP Script port.23indicator('Hull Suite by InSilico — VP', {4 shortTitle: 'Hull Suite — VP',5 pane: 'overlay',6})78const 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 })2324const pickSource = (ctx, name) => {25 if (name === 'open') return ctx.open26 if (name === 'high') return ctx.high27 if (name === 'low') return ctx.low28 if (name === 'hl2') return ctx.hl229 if (name === 'hlc3') return ctx.hlc330 if (name === 'ohlc4') return ctx.ohlc431 return ctx.close32}3334const 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}3940const 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}4546const 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}5253const 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}5859const 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 = useHtf63 ? request.security('', htf, (f) => calculateHull(pickSource(f, sourceName), effectiveLength))64 : localHull65const slowHull = math.shift(hull, 2)6667const 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)7172for (let i = 0; i < barCount; i++) {73 const current = hull[i]74 const slow = slowHull[i]75 if (current === null || slow === null) continue76 const color = !switchColor ? '#ff9800' : current > slow ? '#00ff00' : '#ff0000'77 hullColors[i] = color78 bandColors[i] = color79 if (candleColor && switchColor) candleColors[i] = color80}8182const 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 })8788if (candleColor && switchColor) barcolor(candleColors)8990alertcondition(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})98Versions
- 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.