Reverse Stochastic [BApig Gift]

Reverse Indicator calculation: Oscillators value output are calculated based on the input price (open, high, low or close). This means certain input price can generate the according to the output value of the oscillator. They are both sides of an equation, the process is reversible. Once we know one side of the equation, we can get the value of the other side. We can turn any oscillator into a moving average like indicator on price. This indicator is the reverse calculation of stochastic oscillator. They provide users the exact price level input needed for the stochastic to reach a certain value (crossover, oversold, overbought).


1. Background. @Motgench was the first to introduce the idea of a reverse stochastic coded in Pinescript. Now we see people trying to steal our original idea and come up with cheap knock off copies and charge people a high price: namely The Caretaker (@The_Caretaker) and Krown (@Crypto-Crown). They are stealing people's original ideas and copying open-source scripts in their paid scripts (especially targeting us).

They also rewrite narratives and twist history on the originality of scripts and claim the wrong usage of indicators when they don't know their
functions. We have decided to release our reverse stoch for free to protect people from paying for a bad copy and being misled by people with bad intentions. We also want to prove that this is not a competition of sales; just us trying to do the right thing for the community.

We are here to tell people: do not trust the words of those who steal ideas and copy code. Because they never understand the calculations under the script, they may give you false and misleading information on how to use the indicators.

2. A new approach. After discussions with @Wugamlo, we found some problems in the reverse stoch calculations that we didn't mention before. We have found that there are different approaches to calculate reverse stochastic . You can set the %K = %D when it crosses, or you can decompose %D into sma (%K) on the right side. So, we added Wugamlo's approach to this indicator. The current KD dynamic is when %K = %D, so it may stick closer to price and more reactive in real-time. The current KD static is when we decompose the %D, and it is more accurate in historical calculations.

3. Issues with the Reverse Stochastic . One of the important reasons why we decided to not charge people for this script is because we discovered that no matter which approach we took, the reverse stoch value may produce errors. The main reason is that stochastic calculation depends not only on closing price, but also high-low . For example, when the reverse value creates a higher-high or higher-low, the original calculation in the reverse stoch doesn't update to that high or low, so even if the price reaches that point, it might not cross. Therefore, the calculation of Reverse Stoch may be unstable and sometimes gives false values, particularly when you see very high or low value overshoot. It may work better when a cross is near.
For Reverse RSI and Reverse Wavetrend, the issues described above don’t apply because we calculate them based on the closing price. Reverse Fisher is subtly affected but it sticks with price more closely so the effect is not significant.
We decided the stochastic is not a suitable indicator for reverse engineering, and we don't recommend people blindly read it and trust its value.

4. Christmas is near. This script is a gift to the community. For the people who bought our traditional revolution package, we will replace the reverse stochastic with another cool indicator. We will be releasing paid script for free every Christmas.

Merry Christmas.

The Rest is Similar to the invite only script descriptions:



We provide two ways of reverse calculation. Current reverse value and forecasted value.
Current K and Current D option is just the simple reverse calculation of stochastic .

However, we found due to stochastic oscillator’s calculation (based on high, low and close), the indicator repaints or update value too much. For example, when price moves up, the reverse value also moves up a lot, it’s too reactive to the current price. So we made the reverse stochastic even better by forecasting the value by the open of next bar. This makes the indicator much more stable to the current price and allows you to anticipate the crossing of the stochastic oscillator one step ahead.

Even though it's "forecast", it's just simple math trick. The value of oscillator is calculated by the length of the sample size. When it does the calculation on the next bar, it will erase the last bar in the sample and add a new bar which equals to the one bar ago closing price. By moving all the data of price forward by one bar we produce a 100% accurate forecast of the value the indicator will produce by the closing of the current bar or open of next bar.

One usage of Using Forecast K and Forecast D is that you can anticipate the turning point one bar ahead:
One Bar before the actual stochastic cross
When they actually crossed

All stochastic display, The forecast K and D leads the current K and D by one bar, it's almost like one bar offset ahead.

Now we can apply this forecast VS original stochastic concept on reverse stochastic . It makes even more impact . It reduces lag and overshoot. It's also more stable to changes in the current price. So the reversal price value won't change too much intrabar.

Reverse Stoch Forecast VS Reverse Stoch Original

Reverse Stoch Forecast leads Reverse Stoch Current one bar ahead

One bar before stoch cross

After they both cross

Our recommendation in K,D options:
For people who want to anticipate turning point earlier, they should use forecast K and forecast D options.
For people who like more confirmation, they should use current K and current D options. (Static more stable and accurate in history, Dynamic more reactive in real time)

Warning: For forecast value, even though its 100% accurate. The value can still change due to the next bar value. Eg: Current Bar close below forecast level, the next bar can close above to reverse the result.

Settings functions explanation:

K,D, and Smooth length is the same as stochastic K,D and smooth length

"Show stochastic cross value panel" and "Show overbought and oversold Panel" allows users to display or hide a panel with stoch crossing or overbought and oversold price.

"Overbought and Oversold Style" changes the display of the overbought and oversold price of stochastic .

Option "Line Levels" plots horizontal lines of the price when stochastic K reaches overbought and oversold level.

Option "Bands" plots the historical running value of the price when stochastic K reaches overbought and oversold level. The user should tick off log display of the chart when they choose "Bands" option.

'Line Levels" and "Bands" have the same current value just different displays.

User can choose to plot or hide the overbought and oversold price by ticking and unticking the "plot overbought price" and "plot oversold price"
They can also adjust the oversold and overbought value of stochastic (Default is 80 and 20).

"Stoch Cross Smoothing" enables users to smooth out the reverse stochastic . It turns the reverse stoch into a close to moving average smooth filter.
User can adjust the length of smoothing to change the smoothness of the filter.

"Plot Stoch Historical Value" the stochastic value when it crosses in the past on the running reverse stoch .
User can choose the display K or D value when it crosses.

"Plot Crossing Circles" plots circles on the reverse stoch when stoch crosses.

There's a bug in Tradingview label system. When the background of the label is transparent, the text will get burry when we scroll in and out on the chart. When this happens, changing any settings on the panel could refresh the text display. It could also be avoided by ticking the "dark background" setting to make the background not transparent.

For prices that require more decimal places, users can type in the decimals places they want in the “decimal” setting.
Release Notes: Added Warning Crosses For When it's impossible to cross over the stochastic oscillator to the other side.
Added stepline function

As we mentioned above, there's some serious limitations about reverse stochastic. Because when price reaches the reverse stoch value, the stochastic does not always cross.

There's a limit for stochastic value. We know the highest value for %K before smooth is 100 and lowest value is 0.
After smoothing of %K and %D. The max and min value range for stoch is even smaller.

The reverse stochastic indicator is only accurate if the value it provides doesn't create a new high or new low in price.

When there's a new high in price in the lookback period we choose, the stoch k = 100. When there's a new low in price, stoch k = 0.
For %K the highest value it can get after smooth is k + k + ... k / smoothk. And k = 100 when the value is max.
MaxK = 100 + k + k + ... k / smoothk
MinK = 0 + k + k + ... k / smoothk

%D is the smoothed %K. Therefore it also has a limit.
MaxD = MaxK + %k + %k + ... %k / smoothD
MinD = MinK + %k + %k + ... %k / smoothD

So when there's a new high in price, we know the value of MaxK and MaxD, MinK and MinD.
If MaxK < MaxD, then it's impossible for K to cross up above D
If MinK < MinD, then it's impossible for K to cross below D

This Chart Displays when there's impossible cross
the Panel under is displaying maxK, maxD, minK and MinD
The green background means the reverse stoch value creates new high, the red background means the reverse stoch value creates new low
The 0 and 1 blue lines displays the impossible cross situation. 1 means impossible, 0 means possible.
As you can see, most of the time when reverse stoch creates a new high or low in price, the stoch is impossible to cross

You can also see from the chart. The impossible cross situation which is displayed by yellow crosses happens quite often. In fact, we backtest the resutls. It happens about 30% of the time. That's why the reverse stoch function calculation is highly unstable and it may give the wrong value when it's actually impossible for stoch to reverse. Make sure you read the descriptions, use the correct version and have a deep understanding of the reverse stoch calculation before you use.
Release Notes: Fixed Chart Descriptions
Remove from Favorite Scripts Add to Favorite Scripts
Our Website🅱🅰🐷:

Sign up on our website to get access to our indicators.

Join Our Discord for further discussions:


Another treat from BaPig!!! By far adding the most value to TV community. Definitely do not trust @TheCaretaker or @Crypto-Crown, like Bali said they are stealing original ideas and putting out inferior products and selling them, shame on them....
+15 Reply
This needs to be on the featured script of the month list.

Nice work, thank you ^^
+9 Reply
Merry Christmas and Happy Holidays, indeed!

Once again, the makers of Better MAths-based trading indicators have given the trading community here on TV a rich and POWFUL gift with the release of the Reverse Stoch indicator! Santa's Sleighin' 'em fast this year!

Added up all together, with just the current Free BApig indicators available on TradingView, anyone can have a massive edge built in to their trades, using just the statistics and probabilities and other key indicators used in trading volatility.

Shame on the Naughty copycats who give no credit where credit is due, or pretend to be one thing when they are another.

Kudos to @balipour and @Motgench for doing another great deed for the TV trading community! They and their crew are truly on the cutting edge, pushing the envelope and giving everyday traders like you and me a leg up, where before we were blindfolded by the carefully crafted smoke and mirrors of the Bad MAFFS Voodoo TA Scam that permeates the trading industry from top to bottom, backed by massive financial incentives.

Don't just take my word for it. Try the Free Indicators they have published. Learn how to read and trade the best TV indicators built with Better MAFFS! :) Compare them to your favorite "TA" indicators. See the difference for yourself. Enjoy!
+7 Reply
MVP, happy holidays guys!
+7 Reply
These guys bring more value to this community than any other creators that I know of. They continue to build things the right way and give away to much for free. You should feel lucky to have access to these high level indicators. Thanks once again for raising the bar. Much respect BaPig.
+5 Reply
Great work! You are making a lot of people very happy.
+5 Reply
Christmas come early! BaPig is the gift that keeps on giving.
+5 Reply
Bali you're the man !

Happy Holidays
+4 Reply
Dlu Dlu
Pig too
+4 Reply
Bali and Pig are modern day Robin-hoods. Giving to the poor. As always great shit. THANKS GUYS.
+4 Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out