Sudden increase in volume [PINESCRIPTLABS]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PINE_LABS

//@version=5
indicator("Sudden increase in volume and RSI on oversold or overbought PINESCRIPTLABS", shorttitle="Sudden up and down volume PINESCRIPTLABS", overlay=true)

// Parámetros del indicador
length = input.int(21, title="RSI Length", minval=1)
rsi_overbought = input.int(80, title="RSI Overbought", minval=1)
rsi_oversold = input.int(30, title="RSI Oversold", maxval=100)
volume_threshold = input.int(2, title="Volume Threshold", minval=0)
ema_length = input.int(200, title="EMA Length", minval=1)

// Calcula el RSI
rsi = ta.rsi(close, length)

// Calcula el promedio móvil exponencial del volumen utilizando el valor actualizado de ema_length
ema_volume = ta.ema(volume, ema_length)

// Condiciones para el aumento brusco de volumen y RSI en sobreventa (compra)
abrupt_volume_increase_buy = volume > ema_volume * volume_threshold
rsi_oversold_condition_buy = rsi < rsi_oversold

// Condiciones para la venta (contrario a la compra)
abrupt_volume_increase_sell = volume > ema_volume * volume_threshold
rsi_overbought_condition_sell = rsi > rsi_overbought

// Dibuja un histograma para la compra
plotbar(abrupt_volume_increase_buy and rsi_oversold_condition_buy ? 1 : na, 0, 0, 0, color=color.green, title="Aumento Brusco de Volumen y RSI en Sobreventa (Compra)")

// Dibuja un histograma para la venta
plotbar(abrupt_volume_increase_sell and rsi_overbought_condition_sell ? 1 : na, 0, 0, 0, color=color.red, title="Aumento Brusco de Volumen y RSI en Sobrecompra (Venta)")

// Señal de compra con triángulo grande
plotshape(series=abrupt_volume_increase_buy and rsi_oversold_condition_buy, location=location.belowbar, color=color.green, style=shape.triangleup, title="Señal de Compra", size=size.normal)

// Señal de venta con triángulo grande
plotshape(series=abrupt_volume_increase_sell and rsi_overbought_condition_sell, location=location.abovebar, color=color.red, style=shape.triangledown, title="Señal de Venta", size=size.normal)

