Indicator · Pine Script v6 · Own pane

Derivative Oscillator (DOSC)

by mihakralj

Calculates the Derivative Oscillator by applying double exponential moving average (EMA) smoothing to a Relative Strength Index (RSI) baseline and subtracting a simple moving average (SMA) signal line.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code82
Settings5inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 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

82 lines of Pine Script v6 from lib/oscillators/dosc/dosc.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

dosc.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Derivative Oscillator (DOSC)", "DOSC", overlay=false, precision=4)

//@function Calculates the Derivative Oscillator: double-smoothed RSI minus its SMA signal line
//@param source Series to calculate from
//@param rsiPeriod RSI lookback period
//@param ema1Period First EMA smoothing period applied to RSI
//@param ema2Period Second EMA smoothing period (double smoothing)
//@param sigPeriod SMA signal line period applied to double-smoothed RSI
//@returns DOSC value (histogram: double-smoothed RSI minus signal)
//@optimized O(1) per bar after warmup for all EMA/SMA stages
dosc(series float source, simple int rsiPeriod, simple int ema1Period, simple int ema2Period, simple int sigPeriod) =>
    if rsiPeriod <= 0 or ema1Period <= 0 or ema2Period <= 0 or sigPeriod <= 0
        runtime.error("All periods must be greater than 0")

    // --- Stage 1: RSI via Wilder's smoothing ---
    float change_up = math.max(source - nz(source[1]), 0.0)
    float change_down = math.max(nz(source[1]) - source, 0.0)

    var float avgGain = 0.0
    var float avgLoss = 0.0

    float rsiAlpha = 1.0 / rsiPeriod
    if bar_index < rsiPeriod
        avgGain := change_up
        avgLoss := change_down
    else
        avgGain := nz(avgGain[1]) * (1.0 - rsiAlpha) + change_up * rsiAlpha
        avgLoss := nz(avgLoss[1]) * (1.0 - rsiAlpha) + change_down * rsiAlpha

    float rsiVal = avgLoss == 0.0 ? 100.0 : 100.0 - (100.0 / (1.0 + avgGain / avgLoss))

    // --- Stage 2: EMA1 of RSI ---
    var float ema1 = na
    float alpha1 = 2.0 / (ema1Period + 1.0)
    ema1 := na(ema1[1]) ? rsiVal : nz(ema1[1]) * (1.0 - alpha1) + rsiVal * alpha1

    // --- Stage 3: EMA2 of EMA1 (double smoothing) ---
    var float ema2 = na
    float alpha2 = 2.0 / (ema2Period + 1.0)
    ema2 := na(ema2[1]) ? ema1 : nz(ema2[1]) * (1.0 - alpha2) + ema1 * alpha2

    // --- Stage 4: SMA signal line of EMA2 ---
    var array<float> sigBuf = array.new_float(sigPeriod, na)
    var int sigHead = 0
    var int sigCount = 0
    var float sigSum = 0.0

    float oldest = array.get(sigBuf, sigHead)
    if not na(oldest)
        sigSum -= oldest
        sigSum += ema2
    else
        sigCount += 1
        sigSum += ema2

    array.set(sigBuf, sigHead, ema2)
    sigHead := (sigHead + 1) % sigPeriod

    float signal = sigCount > 0 ? sigSum / sigCount : 0.0

    // DOSC = double-smoothed RSI minus signal
    float result = ema2 - signal
    result

// ---------- Main loop ----------

// Inputs
i_source    = input.source(close, "Source")
i_rsiPeriod = input.int(14, "RSI Period", minval=1, maxval=500)
i_ema1      = input.int(5, "EMA1 Period", minval=1, maxval=500, tooltip="First EMA smoothing of RSI")
i_ema2      = input.int(3, "EMA2 Period", minval=1, maxval=500, tooltip="Second EMA smoothing (double smooth)")
i_sigPeriod = input.int(9, "Signal Period", minval=1, maxval=500, tooltip="SMA signal line period")

// Calculation
dosc_value = dosc(i_source, i_rsiPeriod, i_ema1, i_ema2, i_sigPeriod)

// Plot
plot(dosc_value, "DOSC", color=color.yellow, linewidth=2)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)

Overview

Plotted in a separate pane alongside a zero reference line, it isolates smoothed momentum fluctuations around a central baseline. Inputs allow full control over the source series, RSI period, primary and secondary EMA smoothing lengths, and SMA signal line period.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

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.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosei_source
RSI Periodint14i_rsiPeriod
EMA1 Periodint5i_ema1
EMA2 Periodint3i_ema2
Signal Periodint9i_sigPeriod
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

948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

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