Oscillators for Divergences
"Source-Aligned Oscillators (for Divergences)" by QuantNomad, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Source-Aligned Oscillators (for Divergences) (v1.0), read 2026-11-15T18:50:28.622Z; source language v6.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
Source-Aligned Oscillators (for Divergences) by QuantNomad, ported from Pine v6. Pane indicator with 11 plots and 15 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// (Notice added by FloSignals: the author's source carries none. It was published open-source on 2026-04-05; since 2019-07-26 the platform it was published on has released such a script under MPL-2.0 automatically.)
// ------------------------------------------------------------------------------------------------
// Original author: QuantNomad
// Original title: Source-Aligned Oscillators (for Divergences)
// Licence: MPL-2.0 (the notice above was added by FloSignals; the original carries none)
// Pine version: 6
// Fetched: 2026-11-15
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=6
indicator('Oscillators for Divergences', shorttitle='OscDiv', overlay=false, precision=2)
//====================================================================
// Inputs
//====================================================================
groupGeneral = 'General'
oscType = input.string(defval='RSI', title='Oscillator', options=['RSI', 'ROC', 'Momentum', 'MACD', 'CMO', 'Stoch RSI'], group=groupGeneral)
srcMode = input.string(defval='Close', title='Source Mode', options=['Close', 'HL2', 'HLC3', 'OHLC4', 'High/Low Split', 'Body High/Low Split'], group=groupGeneral)
showBull = input.bool(true, 'Show Bullish Line', group=groupGeneral)
showBear = input.bool(true, 'Show Bearish Line', group=groupGeneral)
showStochD = input.bool(true, 'Show Stoch RSI %D', group=groupGeneral)
groupLengths = 'Lengths'
rsiLen = input.int(14, 'RSI Length', minval=1, group=groupLengths)
rocLen = input.int(14, 'ROC Length', minval=1, group=groupLengths)
momLen = input.int(10, 'Momentum Length', minval=1, group=groupLengths)
cmoLen = input.int(14, 'CMO Length', minval=1, group=groupLengths)
stochLen = input.int(14, 'Stoch RSI Length', minval=1, group='Stoch')
smoothK = input.int(3, 'Stoch RSI %K Smoothing', minval=1, group='Stoch')
smoothD = input.int(3, 'Stoch RSI %D Smoothing', minval=1, group='Stoch')
macdFast = input.int(12, 'Fast Length', minval=1, group='MACD')
macdSlow = input.int(26, 'Slow Length', minval=1, group='MACD')
macdSignal = input.int(9, 'Signal Length', minval=1, group='MACD')
//====================================================================
// Source logic
//====================================================================
bodyHigh = math.max(open, close)
bodyLow = math.min(open, close)
isSplitSource = srcMode == 'High/Low Split' or srcMode == 'Body High/Low Split'
bullSrc = switch srcMode
'Close' => close
'HL2' => hl2
'HLC3' => hlc3
'OHLC4' => ohlc4
'High/Low Split' => low
'Body High/Low Split' => bodyLow
=> close
bearSrc = switch srcMode
'Close' => close
'HL2' => hl2
'HLC3' => hlc3
'OHLC4' => ohlc4
'High/Low Split' => high
'Body High/Low Split' => bodyHigh
=> close
//====================================================================
// Oscillator functions
//====================================================================
f_rsi(_src, _len) =>
ta.rsi(_src, _len)
f_roc(_src, _len) =>
ta.roc(_src, _len)
f_mom(_src, _len) =>
ta.mom(_src, _len)
f_macd_hist(_src, _fast, _slow, _signal) =>
macdLine = ta.ema(_src, _fast) - ta.ema(_src, _slow)
signalLine = ta.ema(macdLine, _signal)
macdLine - signalLine
f_cmo(_src, _len) =>
ta.cmo(_src, _len)
f_stoch_rsi_k(_src, _rsiLen, _stochLen, _smoothK) =>
rsiValue = ta.rsi(_src, _rsiLen)
lowestRsi = ta.lowest(rsiValue, _stochLen)
highestRsi = ta.highest(rsiValue, _stochLen)
rawK = highestRsi != lowestRsi ? 100 * (rsiValue - lowestRsi) / (highestRsi - lowestRsi) : na
ta.sma(rawK, _smoothK)
f_get_osc(_src) =>
out = switch oscType
'RSI' => f_rsi(_src, rsiLen)
'ROC' => f_roc(_src, rocLen)
'Momentum' => f_mom(_src, momLen)
'MACD' => f_macd_hist(_src, macdFast, macdSlow, macdSignal)
'CMO' => f_cmo(_src, cmoLen)
'Stoch RSI' => f_stoch_rsi_k(_src, rsiLen, stochLen, smoothK)
=> na
out
//====================================================================
// Calculations
//====================================================================
bullOsc = f_get_osc(bullSrc)
bearOsc = f_get_osc(bearSrc)
singleOsc = bullOsc
stochBullD = oscType == 'Stoch RSI' ? ta.sma(bullOsc, smoothD) : na
stochBearD = oscType == 'Stoch RSI' ? ta.sma(bearOsc, smoothD) : na
isRsiFamily = oscType == 'RSI' or oscType == 'Stoch RSI'
isCMO = oscType == 'CMO'
isZeroBased = oscType == 'ROC' or oscType == 'Momentum' or oscType == 'MACD' or oscType == 'CMO'
//====================================================================
// Reference lines
//====================================================================
midValue = isZeroBased ? 0.0 : 50.0
plot(midValue, title='Midline', color=color.new(color.gray, 60), linewidth=1)
plot(isRsiFamily ? 70 : na, title='Upper 70', color=color.new(color.gray, 80), linewidth=1)
plot(isRsiFamily ? 30 : na, title='Lower 30', color=color.new(color.gray, 80), linewidth=1)
plot(isCMO ? 50 : na, title='CMO +50', color=color.new(color.gray, 85), linewidth=1)
plot(isCMO ? -50 : na, title='CMO -50', color=color.new(color.gray, 85), linewidth=1)
//====================================================================
// Plots
//====================================================================
plot(not isSplitSource and showBull ? singleOsc : na, title='Oscillator', color=color.new(color.aqua, 0), linewidth=2)
plot(isSplitSource and showBull ? bullOsc : na, title='Bullish Source Line', color=color.new(color.lime, 0), linewidth=2)
plot(isSplitSource and showBear ? bearOsc : na, title='Bearish Source Line', color=color.new(color.red, 0), linewidth=2)
plot(oscType == 'Stoch RSI' and showStochD and not isSplitSource and showBull ? stochBullD : na, title='Stoch RSI %D', color=color.new(color.orange, 0), linewidth=1)
plot(oscType == 'Stoch RSI' and showStochD and isSplitSource and showBull ? stochBullD : na, title='Stoch RSI %D Bull', color=color.new(color.green, 50), linewidth=1)
plot(oscType == 'Stoch RSI' and showStochD and isSplitSource and showBear ? stochBearD : na, title='Stoch RSI %D Bear', color=color.new(color.maroon, 50), linewidth=1)
This file is under the Mozilla Public License 2.0; it is a port of the original by QuantNomad, with the original licence header kept and the changes made for FloScript noted in the file.
- v1
Library refresh 2026-11-15
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.