Indicator · Pine Script v4 · Own pane

Detrended Rhythm Oscillator Peak

by mikeyhu70· code credited to WhenToTrade

This indicator builds a Detrended Rhythm Oscillator in a separate pane.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code130
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago15 Apr 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

130 lines of Pine Script v4 from Cycle/Detrended Rhythm Oscillator (DRO) Peak.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Detrended Rhythm Oscillator (DRO) Peak.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// Detrended Rhythm Oscillator (DRO)
// ----------------------------------
// Uses a Detrended Price Oscillator to calculate detrended "zig zag" swings and plots the distance between the last High-High and Low-Low 
//
// Purpose:
// A tool to measure and visualize the current dominant cycle (or rhythm/beat) in the dataset
// Look for common length numbers on the Zig Zag turns to determine the current dominant cycle length, also check for harmonics (2x, 3x)
// You can use the spotted length to optimize the length parameter of technical indicators (use the length or half of the length as input for any technical indicator)
// A technical indicator with the "correct" length setting in regards to the current dominant cycle will provide much better signals
//
// References:
// Zig Zag array functions used from open-source user "LonesomeTheBlue", script Name: "Double Zig Zag with HHLL"
//
// © WhenToTrade

//@version=4
study("Detrended Rhythm Oscillator (DRO) Peak", shorttitle="DRO_P", max_lines_count=30, max_bars_back=300, overlay = false)


// { Inputs
// -----------------------------------------------------------------------------
indiversion     = input(              "DRO",   "==== Select Indicator ====", input.string , options=["DRO", "DPO", "BOTH"])
src             = input(              high,                     "  Source", input.source )

fastLength      = input(                  3,                "  Fast Length", type=input.integer, group="DPO")
slowLength      = input(                 20,                "  Slow Length", type=input.integer, group="DPO")

//... ZigZag
zigperiod       = input(                 12,                     "  Period", input.integer, minval=5, group="ZigZag", inline="p")
zigstyle        = input(           "Dashed",                     "  Line -", options = ["Dashed", "Dotted"], group="ZigZag", inline="line")
zigwidth        = input(                  1,                  " Width  -- ", input.integer, options=[1,2,3], group="ZigZag", inline="line") 

showdistanceS   = input(           "On",                         "  Labels", options = ["On", "Off"], group="ZigZag", inline="switch")
showdetrendedS  = input(           "On",                       " Detrended", options = ["On", "Off"], group="ZigZag", inline="switch") 

upcolor         = input(defval = #363A45, title = "  Colors:  Up", group="ZigZag", inline="color")
downcolor       = input(defval = #363A45, title = " Down", group="ZigZag", inline="color")
txtcol          = input(defval = #67E1E1, title = " Text", group="ZigZag", inline="color")

//... Switches
showdistance    = (showdistanceS == "On") ? true : false 
showdetrended   = (showdetrendedS == "On") ? true : false  
// } Inputs

// { Variables
// -----------------------------------------------------------------------------
var max_array_size = 10
var ziggyzags = array.new_float(0)
var dir1 = 0
var lastPivot=0
var lastPivotDistance=0
// } Variables

// { Functions
// -----------------------------------------------------------------------------

add_to_zigzag(pointer, value, bindex)=>
    array.unshift(pointer, bindex)
    array.unshift(pointer, value)
    if array.size(pointer) > max_array_size
        array.pop(pointer)
        array.pop(pointer)
    
update_zigzag(pointer, value, bindex, dir)=>
    if array.size(pointer) == 0
        add_to_zigzag(pointer, value, bindex)
    else
        if (dir == 1 and value > array.get(pointer, 0)) or (dir == -1 and value < array.get(pointer, 0))
            array.set(pointer, 0, value)
            array.set(pointer, 1, bindex)
        0.

// } Functions

// { Calculations
// -----------------------------------------------------------------------------

//... DPO
ppo = 100 * (ema(src, fastLength) - ema(src, slowLength)) / ema(src, slowLength)

//... ZigZag
float highs = highestbars(ppo, zigperiod) == 0 ? ppo : na
float lows = lowestbars(ppo, zigperiod) == 0 ? ppo : na

dir1 := iff(highs and na(lows), 1, iff(lows and na(highs), -1, dir1))

dir1changed = change(dir1)
if highs or lows
    if dir1changed 
        add_to_zigzag(ziggyzags, dir1 == 1 ? highs : lows, bar_index)
    else
        update_zigzag(ziggyzags, dir1 == 1 ? highs : lows, bar_index, dir1)

// } Calculations

// { Plots
// -----------------------------------------------------------------------------

//... Detrended Price Oscillator
plot(indiversion=="DPO" or indiversion=="BOTH" ? ppo : na)

//... Detrended Zig-Zag lines with distance labels
if array.size(ziggyzags) >= 6
    var line zzline1 = na
    var label zzlabel1 = na
    float val = array.get(ziggyzags, 0)
    int point = round(array.get(ziggyzags, 1))
    if change(val) or change(point)
        float val1 = array.get(ziggyzags, 2)
        int point1 = round(array.get(ziggyzags, 3))
        lastPivotDistance:=point-lastPivot
        plabel= tostring(point-lastPivot+lastPivotDistance[lastPivotDistance])
        lastPivot:=point1
        
        if change(val1) == 0 and change(point1) == 0
            if (dir1 == 1)
                label.delete(zzlabel1)
            line.delete(zzline1)
            
        if(indiversion=="DRO" or indiversion=="BOTH")
            zzline1 := line.new(x1 = point, x2 = point1, y1 = showdetrended ? dir1 == 1 ? 100 : -100 : val , y2 = showdetrended ? dir1 == 1 ? -100 : 100 : val1, color = dir1 == 1 ? upcolor : downcolor, width = zigwidth, style = zigstyle == "Dashed" ? line.style_dashed: line.style_dotted)
        
        if ((indiversion=="DRO" or indiversion=="BOTH") and showdistance)
            if (dir1 == 1)
                zzlabel1 := label.new(x = point, y = showdetrended ? (dir1 == 1 ? 75 : -75) : val,  text = plabel, textcolor = txtcol, style = label.style_none, size=size.large) 
                //zzlabel1 := label.new(x = point, y = val,  text = plabel, textcolor = txtcol, style = label.style_none) 
            
// } Plots

Overview

Detrended Rhythm Oscillator Peak uses a detrended price oscillator with fast and slow lengths to find zig-zag swings, then draws dashed or dotted lines and labels showing the bar distance between successive highs. The aim is to help spot the dominant cycle length by looking for repeating distances and harmonics. The source, zig-zag period, line style and colours are adjustable. It has no trade signals. The default source is the high.

Details

Published by

mikeyhu70 on GitHub

Code credit

WhenToTrade, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum

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.

Settings

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

SettingTypeDefaultVariable
==== Select Indicator ====stringDROindiversion
  Sourcesourcehighsrc
  Fast Lengthint3fastLength
  Slow Lengthint20slowLength
  Periodint12zigperiod
  Line -stringDashedzigstyle
 Width -- int1zigwidth
  LabelsstringOnshowdistanceS
 DetrendedstringOnshowdetrendedS
  Colors:  Upcolor#363A45upcolor
 Downcolor#363A45downcolor
 Textcolor#67E1E1txtcol
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

Asymmetrical RSI

by everget
947 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 11 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

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
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI
228 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector

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