Relative Price Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © karimka

//@version=5
indicator("Relative Price Volume", "RPV", overlay = true)

// The length is the number of periods to calculate the avg.
period = input(10,"Periods", "Number of candles to use for avg")
// shortFactor = input.float(.4, "Short Factor", minval=0, maxval=1, step=.1)
// longFactor = input.float(.6, "Long Factor", minval=0, maxval=1, step=.1)
sizeFactor = input.float(.1, "Size Factor", minval=.1, maxval=.5, step=.05)

candleHeight = math.abs(close-open)
candleSizeAvg = ta.sma(candleHeight, period)

largeFactor = (1+sizeFactor)
smallFactor = (1-sizeFactor)

// Is the candle long or short
longCandle = candleHeight > (candleSizeAvg * largeFactor) 
shortCandle = candleHeight < (candleSizeAvg * smallFactor)

// Is Volume average, high, or low
avgVolume = ta.sma(volume, period)
highVol =  volume > (avgVolume * largeFactor)
lowVol = volume < (avgVolume * smallFactor)

anomoly = (highVol and shortCandle) or (lowVol and longCandle)

plotshape(title="Signal", series=(anomoly ? candleHeight: na), color=color.yellow, textcolor=color.yellow, style=shape.xcross, location=location.belowbar, size=size.auto)
