TradingView indicator guides

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 Script

The 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 sequenced1 / d2StateWhat it shows
50, 60, 611 / 11BullishLatest rise is smaller, not accelerating upward
70, 60, 7111 / 1BullishA fall then a rise qualifies
60, 50, 49−1 / −11BearishLatest decline is smaller
70, 60, 655 / −5NeutralRSI is rising, but still below the older value
40, 50, 500 / 10NeutralEquality fails the strict comparison
50, 50, 500 / 0NeutralFlat 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

  1. Record symbol, timeframe, session, source adjustments, RSI length and final code. Verify the table above before measuring signals.
  2. 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.
  3. 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.
  4. 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.

Pine Script v6
// 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")
Existing indicator chart preview
Existing visual preview. Verify exact values against the source; the image is not a performance result.

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 Agent

Educational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.

Implementation questions

No. RSI 50, 60, 61 is bullish because 61 exceeds both prior values, even though the latest rise is smaller. Acceleration would require comparing consecutive changes.

No. They subtract prior RSI readings and are expressed in RSI points. The classifier uses only their signs.

Not necessarily. It includes equality, a current value between the previous two, and unavailable comparisons during initialization.

No. They are plotted reference lines. The booleans compare RSI only with its one-bar and two-bar historical values.

No. It has fixed length 14, an RSI plot and colored backgrounds, with no inputs, alert declarations, strategy orders or additional-timeframe requests.