RSI Past Can Turn RSI Into a Directional Tool
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradeStation

// RSI Past
//@version=5
indicator(title="RSI Past", shorttitle="RSI Past", overlay=false, precision=0)

// RSI input settings
rsiLength = input.int(14, title="Length", minval=2, group="RSI Settings")
rsiSource = input(close, title="Price", group="RSI Settings")
rsiOverbought = input.float(70, title="Overbought Threshold", group="RSI Settings")
rsiOversold = input.float(30, title="Oversold Threshold", group="RSI Settings")

// RSI input colors
color aboveColor = input.color(color.green, "Above 0 Color", group="Color Settings")
color belowColor = input.color(color.red, "Below 0 Color", group="Color Settings")
color zeroColor = input.color(color.black, "Zero Line Color", group="Color Settings")

var color plotColor = zeroColor
var int lastBullish = na
var int lastBearish = na
var float reading = na

rsiValue = ta.rsi(rsiSource, rsiLength)

if rsiValue < rsiOversold
    lastBearish := bar_index
else if rsiValue > rsiOverbought
    lastBullish := bar_index

if lastBullish and lastBearish
    reading := lastBullish - lastBearish

if reading
    if reading > 0
        plotColor := aboveColor
    else if reading < 0
        plotColor := belowColor
    else
        plotColor := zeroColor

readingPlot = plot(reading, title="RSI Pass", color=plotColor, style=plot.style_area, linewidth=3)