Indicator · Pine Script v5 · Own pane

CSW Ø-Lag Oscillator

by g-moe· code credited to goodgains

The CSW Ø-Lag Oscillator is a modified MACD indicator designed to reduce lag using zero-lag moving averages and a custom leader calculation.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code107
Settings14inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

107 lines of Pine Script v5 from Tradingview/csw-lag-oscillator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

csw-lag-oscillator.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains

//@version=5
indicator(title='CSW Ø-Lag Oscillator')

// @keywords: zero-lag-macd, csw-lag-oscillator, zlema, macd-histogram, signal-line, lagging-line, convergence-divergence-line, trend-direction, bullish-divergence, bearish-divergence, pivot-low, pivot-high, oscillator-columns, divergence-labels, divergence-alerts, fast-length, slow-length, signal-length, zero-line, instructions-label

//--INSTRUCTIONS--//
instructions_tooltip = "• The Ø-Lag Oscillator is a modified & enhanced MACD. The indicator applies zero-lagging algorithms 
 \nin order to speed up the traditional MACD indicator. The Ø-Lag Oscillator also plots 3 colors. Green if the trend is up. 
 \nRed if the Trend is down. And yellow if the Ø-Lag and traditional MACD do not agree with each other."

instructions = input.bool(title='Show Instructions', defval=false, inline='1', tooltip = instructions_tooltip)
if barstate.islast and instructions
    var label instruction_label = na
    if not na(instruction_label[1])
        label.delete(instruction_label[1])
    instruction_label := label.new(bar_index + 5, close, instructions_tooltip, xloc = xloc.bar_index , yloc = yloc.price, color = color.black , style = label.style_label_left, textcolor = color.white, size = size.large, textalign = text.align_left) 
//--INSTRUCTIONS--//
color_up = input.color(#27a69b, title='Bull Color', inline='2', group='Visual Settings')
color_down = input.color(#b63632, title='Bear Color', inline='2', group='Visual Settings')
color_mismatch = input.color(color.yellow, title='Directional Change Color', inline='2', group='Visual Settings')
color_lagging = input.color(color.new(color.white, 85), title='Lagging Line Color', inline='3', group='Visual Settings')
color_con_div = input.color(color.new(color.white, 85), title='Convergence/Divergence Line Color', inline='3', group='Visual Settings')

fastLength = input.int(12, minval=1, title='Fast Length:', inline='3', group='Indicator Settings')
slowLength = input.int(26, minval=1, title='Slow Length:', inline='3', group='Indicator Settings')
signalLength = input.int(9, minval=1, title='Signal Length:', inline='3', group='Indicator Settings', tooltip  = "These are the default Settings are 12,26,9. For Faster Signals Decrease. For Slower Signals Increase")

src = close
calc_zlema(src, length) =>
    ema1 = ta.ema(src, length)
    ema2 = ta.ema(ema1, length)
    d = ema1 - ema2
    ema1 + d

ma(src, length) =>
    calc_zlema(src, length)
calc_leader(src, shortLength, longLength) =>
    sema = ma(src, shortLength)
    lema = ma(src, longLength)
    i1 = sema + ma(src - sema, shortLength)
    i2 = lema + ma(src - lema, longLength)
    i1 - i2

fastMA = ma(src, fastLength)
slowMA = ma(src, slowLength)
macd = fastMA - slowMA

sig = ta.sma(macd, signalLength)
hist = macd - sig
zerolag = calc_leader(src, fastLength, slowLength)

column_color = hist >= 0 and zerolag >= 0 ? color_up : hist >= 0 and zerolag < 0 or hist < 0 and zerolag >= 0 ? color_mismatch : color_down
highs3 = plot(zerolag, color=color.new(color.black, 0), linewidth=5, editable=false)
lows3 = plot(zerolag, color=color.new(color.black, 0), linewidth=5, editable=false)
leader = plot(zerolag, style=plot.style_line, linewidth=2, color=color.new(column_color, 0), title='Ø-Lag Line')
signal = plot(sig, title='Lagging Line', color=color_lagging)
histogram = plot(hist, style=plot.style_columns, linewidth=2, color=color.new(column_color, 20), title='MACD Oscillator')
zero = plot(0, linewidth=2, color=color.new(color.white, 30), editable=false)
macdline = plot(macd, title='Convergence/Divergence Line', color=color_con_div)

//DIVERGENCE
show_DIV = input.bool(title='Show Divergence', defval=true, inline='5', group='Divergence Settings')
lbR = input.int(title=' - Adjuster:', defval=5, inline='5', group='Divergence Settings', tooltip  = "Set the length over which a swing point in the market is calculated.")
lbL = lbR
rangeUpper = 50
rangeLower = 20
bullColor = input.color(#27a69b, 'Bull Divergence Color', inline='8', group='Divergence Settings')
bearColor = input.color(#b63632, 'Bear Divergence Color', inline='8', group='Divergence Settings')
textColor = input.color(color.white, 'Text Color', inline='8', group='Divergence Settings')
noneColor = color.new(color.white, 100)
osc = zerolag

plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = show_DIV and priceLL and oscHL and plFound
alertcondition(bullCond, 'Bullish Divergence', 'Bullish Divergence')

plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=3, color=bullCond ? bullColor : noneColor, editable=false)

plotshape(bullCond ? osc[lbR] : na, offset=-lbR, title='Regular Bullish Label', text=' ∇ ', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, editable=false)

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCond = show_DIV and priceHH and oscLH and phFound
alertcondition(bearCond, 'Bearish Divergence', 'Bearish Divergence')

plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=3, color=bearCond ? bearColor : noneColor, editable=false)
plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title='Regular Bearish Label', text=' ∇ ', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, editable=false)

Overview

CSW Ø-Lag Oscillator plots a zero-lag line, a lagging signal line, and a histogram in a separate pane. The oscillator uses three distinct color states: green when zero-lag and MACD agree on an uptrend, red for a downtrend, and yellow when directional signals mismatch. It also supports regular divergence detection based on pivot points.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages, Divergence

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.

Settings

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

SettingTypeDefaultVariable
Show Instructionsboolfalseinstructions
Bull Colorcolor#27a69bcolor_up
Bear Colorcolor#b63632color_down
Directional Change Colorcolorcolor.yellowcolor_mismatch
Lagging Line Colorcolorcolor.new(color.white, 85)color_lagging
Convergence/Divergence Line Colorcolorcolor.new(color.white, 85)color_con_div
Fast Length:int12fastLength
Slow Length:int26slowLength
Signal Length:int9signalLength
Show Divergencebooltrueshow_DIV
- Adjuster:int5lbR
Bull Divergence Colorcolor#27a69bbullColor
Show all 14 settings
SettingTypeDefaultVariable
Bear Divergence Colorcolor#b63632bearColor
Text Colorcolorcolor.whitetextColor
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

330 stars

This separate-pane indicator plots a MACD line, a signal line, and a histogram whose colors show whether the histogram is rising or falling above or below zero. The oscillator and signal can each use an SMA or an EMA, and an optional marker highlights MACD and

Indicator v5 Oscillators & momentumDivergence
Updated 2 months ago · None stated GitHub repository of MTF + MACD [Alorse]

Benso RSI + PMARP

by benso87
24 stars

This indicator plots an RSI and a PMARP line in a separate pane. It calculates RSI from a chosen source and length, then overlays an SMA or EMA signal. Horizontal bull and bear control and critical levels scale the oscillator. Optional arrows mark regular and

Indicator v5 Oscillators & momentumDivergence
Updated 4 years ago · MPL-2.0 GitHub repository of Benso RSI + PMARP

Relative Strength Index

by deepentropy
13 stars

The Relative Strength Index indicator calculates momentum based on price changes over a specified length and plots the curve in a separate pane. It includes adjustable upper and lower bands, background color fills, and an optional smoothing moving average or B

Indicator v6 Oscillators & momentumMoving averages
Updated 6 months ago · MIT GitHub repository of Relative Strength Index

This indicator evaluates how price relates to one selected moving-average family rather than treating a crossover as a signal. It scores trend quality, historical respect of the average, extension, compression, acceleration, and exhaustion, then plots a relati

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Market–Average Relationship Engine [WavesUnchained]

This indicator combines RSI and MFI into a hybrid oscillator scaled to 0-1. It detects divergences by comparing price and MFI slopes from linear regression. The MFI receives extra weight during divergence to amplify the effect. A TMA smooths the hybrid result

Indicator v6 Oscillators & momentumDivergence
Updated 5 months ago · None stated GitHub repository of Hybrid RSI+MFI - Gold Divergence

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