OPEN-SOURCE SCRIPT

CQ_(L)_Oscillators Overlay

402
================================================================================
CQ_(L)_OSCILLATORS OVERLAY
User Manual
================================================================================

OVERVIEW
--------------------------------------------------------------------------------
This indicator takes a sub-pane oscillator engine (originally built for a
separate pane) and re-renders it directly on the price chart as an overlay.
You choose one of eight oscillator types, and the script draws it as a
scaled, floating panel above or below price action, using a rolling window
of recent bars. It borrows its array-based collection/redraw technique and
box-drawing style from the CQ Larry Williams Vix Fix overlay script.

Because the oscillator is bidirectional (it can swing both above and below
its own midline, unlike Vix Fix which only measures magnitude), the drawing
engine scales values based on distance from the midline rather than raw
value, and can mirror in either direction.


SECTION 1 — INDICATOR SELECTION
--------------------------------------------------------------------------------
A dropdown lets you choose which oscillator drives the overlay:

MACD - Standard MACD/Signal/Histogram
VMACD - Volume-weighted MACD (volume-weighted EMAs)
RSI - Relative Strength Index
MFI - Money Flow Index (volume-weighted RSI)
CCI - Commodity Channel Index
DRM - Directional Range Momentum (custom range-breakout momentum)
Stochastic - Standard %K / %D
Stoch RSI - Stochastic applied to RSI instead of price

A second dropdown ("Trend") controls an optional trend filter used by the
buy/sell signal logic:

Off - No trend filter; signals fire on oscillator conditions alone
200 EMA Trend - Filters signals using a 200-period EMA of price
VWAP Trend - Filters signals using session VWAP instead of the 200 EMA
Range - Same trend line, but skips the "must agree with trend"
requirement (used for range-bound markets)


SECTION 2 — COLOR & LINE STYLE
--------------------------------------------------------------------------------
- Two color pickers set the oscillator line color and the
basis/signal line color.
- "Alternate Colors" toggle: when on, the signal/basis line becomes
transparent, and the main oscillator line instead turns green when above
its midline and red when below it (a simple directional color scheme).


SECTION 3 — MACD / VW-MACD SETTINGS
--------------------------------------------------------------------------------
Fast Length (default 12)
Slow Length (default 26)
Signal Length (default 9)

These only apply when MACD or VMACD is the selected indicator. VMACD uses
volume-weighted EMAs instead of plain EMAs for the fast/slow lines.


SECTION 4 — OSCILLATOR SETTINGS (RSI / Stochastic family)
--------------------------------------------------------------------------------
Length (default 14) - lookback for RSI, MFI, CCI, DRM, or Stochastic %K
Smoothing (default 3) - smoothing applied to the raw oscillator/%K
Signal (default 14) - length of the basis/EMA signal line, or %D length

OB/OS (Overbought/Oversold)
OB/OS value (default 70) - sets the overbought line; the oversold line is
mirrored automatically around the midline
Extreme (default 10) - added to OB/OS to define an "Extreme" zone
(used for stronger/"slow-cooldown" signals)

Volume Pressure
A toggle that overlays a secondary line built from a fast/slow blended MFI
reading, compressed through a power curve. Useful as a volume-based
confirmation line drawn against the same midline.

Options row
Fill Lines - shades the area between the oscillator and its basis line
(blue when oscillator is above basis, orange when below)
Fill OB/OS - shades the area between the oscillator and the OB/OS
reference lines when price pushes into those zones
(deeper shade in the "Extreme" zone)
Divergence - draws bullish/bearish divergence lines and labels comparing
price pivots against oscillator pivots


SECTION 5 — OVERLAY DISPLAY OPTIONS (Group: "OVERLAY — Display Options")
--------------------------------------------------------------------------------
Number of Bars to Show (default 50, max 150)
How many of the most recent bars are drawn in the overlay panel.
Capped at 150 to respect TradingView's per-indicator object budget.

Oscillator Height (default 300, price units)
The vertical distance (in price units) that the extreme OB/OS+Extreme
value is stretched out to, measured from the panel's baseline.

Separation from Price (default 150%, range 100-1400%)
How far the panel's baseline sits from the highest/lowest visible
candle. 100% means the baseline touches price; higher values add gap.

Placement (Top / Bottom, default Bottom)
Whether the panel is drawn above the visible highs or below the
visible lows.

Flip Upside Down
Mirrors the panel vertically (useful if you prefer overbought
readings to point toward price rather than away from it).

Show OB/Mid/OS Reference Lines
Draws dotted horizontal lines marking the midline, overbought, and
oversold levels across the visible window.

Show OB/OS Zone Fill
Shades the band between the OB and OS reference lines.


SECTION 6 — HOW THE OVERLAY IS DRAWN (for reference)
--------------------------------------------------------------------------------
Each bar's oscillator, basis, histogram, and volume-pressure values are
pushed into rolling arrays capped at "Number of Bars to Show." On the last
bar, all previous drawings are deleted and redrawn:

1. A baseline price level is computed from the visible high/low range,
offset by Height x Separation%.
2. A scale factor ("wMax") is derived from the OB+Extreme distance and the
actual oscillator/basis range, so the panel never clips.
3. Oscillator and basis values are converted to price-scale y-coordinates
relative to the midline and drawn as connected line segments.
4. For MACD/VMACD, histogram bars are drawn as thin boxes from the
baseline out to each bar's scaled histogram value, colored by
rising/falling and above/below-zero state.
5. A text label with the selected indicator's name is placed at the end
of the panel.

This mirrors the same rolling-window / redraw-on-last-bar technique used in
the Vix Fix overlay script, adapted for a two-sided (bidirectional)
oscillator instead of a one-sided magnitude series.


SECTION 7 — SIGNALS & ALERTS
--------------------------------------------------------------------------------
MACD Signals (only when MACD is selected)
- Buy: MACD crosses over Signal while price is above the trend EMA/VWAP,
and the cross happens at or near zero (MACD or its prior value
below zero).
- Sell: Mirror image condition for a bearish cross.
- Both have dedicated alertcondition() alerts.

Oscillator Signals (RSI, CCI, DRM, Stochastic, Stoch RSI)
Two signal speeds, each with its own cooldown to prevent rapid repeat
firing:
Fast (5-bar cooldown) - oscillator crosses its basis line while still
inside normal territory, OR crosses the
"Extreme" OB/OS+Extreme level.
Slow (10-bar cooldown) - oscillator crosses the standard OB/OS level.
If the Trend filter is not "Off" or "Range", signals additionally require
price to agree with the trend EMA/VWAP direction.
Buy/Sell background highlighting (green/red) marks bars where any of
these signals fire, matched to whichever oscillator is active.


SECTION 8 — DIVERGENCE
--------------------------------------------------------------------------------
When "Divergence" is enabled, the script compares 5-bar-left/5-bar-right
pivot highs and lows in price against the oscillator's own pivots:
- Bullish divergence: price makes a lower low while the oscillator makes
a higher low -> green line + "Bull Div" label below the bar.
- Bearish divergence: price makes a higher high while the oscillator
makes a lower high -> red line + "Bear Div" label above the bar.


SECTION 9 — PRACTICAL NOTES & LIMITS
--------------------------------------------------------------------------------
- "Number of Bars to Show" is capped at 150 bars to stay within Pine's
line/box drawing budget when combined with fills, reference lines, and
histogram boxes.
- The overlay drawing loop stops adding new line objects once the combined
oscillator + basis + volume-pressure line count reaches 480, as a safety
margin under the 500-object limit declared at the top of the script.
- Volume Pressure, Fill Lines, Fill OB/OS, and Divergence are independent
toggles and can be combined freely, but turning on several at once with a
high bar count will use more of the drawing budget.
- OB/OS zone fill and reference lines are skipped for MACD/VMACD, since
those use a zero-centered histogram instead of a fixed OB/OS band.
- All original oscillator calculations run on the current chart's timeframe
by default (the internal multi-timeframe parameter is left blank), so the
overlay reflects the chart timeframe you have open.

================================================================================
End of manual — CQ_(L)_Oscillators Overlay
================================================================================

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.