Compare the inputs before comparing signals
For length N, raw Stochastic is 100 × (close − lowest low) / (highest high − lowest low), using the latest N bars. Smooth that result with an SMA to obtain %K, then apply another SMA to %K for %D. RSI is 100 − 100 / (1 + average gain / average loss), where gains and losses come from consecutive closes and use Wilder smoothing. For a nonzero sum, the equivalent RSI expression is 100 × average gain / (average gain + average loss).
- The settings row follows the linked TradingView help pages. Inspect the actual Inputs tab, including saved templates. Record all three Stochastic parameters by name; shorthand such as 14,3,3 can hide their order.
- For a raw-value comparison, explicitly set Stochastic K smoothing to 1 and compare K with the RSI line. Hide D and the additional RSI moving average so that they cannot be mistaken for the measurements under test.
| Comparison | Stochastic | RSI |
|---|
| Price information | Close plus window highs and lows. | Changes in the selected source; close in this comparison. |
| Typical reference levels | 20 and 80. | 30 and 70. |
| Help-page settings | K length 14, K smoothing 3, D length 3. | RSI length 14, source close. |
| Optional smoothing | K smoothing changes K; D averages K. | The separate Smoothing setting adds an average of RSI. |
One price sequence, two different answers
This is a hypothetical calculation, not market data or a backtest. Use length 5 for both indicators to keep the arithmetic visible, Stochastic K smoothing 1, and no extra RSI moving average. The first RSI value uses the arithmetic averages of the first five changes. Thereafter each average updates as (4 × previous average + current gain or loss) / 5. A flat close supplies zero to both averages. Opens do not enter these calculations.
- At bar 5, the five close changes are +2, −1, +2, −1, +2. Average gain is 6 / 5 = 1.2 and average loss is 2 / 5 = 0.4. RSI is 100 × 1.2 / 1.6 = 75.
- At that same bar, the five-bar high is 105 and low is 99. Raw K is 100 × (104 − 99) / (105 − 99) = 83.33. The values answer different questions on identical input bars.
| Bar | Close | High | Low |
|---|
| 0 | 100 | 101 | 99 |
| 1 | 102 | 103 | 99 |
| 2 | 101 | 103 | 100 |
| 3 | 103 | 104 | 100 |
| 4 | 102 | 104 | 101 |
| 5 | 104 | 105 | 101 |
| 6 | 103 | 105 | 102 |
| 7 | 103 | 104 | 102 |
| 8 | 103 | 104 | 102 |
| 9 | 105 | 106 | 102 |
Why a flat close can move Stochastic but leave RSI unchanged
Values below use the preceding data and retain full precision until display. At bars 7 and 8, both RSI averages decay by the same factor, so their ratio stays unchanged. At bar 8, the old low of 100 leaves the Stochastic window. The new low is 101, which changes the close position even though the close is still 103.
- To reproduce bar 6: gain = (4 × 1.2 + 0) / 5 = 0.96; loss = (4 × 0.4 + 1) / 5 = 0.52. RSI = 100 × 0.96 / 1.48 = 64.86.
- To reproduce bar 8: raw K = 100 × (103 − 101) / (105 − 101) = 50. The RSI ratio is still 0.6144 / (0.6144 + 0.3328), or 64.86.
- A completely flat high-low window makes the raw Stochastic fraction undefined. Treat that as a separate edge case. Similarly, state how a custom RSI handles zero average loss or both averages being zero; do not infer a neutral reading from division by zero.
| Bar | Window low / high | Avg gain / loss | Raw K | RSI |
|---|
| 5 | 99 / 105 | 1.2000 / 0.4000 | 83.33 | 75.00 |
| 6 | 100 / 105 | 0.9600 / 0.5200 | 60.00 | 64.86 |
| 7 | 100 / 105 | 0.7680 / 0.4160 | 60.00 | 64.86 |
| 8 | 101 / 105 | 0.6144 / 0.3328 | 50.00 | 64.86 |
| 9 | 101 / 106 | 0.8915 / 0.2662 | 80.00 | 77.00 |
Thresholds describe states; crossing rules define events
In the example, bar 5 exceeds the usual upper levels for both indicators. Bar 6 falls below both. That is one matched event, not evidence of predictive accuracy. At bar 9, K equals 80 while RSI exceeds 70. A strict "greater than" test therefore differs from a "greater than or equal" test before any question about trade quality arises.
- For an initial controlled comparison, use the same length and the same threshold pair, such as 30/70, with identical crossing and equality rules. This isolates a chosen numerical rule; equal thresholds still do not represent equal price conditions.
- Run a second, separately labeled comparison using the conventional 20/80 for Stochastic and 30/70 for RSI. That changes the threshold rule as well as the indicator, so keep its results separate.
- A trend can repeatedly make new highs and close near them. Stochastic can remain high while gains keep RSI high. Selling solely because either is high assumes a reversal the calculation has not established.
- Specify any trend condition before testing, including its timeframe and confirmation rule. Evaluate range periods and trend periods separately. Changing that filter after seeing losses creates a different experiment.
Check both lines on the same completed TradingView bar
Add the built-in Stochastic and RSI to one standard candlestick chart. Match the symbol, exchange feed, session, interval, and evaluation dates. Use the same closed candle in the Data Window. The current high, low, and close can change while a bar is open, so an apparent threshold crossing may disappear before the close.
- Record length, source, K smoothing, and D length alongside the numbers. A length of 14 on an hourly chart summarizes different observations from 14 on a daily chart.
- Load enough preceding history for RSI initialization, then compare a stable evaluation segment. The arithmetic seed in this short example is explicit; a chart with earlier history need not start at the same RSI value.
- A chart-bar close rule does not confirm an unfinished higher-timeframe input. If you introduce another timeframe, specify its confirmation separately.
- First compare values and signal timestamps. Only after those agree with the intended rules should a strategy comparison add entries, exits, sizing, order timing, commission, and slippage. An indicator comparison alone contains no trade result.
Turn the comparison into a reviewable script specification
Use the Pine Script AI Coding Agent to draft a panel with both measurements and named input controls. Ask it to show the window high and low, average gain and loss, raw K, and RSI in the Data Window. Include the length-5 calculation above as a reference case, then check generated code and chart values before adding strategy orders.
- Specify whether the trigger tests K, a smoothed K, a K/D cross, or RSI. Comparing a K/D crossover with an RSI threshold crossing tests two different signal designs.
- Keep bar confirmation, equality handling, warm-up, and zero-denominator behavior explicit. Request a signal log first; ask for a strategy only after defining exits and trading costs.