Indicator · Pine Script v5 · Own pane

Hull Butterfly Oscillator [LuxAlgo]

by theonetrade· code credited to LuxAlgo

The Hull Butterfly Oscillator calculates a custom Hull Squeeze Oscillator by taking the difference between a Hull Moving Average calculation and an inverse weighting of historical prices.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code124
Settings7inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

124 lines of Pine Script v5 from assets/indicator/bit-exact/hull_butterfly_oscillator_luxalgo_xtuVIaa8.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

hull_butterfly_oscillator_luxalgo_xtuVIaa8.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=5
indicator("Hull Butterfly Oscillator [LuxAlgo]", "Hull Butterfly Oscillator [LuxAlgo]")
//-----------------------------------------------------------------------------}
//Settings
//----------------------------------------------------a-------------------------{
length = input(14)

mult = input(2., 'Levels Multiplier')

src = input(close)

//Style
bull_css_0 = input.color(color.new(#0cb51a, 50), 'Bullish Gradient'
  , inline = 'inline0'
  , group = 'Style')

bull_css_1 = input.color(#0cb51a, ''
  , inline = 'inline0'
  , group = 'Style')

bear_css_0 = input.color(color.new(#ff1100, 50), 'Bearish Gradient'
  , inline = 'inline1'
  , group = 'Style')

bear_css_1 = input.color(#ff1100, ''
  , inline = 'inline1'
  , group = 'Style')

//-----------------------------------------------------------------------------}
//Normalization variables
//-----------------------------------------------------------------------------{
var short_len = int(length / 2)
var hull_len = int(math.sqrt(length))

var den1 = short_len * (short_len + 1) / 2
var den2 = length * (length + 1) / 2
var den3 = hull_len * (hull_len + 1) / 2

//-----------------------------------------------------------------------------}
//Hull coefficients
//-----------------------------------------------------------------------------{
var lcwa_coeffs = array.new_float(hull_len, 0)
var hull_coeffs = array.new_float(0)

if barstate.isfirst
    //Linearly combined WMA coeffs
    for i = 0 to length-1
        sum1 = math.max(short_len - i, 0)
        sum2 = length - i
    
        array.unshift(lcwa_coeffs, 2 * (sum1 / den1) - (sum2 / den2))
    
    //Zero padding of linearly combined WMA coeffs
    for i = 0 to hull_len-2
        array.unshift(lcwa_coeffs, 0)
    
    //WMA convolution of linearly combined WMA coeffs
    for i = hull_len to array.size(lcwa_coeffs)-1
        sum3 = 0.
        for j = i-hull_len to i-1
            sum3 += array.get(lcwa_coeffs, j) * (i - j)
        
        array.unshift(hull_coeffs, sum3 / den3)

//-----------------------------------------------------------------------------}
//Hull squeeze oscillator
//-----------------------------------------------------------------------------{
var os  = 0
var len = array.size(hull_coeffs)-1
hma     = 0.
inv_hma = 0.

for i = 0 to len
    hma += src[i] * array.get(hull_coeffs, i)
    inv_hma += src[len-i] * array.get(hull_coeffs, i)
    
hso = hma - inv_hma

cmean = ta.cum(math.abs(hso)) / bar_index * mult

os := ta.cross(hso, cmean) or ta.cross(hso, -cmean) ? 0
  : hso < hso[1] and hso > cmean ? -1
  : hso > hso[1] and hso < -cmean ? 1
  : os

//-----------------------------------------------------------------------------}
//Plot
//-----------------------------------------------------------------------------{
//Colors
css0 = color.from_gradient(hso, 0, cmean, bull_css_0, bull_css_1)
css1 = color.from_gradient(hso, -cmean, 0, bear_css_1, bear_css_0)
css = hso > 0 ? css0 : css1

//Oscillator line/histogram
plot(hso, 'Hull Butterfly', css
  , style = plot.style_histogram)

plot(hso, 'Hull Butterfly', chart.fg_color)

//Dots
plot(os > os[1] and os == 1 ? hso : na, 'Bullish Dot'
  , bull_css_1
  , 2
  , plot.style_circles)
  
plot(os < os[1] and os == -1 ? hso : na, 'Bearish Dot'
  , bear_css_1
  , 2
  , plot.style_circles)


//Levels
plot(cmean, color = color.gray, editable = false)

plot(cmean / 2, color = color.gray, editable = false)

plot(-cmean / 2, color = color.gray, editable = false)

plot(-cmean, color = color.gray, editable = false)

//-----------------------------------------------------------------------------}

Overview

Hull Butterfly Oscillator [LuxAlgo] uses a cumulative absolute mean multiplied by a user-defined level multiplier to establish dynamic upper and lower thresholds. The indicator renders as a gradient-colored histogram and continuous line in a separate pane, alongside circle signal dots that highlight bullish and bearish state changes. Users can adjust the smoothing length, level multiplier, source series, and color styling.

Details

Published by

theonetrade on GitHub

Code credit

LuxAlgo, as written in the script's header

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
lengthint14length
Levels Multiplierinput2.mult
srcsourceclosesrc
Bullish Gradientcolorcolor.new(#0cb51a, 50)bull_css_0
bull_css_1color#0cb51abull_css_1
Bearish Gradientcolorcolor.new(#ff1100, 50)bear_css_0
bear_css_1color#ff1100bear_css_1
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

947 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 5 weeks ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
408 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

MACD

by Alorse
368 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 3 months ago · None stated GitHub repository of MACD

[TVT] OBV with EMA

by namuan
321 stars

Calculates On-Balance Volume (OBV) alongside two Exponential Moving Averages (EMAs) applied directly to the cumulative OBV line. The indicator tracks volume flow relative to price movement and smooths it using short-term and longer-term EMAs to highlight volum

Indicator v6 VolumeOscillators & momentum
Updated 8 days ago · MIT GitHub repository of [TVT] OBV with EMA
228 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 4 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

MACD-V

by harryguiacorn
220 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers