Indicator · Pine Script v6 · Own pane

Reverse Stochastic

by mushroom-men-Trading

This indicator converts a smoothed stochastic oscillator back into price levels.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code154
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update9 months ago25 Jan 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

154 lines of Pine Script v6 from Indicators/indicators/reversals/reverse stochs.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

reverse stochs.pine
//@version=6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

///////////////////////////////////////////////////////////////////////////////

indicator('Reverse Stochastic', 'RSTOCH', false, format.price, precision = 2)

///////////////////////////////////////////////////////////////////////////////
// Inputs

TextBoxOn = input(true, 'Info Box On')
DecPlaces = input.int(2, 'Prices Decimal Places', minval = 0, maxval = 10)
BoxOffSet = input.int(5, 'Info Box Offset', minval = 1, maxval = 50)

///////////////////////////////////////////////////////////////////////////////
// Stoch Inputs

Src = input(close, 'Stochastic Source')

LenK = input.int(14, 'Stochs K Length', minval = 1, maxval = 200)
LenD = input.int(3, 'Stochs D Length', minval = 1, maxval = 200)
SmthK = input.int(6, 'Stochs Smooth', minval = 1, maxval = 200)

///////////////////////////////////////////////////////////////////////////////
// Scale Zone Inputs & Variable Declarations

ScaleHi = 100
BullHi = input.int(80, 'Bull Control Zone High', minval = 1)
BullLo = input.float(61.8, 'Bull Control Zone Low', minval = 1)
MidLine = input.int(50, 'Midline', minval = 1)
BearHi = input.float(38.2, 'Bear Control Zone High', minval = 1)
BearLo = input.int(20, 'Bear Control Zone Low', minval = 1)
ScaleLo = 0

///////////////////////////////////////////////////////////////////////////////
// Variable Declarations

GMSmooth = 6
Trend = 25
MaxTrend = 10

var label KDXLabel = na
var label GMLabel = na
var string GMLabelText1 = ''
var string KDXLabelText = ''
var string LabelText = ''

LabelXLoc = time_close + BoxOffSet * (time_close - time_close[1])

///////////////////////////////////////////////////////////////////////////////
// Function Declarations

///// Decimal Truncation

TruncdNum(Val, DecPl) =>
    Fact = math.pow(10, DecPl)
    int(Val * Fact) / Fact

////// Reverse Stoch 

f_OnChartStoch(LenK, LenD, SmthK) =>
    var X = 0.0
    var K = 0.0
    var D = 0.0
    var KSum = 0.0
    var DSum = 0.0
    var RStoch = 0.0
    X := ta.stoch(close, high, low, LenK)
    K := ta.sma(X, SmthK)
    D := ta.sma(K, LenD)
    KSum := math.sum(X[1], SmthK - 1)
    DSum := math.sum(K[1], LenD - 1)
    RStoch := (DSum * SmthK + KSum - KSum * LenD) * (ta.highest(high, LenK) - ta.lowest(low, LenK)) / ((LenD - 1) * 100) + ta.lowest(low, LenK)
    RStoch

OnChartValue(LenK, LenD, SmthK, ScaleValue) =>
    var X = 0.0
    var K = 0.0
    var D = 0.0
    var KSum = 0.0
    var DSum = 0.0
    var RScaleVal = 0.0
    X := ta.stoch(close, high, low, LenK)
    K := ta.sma(ScaleValue, SmthK)
    D := ta.sma(K, LenD)
    KSum := math.sum(X[1], SmthK - 1)
    DSum := math.sum(K[1], LenD - 1)
    RScaleVal := (DSum * SmthK + KSum - KSum * LenD) * (ta.highest(high, LenK) - ta.lowest(low, LenK)) / ((LenD - 1) * 100) + ta.lowest(low, LenK)
    RScaleVal

///////////////////////////////////////////////////////////////////////////////
// Stoch Calcs

BarHi = close > open ? close : open

BarLo = close < open ? close : open

///////////////////////////////////////////////////////////////////////////////
// On Chart Stochastic & Scale Calcs

OnChartStoch = f_OnChartStoch(LenK, LenD, SmthK)

OnChartScaleHi = OnChartValue(LenK, LenD, SmthK, ScaleHi)
OnChartBullHi = OnChartValue(LenK, LenD, SmthK, BullHi)
OnChartBullLo = OnChartValue(LenK, LenD, SmthK, BullLo)
OnChartMidLine = OnChartValue(LenK, LenD, SmthK, MidLine)
OnChartBearHi = OnChartValue(LenK, LenD, SmthK, BearHi)
OnChartBearLo = OnChartValue(LenK, LenD, SmthK, BearLo)
OnChartScaleLo = OnChartValue(LenK, LenD, SmthK, ScaleLo)

Delta = OnChartStoch - close
K = ta.sma(ta.stoch(close, high, low, LenK), SmthK)
D = ta.sma(K, LenD)

///////////////////////////////////////////////////////////////////////////////
// Compute Info Label

StdKX = Delta > 0 ? 'Std Cross Up Above' : 'Std Cross Down Below'

StochCrossText = '\n' + StdKX + '\n\n' + str.tostring(TruncdNum(OnChartStoch, DecPlaces))

StochZoneText = K > BullHi ? 'Critical Bull Zone' : K > BullLo ? 'Bull Zone' : K > BearHi ? 'Neutral Zone' : K > BearLo ? 'Bear Zone' : 'Critical Bear Zone'

InfoBox = StochZoneText + '\n\n' + StochCrossText

///////////////////////////////////////////////////////////////////////////////
// InfoBox Plot

if TextBoxOn
    GMLabel := label.new(LabelXLoc, K, InfoBox, xloc.bar_time, yloc.price, #000000ff, label.style_label_left, color.white)
    GMLabel

label.delete(GMLabel[1])

///////////////////////////////////////////////////////////////////////////////
// Stoch Plots & Fills

plot(K, '%K', color.new(color.aqua, 10), 2, plot.style_line)
plot(D, '%D', color.new(color.fuchsia, 10), 2, plot.style_line)

///////////////////////////////////////////////////////////////////////////////
// Scale Level Plots and Zone Fills

h0 = hline(100, 'Upper Band', color = color.red, linestyle = hline.style_dotted, linewidth = 2)
h1 = hline(0, 'Lower Band', color = color.red, linestyle = hline.style_dotted, linewidth = 2)
h2 = hline(80, 'Upper Band', color = #606060)
h3 = hline(20, 'Lower Band', color = #606060)
h4 = hline(55, 'Upper Band', color = #606060)
h5 = hline(45, 'Lower Band', color = #606060)
//fill(BullHiPlot, BullLoPlot, color.new(color.aqua, 75), 'Bull Control Zone')
//fill(BearHiPlot, BearLoPlot, color.new(color.purple, 75), 'Bear Control Zone')

///////////////////////////////////////////////////////////////////////////////
// End

Overview

Reverse Stochastic calculates a reverse stochastic from close, high, and low using configurable K length, D length, and smoothing, then maps fixed scale points, including bull and bear control zones and a midline, to corresponding prices. An optional info box shows values with a chosen decimal precision and horizontal offset. It draws in a separate pane. The provided code ends before the plot calls, so exact drawing details are incomplete.

Details

Published by

mushroom-men-Trading on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Support & resistance

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
Info Box OnbooltrueTextBoxOn
Prices Decimal Placesint2DecPlaces
Info Box Offsetint5BoxOffSet
Stochastic SourcesourcecloseSrc
Stochs K Lengthint14LenK
Stochs D Lengthint3LenD
Stochs Smoothint6SmthK
Bull Control Zone Highint80BullHi
Bull Control Zone Lowfloat61.8BullLo
Midlineint50MidLine
Bear Control Zone Highfloat38.2BearHi
Bear Control Zone Lowint20BearLo
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

114 stars

This indicator combines a scaled Forecast Oscillator with a Point of Force state detector. The Forecast Oscillator calculates the percentage deviation of price from its linear regression curve and normalizes the output between 0 and 1, plotting a line in a sep

Indicator v4 Oscillators & momentumSupport & resistance Repaints

CCI DC

by be-thomas
65 stars

This indicator plots the Commodity Channel Index in a separate pane and surrounds it with a Donchian channel whose lookback length changes with volatility. It measures volatility as a ratio of short and long ATR values, then ranks that ratio and shortens or le

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 days ago · GPL-3.0 GitHub repository of CCI DC

WaveTrend 3D

by nersent
29 stars

WaveTrend 3D is a redesigned oscillator that implements the classic WaveTrend algorithm with kernel-based regression for trend reversal confirmation and multi-timeframe support. It calculates a smoothed oscillator line and displays a symmetrical three-dimensio

Indicator v5 Oscillators & momentumDivergence
Updated 11 months ago · Custom licence GitHub repository of WaveTrend 3D

Benso Pendulum

by benso87
24 stars

Benso Pendulum is an indicator that plots a customizable Relative Strength Index (RSI) oscillator in a separate pane on the price chart. It calculates the RSI using the specified source and period, applying dynamic colors that change based on overbought and ov

Indicator v5 Oscillators & momentumSupport & resistance
Updated 4 years ago · MPL-2.0 GitHub repository of Benso Pendulum
9 stars

This indicator plots currency strength values for EUR, USD, JPY, GBP, CHF, AUD, CAD, NZD and optionally XAU or XAG on a separate pane. It computes strength by comparing current pair closes to daily closes using broker-specific data from OANDA, FX or FOREXCOM.

Indicator v4 Oscillators & momentumSupport & resistance Repaints
Updated 5 years ago · None stated GitHub repository of 4th Dimension Currency Strength

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