//@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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Info Box On
bool
true
TextBoxOn
Prices Decimal Places
int
2
DecPlaces
Info Box Offset
int
5
BoxOffSet
Stochastic Source
source
close
Src
Stochs K Length
int
14
LenK
Stochs D Length
int
3
LenD
Stochs Smooth
int
6
SmthK
Bull Control Zone High
int
80
BullHi
Bull Control Zone Low
float
61.8
BullLo
Midline
int
50
MidLine
Bear Control Zone High
float
38.2
BearHi
Bear Control Zone Low
int
20
BearLo
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.
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
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
This indicator tracks intermediate market cycles inspired by Linda Raschke's approach using daily NYSE TICK statistics. It fetches daily high, low, and close values for the TICK index via security requests and computes moving averages of the highs and lows. It
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
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
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.