Indicator · Pine Script v6 · Own pane

Quad Rotation 9 3

by rubbermetal· code credited to claygrace74

Quad Rotation 9 3 is the fast pane of a four-stochastic setup with periods 9, 14, 40 and 60.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code223
Settings24inputs
LicenceMPL-2.0
Last update4 months ago10 Jun 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

223 lines of Pine Script v6 from Quad Rotation 9 3.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Quad Rotation 9 3.pine
// This Pine Script code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © claygrace74
// Quad Rotation Strategy - 9/3 Stochastic Pane
// Day Trader Rock Star's Quad Rotation: 4 stochastics (9/3, 14/3, 40/4, 60/10)
// This pane features the FAST stochastic (9,3,3)

//@version=6
indicator("Quad Rotation 9 3", shorttitle="QR 9/3")

// ==================== Stochastic Inputs ====================
var stoch_group = "Stochastic Settings"
k1source = input.source(close, "Stoch 9/3 Source", group=stoch_group)
periodK1 = input.int(9,  title="%K1 Length", minval=1, group=stoch_group)
smoothK1 = input.int(3,  title="%K1 Smoothing", minval=1, group=stoch_group)
periodD1 = input.int(3,  title="%D1 Smoothing", minval=1, group=stoch_group)
k1 = ta.sma(ta.stoch(k1source, high, low, periodK1), smoothK1)
d1 = ta.sma(k1, periodD1)

periodK2 = input.int(14, title="%K2 Length", minval=1, group=stoch_group)
smoothK2 = input.int(3,  title="%K2 Smoothing", minval=1, group=stoch_group)
periodD2 = input.int(3,  title="%D2 Smoothing", minval=1, group=stoch_group)
k2 = ta.sma(ta.stoch(close, high, low, periodK2), smoothK2)
d2 = ta.sma(k2, periodD2)

periodK3 = input.int(40, title="%K3 Length", minval=1, group=stoch_group)
smoothK3 = input.int(4,  title="%K3 Smoothing", minval=1, group=stoch_group)
periodD3 = input.int(4,  title="%D3 Smoothing", minval=1, group=stoch_group)
k3 = ta.sma(ta.stoch(close, high, low, periodK3), smoothK3)
d3 = ta.sma(k3, periodD3)

periodK4 = input.int(60, title="%K4 Length", minval=1, group=stoch_group)
smoothK4 = input.int(10, title="%K4 Smoothing", minval=1, group=stoch_group)
periodD4 = input.int(10, title="%D4 Smoothing", minval=1, group=stoch_group)
k4 = ta.sma(ta.stoch(close, high, low, periodK4), smoothK4)
d4 = ta.sma(k4, periodD4)

// ==================== DTRS Strategy Settings ====================
var dtrs_group = "DTRS Strategy Settings"
rot_window = input.int(20, "Rotation Window (bars)", minval=5, maxval=100, tooltip="Max bars for sequential rotation to complete (fast→slow)", group=dtrs_group)

// ==================== RSI Divergence Settings ====================
var rsi_group = "RSI Divergence Settings"
rsi_fast_len = input.int(5,  "Fast RSI Length", minval=1, group=rsi_group)
rsi_slow_len = input.int(14, "Slow RSI Length", minval=1, group=rsi_group)

// ==================== Display Settings ====================
var disp_group = "Display Settings"
bool i_showDarkMode      = input.bool(false, "Use Dark Mode", group=disp_group)
bool i_showSignals       = input.bool(true,  "Show K/D Cross Signals", group=disp_group)
bool i_showRotation      = input.bool(true,  "Show Rotation Status", group=disp_group)
bool i_showSequence      = input.bool(true,  "Show Sequential Rotation", group=disp_group)
bool i_showRSIDivergence = input.bool(true,  "Show RSI Divergence", group=disp_group)
bool i_showHolyGrail     = input.bool(true,  "Show Holy Grail Signals", group=disp_group)
bool i_showCounterTrend  = input.bool(true,  "Show Counter-Trend Warnings", group=disp_group)
bool i_showConvergence   = input.bool(true,  "Show Convergence Band", group=disp_group)

// ==================================================================================
// RSI Divergence (standalone)
// ==================================================================================
rsi_f   = ta.rsi(close, rsi_fast_len)
rsi_s   = ta.rsi(close, rsi_slow_len)
rsi_div = rsi_f - rsi_s

// ==================================================================================
// Zone Constants
// ==================================================================================
upperBand = 80
lowerBand = 20

// ==================================================================================
// DTRS Strategy Logic
// ==================================================================================

// --- Quad Alignment ---
allOversold   = d1 < lowerBand and d2 < lowerBand and d3 < lowerBand and d4 < lowerBand
allOverbought = d1 > upperBand and d2 > upperBand and d3 > upperBand and d4 > upperBand

// --- Individual Rotation (first bar of turn in extreme zone) ---
turningUp1 = d1 < lowerBand and d1 > d1[1] and d1[1] <= d1[2]
turningDn1 = d1 > upperBand and d1 < d1[1] and d1[1] >= d1[2]
turningUp2 = d2 < lowerBand and d2 > d2[1] and d2[1] <= d2[2]
turningDn2 = d2 > upperBand and d2 < d2[1] and d2[1] >= d2[2]
turningUp3 = d3 < lowerBand and d3 > d3[1] and d3[1] <= d3[2]
turningDn3 = d3 > upperBand and d3 < d3[1] and d3[1] >= d3[2]
turningUp4 = d4 < lowerBand and d4 > d4[1] and d4[1] <= d4[2]
turningDn4 = d4 > upperBand and d4 < d4[1] and d4[1] >= d4[2]

// --- Sequential Rotation Detection ---
// Track bars since each stochastic turned in its extreme zone
// Bullish: fastest turns first (most bars ago), slowest most recently — all within window
bs_up1 = ta.barssince(turningUp1)
bs_up2 = ta.barssince(turningUp2)
bs_up3 = ta.barssince(turningUp3)
bs_up4 = ta.barssince(turningUp4)

seq_bull = not na(bs_up1) and not na(bs_up2) and not na(bs_up3) and not na(bs_up4)
     and bs_up1 > bs_up2 and bs_up2 > bs_up3 and bs_up3 > bs_up4
     and bs_up4 < rot_window
// Fire only on the bar the sequence completes (when slowest just turned)
seq_bull_trigger = seq_bull and turningUp4

bs_dn1 = ta.barssince(turningDn1)
bs_dn2 = ta.barssince(turningDn2)
bs_dn3 = ta.barssince(turningDn3)
bs_dn4 = ta.barssince(turningDn4)

seq_bear = not na(bs_dn1) and not na(bs_dn2) and not na(bs_dn3) and not na(bs_dn4)
     and bs_dn1 > bs_dn2 and bs_dn2 > bs_dn3 and bs_dn3 > bs_dn4
     and bs_dn4 < rot_window
seq_bear_trigger = seq_bear and turningDn4

// --- Holy Grail: Quad alignment + RSI divergence confirmation ---
holy_grail_bull = allOversold and rsi_div > 0
holy_grail_bear = allOverbought and rsi_div < 0

// --- Counter-Trend Protection ---
// Slowest stuck in extreme while fastest at opposite extreme
ct_bull_danger = d4 < lowerBand and d4 <= d4[1] and d1 > upperBand
ct_bear_danger = d4 > upperBand and d4 >= d4[1] and d1 < lowerBand

// --- Convergence Band ---
convergence = (d1 * 1.0 + d2 * 2.0 + d3 * 3.0 + d4 * 4.0) / 10.0
spread = (math.abs(d1 - convergence) + math.abs(d2 - convergence) + math.abs(d3 - convergence) + math.abs(d4 - convergence)) / 4.0
conv_color = color.from_gradient(spread, 3.0, 20.0, color.new(color.white, 20), color.new(color.gray, 70))

// --- K/D Cross Signals in extreme zones ---
bullCross = ta.crossover(k1, d1) and d1 < lowerBand
bearCross = ta.crossunder(k1, d1) and d1 > upperBand

// ==================================================================================
// Background Color
// ==================================================================================
darkMode_clr  = color.rgb(0, 0, 0, 0)
lightModeDown = color.new(color.rgb(241, 24, 24), 90)
lightModeUp   = color.new(#02a710, 90)

brokerage1_trend_dir_fma = ta.ema(close, 21)
brokerage1_trend_dir_sma = ta.ema(close, 50)
brokerage1_trend_dir     = brokerage1_trend_dir_fma > brokerage1_trend_dir_sma ? "Up" : "Down"

ct_warn = i_showCounterTrend and (ct_bull_danger or ct_bear_danger)
bgcolor(ct_warn ? color.new(color.orange, 85) : i_showDarkMode ? darkMode_clr : brokerage1_trend_dir == "Up" ? lightModeUp : lightModeDown)

// ==================================================================================
// Grid Layout
// ==================================================================================
onehundredLine = 100
ninetyLine     = 90
tenLine        = 10
midBand        = 50
zeroLine       = 0

onehundred = hline(onehundredLine, "100 Line",   color=color.rgb(120, 123, 134, 50), linestyle=hline.style_solid)
ninety     = hline(ninetyLine,     "Ninety Line", color=color.rgb(120, 123, 134, 50), linestyle=hline.style_dashed)
eighty     = hline(upperBand,      "Upper Band",  color=color.rgb(120, 123, 134, 50), linestyle=hline.style_solid)
fifty      = hline(midBand,        "Mid Band",    color=color.rgb(120, 123, 134, 50), linestyle=hline.style_dashed)
twenty     = hline(lowerBand,      "Lower Band",  color=color.rgb(120, 123, 134, 50), linestyle=hline.style_solid)
ten        = hline(tenLine,        "Ten Line",    color=color.rgb(120, 123, 134, 50), linestyle=hline.style_dashed)
zero       = hline(zeroLine,       "Zero Line",   color=color.rgb(120, 123, 134, 50), linestyle=hline.style_solid)

// Zone fills — overbought (80-100) = RED, oversold (0-20) = GREEN
fill(onehundred, eighty, color=color.new(color.red, 92))
fill(twenty, zero, color=color.new(color.green, 92))

// ==================================================================================
// Plots — Featured: D1 (9,3,3 Fast Stochastic)
// ==================================================================================

// K line for crossover visibility
plot(k1, title="Stoch K1", color=color.new(color.white, 40), linewidth=1)

// D line glow + shadow
plot(d1, title="Stoch D1 Glow", linewidth=2, color=color.rgb(125, 249, 255, 0))
plot(d1, title="Stoch D1",      linewidth=1, color=color.rgb(50, 50, 50, d1))

// Convergence band
plot(i_showConvergence ? convergence : na, title="Convergence", color=conv_color, linewidth=1, style=plot.style_line)

// RSI divergence subtle histogram at midline
rsi_div_clamped = math.max(-2.0, math.min(2.0, rsi_div / 15.0))
rsi_div_plot    = 50.0 + rsi_div_clamped
rsi_div_color   = rsi_div > 0 ? color.new(color.green, 60) : color.new(color.red, 60)
plot(i_showRSIDivergence ? rsi_div_plot : na, title="RSI Div", style=plot.style_histogram, color=rsi_div_color, linewidth=2, histbase=50)

// Quad alignment circles
plot(allOversold ? zeroLine : na, style=plot.style_circles, color=color.green, linewidth=2, title="All Oversold")
plot(allOverbought ? onehundredLine : na, style=plot.style_circles, color=color.red, linewidth=2, title="All Overbought")

// K/D cross signals in extreme zones
plotshape(i_showSignals and bullCross, style=shape.triangleup,   location=location.bottom, color=color.green, size=size.tiny, title="Bull K/D Cross")
plotshape(i_showSignals and bearCross, style=shape.triangledown, location=location.top,    color=color.red,   size=size.tiny, title="Bear K/D Cross")

// Rotation status — individual turn detection for featured stochastic
plotshape(i_showRotation and turningUp1, style=shape.labelup,   location=location.bottom, color=color.new(color.green, 30), text="TURN", textcolor=color.white, size=size.tiny, title="Turning Up")
plotshape(i_showRotation and turningDn1, style=shape.labeldown, location=location.top,    color=color.new(color.red, 30),   text="TURN", textcolor=color.white, size=size.tiny, title="Turning Down")

// Sequential rotation — fires when all 4 have turned in order (fast→slow)
plotshape(i_showSequence and seq_bull_trigger, style=shape.diamond, location=location.bottom, color=color.new(color.green, 0), text="SEQ", textcolor=color.white, size=size.small, title="Sequential Bull Rotation")
plotshape(i_showSequence and seq_bear_trigger, style=shape.diamond, location=location.top,    color=color.new(color.red, 0),   text="SEQ", textcolor=color.white, size=size.small, title="Sequential Bear Rotation")

// Holy Grail — quad alignment + RSI divergence
plotshape(i_showHolyGrail and holy_grail_bull, style=shape.flag, location=location.bottom, color=color.new(#FFD700, 0), text="HG", textcolor=color.white, size=size.small, title="Holy Grail Bull")
plotshape(i_showHolyGrail and holy_grail_bear, style=shape.flag, location=location.top,    color=color.new(#FFD700, 0), text="HG", textcolor=color.white, size=size.small, title="Holy Grail Bear")

// Counter-trend warning
plotshape(i_showCounterTrend and ct_bull_danger, style=shape.xcross, location=location.top,    color=color.orange, size=size.tiny, title="Counter-Trend Bull Danger")
plotshape(i_showCounterTrend and ct_bear_danger, style=shape.xcross, location=location.bottom, color=color.orange, size=size.tiny, title="Counter-Trend Bear Danger")

// ==================================================================================
// Alert Conditions
// ==================================================================================
alertcondition(allOversold,       "Quad Oversold",                "All 4 stochastics below 20 — rotation buy zone")
alertcondition(allOverbought,     "Quad Overbought",              "All 4 stochastics above 80 — rotation sell zone")
alertcondition(bullCross,         "Bull K/D Cross (9/3)",         "K1 crossed above D1 in oversold zone")
alertcondition(bearCross,         "Bear K/D Cross (9/3)",         "K1 crossed below D1 in overbought zone")
alertcondition(turningUp1,        "Rotation Turning Up (9/3)",    "Fast stoch turning up from oversold")
alertcondition(turningDn1,        "Rotation Turning Down (9/3)",  "Fast stoch turning down from overbought")
alertcondition(seq_bull_trigger,  "Sequential Rotation Buy",      "All 4 stochastics turned up in sequence (fast to slow)")
alertcondition(seq_bear_trigger,  "Sequential Rotation Sell",     "All 4 stochastics turned down in sequence (fast to slow)")
alertcondition(holy_grail_bull,   "Holy Grail Buy",               "Quad oversold + RSI bullish divergence")
alertcondition(holy_grail_bear,   "Holy Grail Sell",              "Quad overbought + RSI bearish divergence")
alertcondition(ct_bull_danger,    "Counter-Trend Warning (Long)", "60/10 stuck below 20 while 9/3 above 80 — exit longs")
alertcondition(ct_bear_danger,    "Counter-Trend Warning (Short)","60/10 stuck above 80 while 9/3 below 20 — exit shorts")

Overview

Quad Rotation 9 3 plots the 9/3 stochastic K and D lines in a separate pane with oversold and overbought zones, K/D cross triangles inside extreme zones, and a convergence band weighting all four D lines. Optional layers include sequential rotation, an RSI divergence check, alignment and counter-trend warnings. Source and all stochastic settings are adjustable.

Details

Published by

rubbermetal on GitHub

Code credit

claygrace74, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence

Markets

Any symbol

Timeframes

M15-H1

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
Stoch 9/3 Sourcesourceclosek1source
%K1 Lengthint9periodK1
%K1 Smoothingint3smoothK1
%D1 Smoothingint3periodD1
%K2 Lengthint14periodK2
%K2 Smoothingint3smoothK2
%D2 Smoothingint3periodD2
%K3 Lengthint40periodK3
%K3 Smoothingint4smoothK3
%D3 Smoothingint4periodD3
%K4 Lengthint60periodK4
%K4 Smoothingint10smoothK4
Show all 24 settings
SettingTypeDefaultVariable
%D4 Smoothingint10periodD4
Rotation Window (bars)int20rot_window
Fast RSI Lengthint5rsi_fast_len
Slow RSI Lengthint14rsi_slow_len
Use Dark Modeboolfalsei_showDarkMode
Show K/D Cross Signalsbooltruei_showSignals
Show Rotation Statusbooltruei_showRotation
Show Sequential Rotationbooltruei_showSequence
Show RSI Divergencebooltruei_showRSIDivergence
Show Holy Grail Signalsbooltruei_showHolyGrail
Show Counter-Trend Warningsbooltruei_showCounterTrend
Show Convergence Bandbooltruei_showConvergence
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

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

This indicator calculates the MACD oscillator from a configurable source with fast and slow lengths, then plots the histogram, MACD line, and signal line in a separate pane. It detects regular bullish divergences (price lower lows with oscillator higher lows),

Indicator v5 Oscillators & momentumDivergence
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]
218 stars

This indicator calculates the Relative Strength Index (RSI) across four user-selected timeframes and plots the results in a separate pane. It identifies regular bullish and bearish divergences between price pivot points and the primary timeframe RSI value. Add

Indicator v6 Oscillators & momentumDivergence
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe RSI with Divergence

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

RSI [SystemAlpha]

by iamc1oud
56 stars

This indicator plots a standard Relative Strength Index (RSI) in a separate pane alongside customizable overbought and oversold threshold levels with shaded fills. It identifies pivot highs and lows on the oscillator to detect regular and hidden bullish and be

Indicator v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of RSI [SystemAlpha]
55 stars

This indicator calculates a 14-period RSI from close and plots it in a separate pane with dotted overbought and dashed oversold lines at 70 and 30. It marks bullish divergence when a five-bar pivot low in price is lower than the price twenty bars earlier while

Indicator v6 Oscillators & momentumDivergence
Updated 6 months ago · Apache-2.0 GitHub repository of RSI Divergence 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