RSI ROC Conditions: Direction States, Not Acceleration
This classifier compares the current RSI with the two preceding RSI values. Green means the current reading is strictly above both; red means it is strictly below both. Gray covers everything else, including unavailable comparisons. These are relative-level states, not a measurement of acceleration or a forecast of returns.
Inspect the Pine ScriptThe two differences and three states
Let R be ta.rsi(close, length). The helper calculates d1 = R − R[1] and d2 = R − R[2]. Both differences are measured in RSI points. Despite the ROC name, neither divides by a prior value or computes a percentage return.
bullish = d1 > 0 and d2 > 0
bearish = d1 < 0 and d2 < 0
neutral = not bullish and not bearish
For three valid values, green therefore marks a strict current maximum and red a strict current minimum within that three-value group. It does not require two successive rises or two successive falls. A gray state includes ties and a current value between the preceding two.
The RSI base follows TradingView’s RSI calculation. The 30 and 70 horizontal lines are visual references only; they are not used in any of these boolean comparisons. Changing those lines cannot change the background states.
Check the classifier with synthetic RSI sequences
Each row gives three hypothetical RSI values from oldest to newest. These isolate the logic; they are not sampled trades or performance measurements.
| RSI sequence | d1 / d2 | State | What it shows |
|---|---|---|---|
| 50, 60, 61 | 1 / 11 | Bullish | Latest rise is smaller, not accelerating upward |
| 70, 60, 71 | 11 / 1 | Bullish | A fall then a rise qualifies |
| 60, 50, 49 | −1 / −11 | Bearish | Latest decline is smaller |
| 70, 60, 65 | 5 / −5 | Neutral | RSI is rising, but still below the older value |
| 40, 50, 50 | 0 / 10 | Neutral | Equality fails the strict comparison |
| 50, 50, 50 | 0 / 0 | Neutral | Flat is only one neutral case |
A discrete acceleration calculation would compare consecutive changes: R − 2R[1] + R[2]. In the first row that is −9 even though the classifier is bullish. No such second-difference test appears in this script.
Likewise, 20 → 30 and 80 → 90 both add 10 RSI points but represent different percentage changes in RSI. This helper only uses the sign of each point difference, so it also discards the magnitude of qualifying changes.
Neutral does not always mean a measured market state
When RSI or one of its two historical values is unavailable, the comparisons cannot establish a bullish or bearish condition. In this Pine v6 script their booleans are false, so neutral becomes true and the background can be gray during initialization. There is no explicit three-value validity gate.
With uninterrupted prices and a length-14 RSI seed, the first possible RSI needs 15 closes; two further valid readings are needed for both comparisons, making 17 closes the earliest complete comparison group. This is initialization, not proof of convergence, and missing or undefined values require separate inspection.
After initialization, gray can represent a reversal inside the prior two-value range, an equal reading, or a flat sequence. It does not prove low volatility, predict a coming reversal, or measure the duration of a market regime.
State, event and realtime behavior
A run of green backgrounds counts multiple bullish-state bars. It is not a new state-entry event on each one. If an adaptation needs one event when bullish first becomes true, specify that transition separately, including what to do when the preceding data is unavailable.
The default length is fixed at 14 in the function call. There are no input declarations or alert conditions. The copy plots an RSI line, two horizontal references and three mutually exclusive background conditions. Its booleans can be used when writing additional alert logic, but this script does not already implement that logic.
The open bar can change color as close changes because there is no bar-close gate. The one-bar and two-bar references describe the chart timeframe, not separate timeframes. A multi-timeframe extension requires explicit requests and confirmed-data policies; it is not present here.
Evaluate a proposed rule without inventing an edge
- Record symbol, timeframe, session, source adjustments, RSI length and final code. Verify the table above before measuring signals.
- Separate state occupancy, state transitions and entries. A finalized daily bar has one resulting state; claims of multiple finalized state changes per daily bar need a different intrabar definition and data.
- Keep the 30/70 visual lines separate from any additional thresholds used in a strategy. A bullish state can occur below 30 or above 70.
- If testing EMA, ATR, volume or another timeframe as a filter, define the calculation and decision time. Compare the same data and costs, retain an untouched evaluation period and report counts and drawdown.
Longer RSI length changes smoothing; it does not guarantee fewer transitions, higher accuracy or a fixed number of bars of extra delay. Stochastic RSI normalizes RSI within a rolling RSI range, which is another transformation of the same underlying series rather than independent confirmation.
Pine Script v6: implementation and limits
The full original classifier is retained below. Its missing-data behavior maps unavailable comparisons to the neutral background, and its realtime backgrounds have no confirmation gate. Its name does not change the point-difference arithmetic.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//@version=6
indicator(title="RSI ROC Conditions", overlay=false, max_labels_count=500)
// RSI ROC Conditions — Bullish / Bearish / Neutral Classifier
p_ta_rsi_roc_conditions(simple int rsiLength) =>
rsiValue = ta.rsi(close, rsiLength)
roc1 = rsiValue - rsiValue[1]
roc2 = rsiValue - rsiValue[2]
bullish = roc1 > 0 and roc2 > 0
bearish = roc1 < 0 and roc2 < 0
neutral = not bullish and not bearish
[rsiValue, bullish, bearish, neutral]
// Call with default length
[rsi, bullish, bearish, neutral] = p_ta_rsi_roc_conditions(14)
// Visualization
hline(70, "Overbought", color=color.rgb(242, 54, 69, 0))
hline(30, "Oversold", color=color.rgb(76, 175, 80, 0))
plot(rsi, "RSI", color=color.rgb(41, 98, 255, 0), linewidth=1)
bgcolor(bullish ? color.rgb(76, 175, 80, 85) : na, title="Bullish Background")
bgcolor(bearish ? color.rgb(242, 54, 69, 85) : na, title="Bearish Background")
bgcolor(neutral ? color.rgb(120, 123, 134, 85) : na, title="Neutral Background")
Specify a checkable adaptation in Pineify
Ask for an explicit validity flag, an adjustable RSI length, and separately named state-entry events if needed. Specify whether colors and alerts require bar close. Review the generated code, run syntax checks, and verify the synthetic sequences and initialization in TradingView before evaluating a strategy.
Open Pine Script AI Coding AgentEducational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.