OPEN-SOURCE SCRIPT
Aggiornato

Supertrend Oscillator | TR

619
🎯 Overview
Supertrend Oscillator transforms the classic Supertrend (which plots a directional line on price) into a bounded oscillator that ranges from -100% to +100%. It measures how far price is from the Supertrend line relative to the ATR‑based bandwidth, giving a clear, normalised view of trend strength. The indicator keeps all the familiar Supertrend logic but adds gradient candle coloring, dynamic fills, nine color themes, entry signals, and a persistent trend table – turning a trend‑following line into a full visual momentum system.

⚙️ Core Calculations
1. Standard Supertrend
Source: hl2 (high+low / 2)

ATR Period: default 10

Factor: default 3

The Supertrend line and direction (pineDir) are computed using the classic Pine Script logic:

pineDir = -1 → uptrend (price above Supertrend)

pineDir = +1 → downtrend (price below Supertrend)

2. Oscillator (%)
Uptrend (pineDir = -1): positive values (0 to +100)

Downtrend (pineDir = +1): negative values (0 to -100)

The result is clamped to [-100, +100].

3. Normalised Percent (0..1)
Over the last 70 bars, percent is re‑scaled to a 0–1 range. Used for gradient candle coloring (smooth transition between bearish and bullish theme colors).

4. Momentum & Fill Transparency
Momentum = absolute 5‑bar change of percent

Normalised over a 50‑bar max → normMomentum

Fill transparency = 35 - (normMomentum × 25) clamped 0–100
→ Higher momentum = less transparent (more visible fill).

🎨 Visual Features
9 Color Themes
Same palette as the previous Williams %R indicator:

Classic, Modern, Heat, Robust, Accented, Monochrome, Moderate, Aqua, Cosmic.

Each theme defines UpC (bullish color) and DnC (bearish color).

Gradient Candles
Candle color interpolates between DnC and UpC based on the normalised percent.

Overlay on the price chart (plotcandle).

Dynamic Fills (between oscillator and zero line)
Overbought fill (percent > 0) – gradient from solid UpC (at +100) to transparent (at 0)

Oversold fill (percent < 0) – gradient from transparent (at 0) to solid DnC (at -100)

Trend‑direction fill – only fills the side of the current trend (bullish or bearish), with momentum‑based transparency. Higher momentum = less transparent.

Supertrend Overlay (optional)
Plot Chart toggle (false by default). When enabled, plots the classic Supertrend lines directly on the price pane:

Uptrend line (green) when pineDir = -1

Downtrend line (red) when pineDir = +1

Signal Markers
LONG (Bull_Cross): percent crosses above zero → green triangle below bar.

SHORT (Bear_Cross): percent crosses below zero → red triangle above bar.

Background Tint
Very light bullish / bearish tint matching the active trend.

Trend Table (middle‑right corner)
Shows “BULLISH” (⬆️) or “BEARISH” (⬇️) in large colored text.

Floating Value Label
On the last bar, shows the current percent value (e.g., 42.35%) near the oscillator line, with a semi‑transparent background matching the trend color.

📈 Signal System
Entry Signals
LONG (Bull_Cross): percent crosses above 0
→ Occurs when price moves from below Supertrend to above it, pushing the oscillator from negative into positive territory.

SHORT (Bear_Cross): percent crosses below 0

Trend Persistence
Trend_Supertrend stores the last confirmed direction:

1 = bullish (percent > 0)

-1 = bearish (percent < 0)

The trend state only changes on a zero‑line cross – prevents flickering near the threshold.

Overbought / Oversold Interpretation
+100 → price is exactly one ATR‑bandwidth above the Supertrend (strong uptrend).

-100 → price is exactly one ATR‑bandwidth below the Supertrend (strong downtrend).

Crossing zero indicates the price has just crossed the Supertrend line – a classic reversal signal.

Divergence Possibility
Although not explicitly coded, the oscillator’s raw percent value can be used to spot divergences:

Price makes a higher high but percent makes a lower high → bearish divergence.

Price makes a lower low but percent makes a higher low → bullish divergence.
Note di rilascio
Debug

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.