// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ZeusAlgo //@version=5 indicator("ZeusAlgo Premium Oscillator™", overlay = false, explicit_plot_zorder = true) upColor = input.color(#2be300, "Positive Color") downColor = input.color(#ff1100, "Negative Color") momentumLength = input.int(title="Primary Momentum Length", defval=10, minval=2, maxval = 200, group = "Momentum Configuration") swingMomentumLength = input.int(title="Secondary Momentum Length", defval=20, minval=2, maxval = 200, group = "Momentum Configuration") calcPeriod = input.int(title="Squeeze Period", defval=14, minval=1, group = "Squeeze Parameters") smoothLength = input.int(title="Smoothing Length", defval=7, minval=1, group = "Squeeze Parameters") emaLength = input.int(title="EMA Length", defval=14, minval=2, maxval = 200, group = "Squeeze Parameters") hyperSqueezeLength = input.int(title="Hyper Squeeze Length", defval=5, minval=1, group = "Squeeze Parameters") pivotDetectLength = input.int(title="Pivot Detection Length", defval=15, group = "Divergence Settings", tooltip = "Larger values make divergence detection less sensitive") pivotConfirmLength = input.int(title="Pivot Confirmation Length", defval=1, group = "Divergence Settings", tooltip = "Higher values delay signal confirmation but reduce false signals. Set to 0 for no delay") showBullishDiv = input(title="Show Bullish Divergences", defval=true, group = "Divergence Settings") showBearishDiv = input(title="Show Bearish Divergences", defval=true, group = "Divergence Settings") // Calculating ATR and its EMA averageTrueRange = ta.ema(ta.tr(true), calcPeriod) emaOfATR = ta.ema(averageTrueRange, calcPeriod * 2) volatilityIndicator = emaOfATR - averageTrueRange // Calculating SV (Squeeze Value) and SVMA (Squeeze Value Moving Average) emaHighLowDifference = ta.ema(high - low, calcPeriod * 2) squeezeValue = ta.ema(volatilityIndicator / emaHighLowDifference * 100, smoothLength) squeezeValueMA = ta.ema(squeezeValue, emaLength) hypersqueeze = squeezeValue > 0 and ta.rising(squeezeValue, hyperSqueezeLength) l = ta.ema(ta.lowest(low, momentumLength), momentumLength) h = ta.ema(ta.highest(high, momentumLength), momentumLength) var direction = 0 if ta.crossover(close, h) direction := 1 if ta.crossunder(close, l) direction := -1 val = direction == 1 ? l : h val1 = close - val val2 = ta.hma(val1, momentumLength) vf = (val2 / (ta.ema(high - low, momentumLength * 2)) * 100) / 8 basis = ta.sma(vf, swingMomentumLength) zscore = (vf - basis) / ta.stdev(vf, swingMomentumLength) zscore := ta.ema(zscore, swingMomentumLength) zscore := zscore * 66 level = 2 f = plot(100, display = display.none) negf = plot(-100, display = display.none) z = plot(0, display = display.none) fill(z, f, top_value = 100, bottom_value = 50, bottom_color = na, top_color = color.from_gradient(vf, -100, 100, color.new(downColor,100), color.new(downColor,20))) fill(z, negf, top_value = -50, bottom_value = -100, bottom_color = color.from_gradient(-vf, -100, 100, color.new(upColor,100), color.new(upColor,30)) , top_color = na) v1 = plot(vf, color = vf > 0 ? upColor : downColor, style = plot.style_line) p1 = plot(level, color = hypersqueeze ? color.yellow : squeezeValueMA - squeezeValue < 0 ? color.orange : color.gray, linewidth = 4, trackprice = false, histbase = -level, style = plot.style_areabr) fill(p1, v1, level, vf, vf > 0 ? color.new(upColor, 100) : na, vf > 0 ? upColor : na) fill(p1, v1, vf, -level, vf < 0 ? downColor : na, vf < 0 ? color.new(downColor, 100) : na) z0 = plot(zscore, color = color.white) z1 = plot(zscore[1], color = color.white, display = display.none) fill(z0, z1, color.new(color.white, 50)) plotchar(ta.cross(zscore, zscore[1]) ? zscore[1] : na, "Swing Momentum Cross", "●", location.absolute, color.white, size = size.tiny) // Divergences Section wideDisplayCond = display.all x = zscore bullColor = upColor bearColor = downColor hiddenBullColor = color.new(upColor, 80) hiddenBearColor = color.new(downColor, 80) textColor = color.white noneColor = color.new(color.white, 100) plFound = na(ta.pivotlow(x, pivotDetectLength, pivotConfirmLength)) ? false : true phFound = na(ta.pivothigh(x, pivotDetectLength, pivotConfirmLength)) ? false : true _inRange(cond) => bars = ta.barssince(cond == true) -80 <= bars and bars <= 80 // Regular Bullish oscHL = x[pivotConfirmLength] > ta.valuewhen(plFound, x[pivotConfirmLength], 1) and _inRange(plFound[1]) priceLL = low[pivotConfirmLength] < ta.valuewhen(plFound, low[pivotConfirmLength], 1) bullCond = showBullishDiv and priceLL and oscHL and plFound plot(plFound ? x[pivotConfirmLength] : na, offset=-pivotConfirmLength, title="Regular Bullish", linewidth=2, color=(bullCond ? bullColor : noneColor), display = wideDisplayCond) plotshape(bullCond ? x[pivotConfirmLength] : na, offset=-pivotConfirmLength, title="Regular Bullish Label", text=" B ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor) // Regular Bearish oscLH = x[pivotConfirmLength] < ta.valuewhen(phFound, x[pivotConfirmLength], 1) and _inRange(phFound[1]) priceHH = high[pivotConfirmLength] > ta.valuewhen(phFound, high[pivotConfirmLength], 1) bearCond = showBearishDiv and priceHH and oscLH and phFound plot(phFound ? x[pivotConfirmLength] : na, offset=-pivotConfirmLength, title="Regular Bearish", linewidth=2, color=(bearCond ? bearColor : noneColor), display = wideDisplayCond) plotshape(bearCond ? x[pivotConfirmLength] : na, offset=-pivotConfirmLength, title="Regular Bearish Label", text=" S ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor) ///////////Alerts alertcondition(ta.crossover(vf, 0), "Positive Underlying Momentum") alertcondition(ta.crossunder(vf, 0), "Negative Underlying Momentum") alertcondition(ta.crossover(zscore, zscore[1]), "Positive Swing Momentum") alertcondition(ta.crossunder(zscore, zscore[1]), "Negative Swing Momentum") alertcondition(plFound, "Bullish Divergence Detected") alertcondition(phFound, "Bearish Divergence Detected") alertcondition(ta.crossover(squeezeValueMA - squeezeValue, 0), "Standard Squeeze Detected") alertcondition(hypersqueeze, "Hyper Squeeze Detected")