Indicator · Pine Script v6 · Own pane

Williams Gator Oscillator

by mihakralj

This indicator calculates the Williams Gator Oscillator derived from Bill Williams Alligator lines and plots dual histograms in a separate pane.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code103
Settings7inputs
LicenceMIT
Last update8 months ago28 Feb 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

103 lines of Pine Script v6 from indicators/oscillators/gator.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

gator.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Williams Gator Oscillator", "GATOR", overlay=false)

//@function Calculates Williams Gator Oscillator from Alligator lines
//@param source Series to calculate from
//@param jawPeriod Period for Jaw SMMA (typically 13)
//@param jawOffset Forward offset for Jaw line (typically 8)
//@param teethPeriod Period for Teeth SMMA (typically 8)
//@param teethOffset Forward offset for Teeth line (typically 5)
//@param lipsPeriod Period for Lips SMMA (typically 5)
//@param lipsOffset Forward offset for Lips line (typically 3)
//@returns Tuple [upper, lower] histogram values
//@optimized Uses Wilder's RMA (SMMA) with exponential warmup compensator for O(1) complexity
gator(series float source, simple int jawPeriod, simple int jawOffset, simple int teethPeriod, simple int teethOffset, simple int lipsPeriod, simple int lipsOffset) =>
    if jawPeriod <= 0 or teethPeriod <= 0 or lipsPeriod <= 0
        runtime.error("All periods must be greater than 0")
    if jawOffset < 0 or teethOffset < 0 or lipsOffset < 0
        runtime.error("All offsets must be non-negative")

    // Step 1: Compute SMMA (Wilder's RMA) for each Alligator line
    float alphaJaw = 1.0 / float(jawPeriod)
    float alphaTeeth = 1.0 / float(teethPeriod)
    float alphaLips = 1.0 / float(lipsPeriod)

    var bool warmupJaw = true
    var bool warmupTeeth = true
    var bool warmupLips = true
    var float eJaw = 1.0
    var float eTeeth = 1.0
    var float eLips = 1.0
    var float emaJaw = 0.0
    var float emaTeeth = 0.0
    var float emaLips = 0.0
    var float jaw = source
    var float teeth = source
    var float lips = source

    emaJaw := alphaJaw * (source - emaJaw) + emaJaw
    emaTeeth := alphaTeeth * (source - emaTeeth) + emaTeeth
    emaLips := alphaLips * (source - emaLips) + emaLips

    if warmupJaw
        eJaw *= (1.0 - alphaJaw)
        float cJaw = 1.0 / (1.0 - eJaw)
        jaw := cJaw * emaJaw
        warmupJaw := eJaw > 1e-10
    else
        jaw := emaJaw

    if warmupTeeth
        eTeeth *= (1.0 - alphaTeeth)
        float cTeeth = 1.0 / (1.0 - eTeeth)
        teeth := cTeeth * emaTeeth
        warmupTeeth := eTeeth > 1e-10
    else
        teeth := emaTeeth

    if warmupLips
        eLips *= (1.0 - alphaLips)
        float cLips = 1.0 / (1.0 - eLips)
        lips := cLips * emaLips
        warmupLips := eLips > 1e-10
    else
        lips := emaLips

    // Step 2: Apply offsets and compute histogram differences
    float jawShifted = jaw[jawOffset]
    float teethShifted = teeth[teethOffset]
    float lipsShifted = lips[lipsOffset]

    // Upper histogram: abs(Jaw - Teeth), always positive
    float upper = math.abs(jawShifted - teethShifted)
    // Lower histogram: -abs(Teeth - Lips), always negative
    float lower = -math.abs(teethShifted - lipsShifted)

    [upper, lower]

// ---------- Main loop ----------

// Inputs
i_source = input.source(hlc3, "Source")
i_jawPeriod = input.int(13, "Jaw Period", minval=1)
i_jawOffset = input.int(8, "Jaw Offset", minval=0)
i_teethPeriod = input.int(8, "Teeth Period", minval=1)
i_teethOffset = input.int(5, "Teeth Offset", minval=0)
i_lipsPeriod = input.int(5, "Lips Period", minval=1)
i_lipsOffset = input.int(3, "Lips Offset", minval=0)

// Calculation
[upper, lower] = gator(i_source, i_jawPeriod, i_jawOffset, i_teethPeriod, i_teethOffset, i_lipsPeriod, i_lipsOffset)
float prevUpper = upper[1]
float prevLower = lower[1]

// Colors: green when expanding (upper rising or lower falling), red when contracting
color upperColor = upper >= prevUpper ? color.green : color.red
color lowerColor = lower <= prevLower ? color.green : color.red

// Plot
plot(upper, "Upper", color=upperColor, style=plot.style_histogram, linewidth=2)
plot(lower, "Lower", color=lowerColor, style=plot.style_histogram, linewidth=2)
plot(0, "Zero", color=color.gray, linewidth=1)

Overview

The upper histogram displays the absolute difference between the Jaw and Teeth moving averages, while the lower histogram displays the negative absolute difference between the Teeth and Lips. Bars reflect expansion and contraction cycles based on changes relative to previous bars. Configurable settings adjust the source price, smoothing periods, and forward bar offsets for each moving average line. It provides visual oscillator bars without automated entry, exit, or risk management rules.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages, Trend

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

pinescriptpinescript-indicatorstechnical-analysistradingview-indicators

Settings

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

SettingTypeDefaultVariable
Sourcesourcehlc3i_source
Jaw Periodint13i_jawPeriod
Jaw Offsetint8i_jawOffset
Teeth Periodint8i_teethPeriod
Teeth Offsetint5i_teethOffset
Lips Periodint5i_lipsPeriod
Lips Offsetint3i_lipsOffset
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

Beep Boop

by magic8bot
409 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
218 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 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Elder Impulse System

by mihakralj
99 stars

Elder Impulse System plots a column series in a separate pane. It compares a 13-period exponential moving average with its previous value and a MACD histogram with its previous value. A rising EMA and rising histogram print 1, a falling EMA and falling histogr

Indicator v5 TrendOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Elder Impulse System
43 stars

This indicator plots the percentage difference between a fast exponential moving average and a slow one, scaled by the close, in a separate pane. It treats that gap as a standardized measure of trend strength and draws a zero line. Users set both EMA lengths a

Indicator v5 Moving averagesOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Standardized MA Difference

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers