RSIOMA with Volume Index Confirmation
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BoredDev

//@version=5
indicator("RSIOMA with Volume Index Confirmation", overlay=true)

// Input parameters
rsi_length = input.int(14, title="RSI Length", minval=1)
rsi_ob_level = input.int(70, title="Overbought Level")
rsi_os_level = input.int(30, title="Oversold Level")
nvi_length = input.int(255, title="NVI Length")
pvi_length = input.int(255, title="PVI Length")

// RSI calculation
rsi = ta.rsi(close, rsi_length)

// NVI calculation
nvi = 1.0
for i = 1 to nvi_length
    if volume[i] < volume[i-1]
        nvi := nvi + (nz(close[i], close[i-1]) - nz(close[i-1], close[i])) / nz(close[i-1], close[i])
    else
        nvi := nvi

// PVI calculation
pvi = 1.0
for i = 1 to pvi_length
    if volume[i] > volume[i-1]
        pvi := pvi + (nz(close[i], close[i-1]) - nz(close[i-1], close[i])) / nz(close[i-1], close[i])
    else
        pvi := pvi

// Determine entry points
bearish_div = (ta.rsi(close, rsi_length)[1] > rsi_ob_level) and (rsi < rsi_ob_level) and (close[1] > close)
bullish_div = (ta.rsi(close, rsi_length)[1] < rsi_os_level) and (rsi > rsi_os_level) and (close[1] < close)
sell_signal = bearish_div and nvi < nz(nvi[1], 1.0)
buy_signal = bullish_div and pvi > nz(pvi[1], 1.0)

// Plot signals
plotshape(sell_signal, title="Sell", style=shape.triangledown, location=location.abovebar, color=color.red)
plotshape(buy_signal, title="Buy", style=shape.triangleup, location=location.belowbar, color=color.green)
