//@version=4 study("OBV", overlay=true) // Input variables inpPrice = input(title="Price", type=input.source, defval=close) FilterType = input(title="Filter Type", type=input.string, options=["Value", "Price", "All"], defval="Value") inpFilPeriod = input(title="Filter Period", type=input.integer, defval=0) inpFilSize = input(title="Filter Size", type=input.float, defval=2) // Function to calculate filtered value fchange(src, i) => abs(src[i] - src[i-1]) / src[i-1] * 100 fachange(src, period) => sum = 0.0 for i = 1 to period sum := sum + abs(src - src[i]) sum / period iFilter(tprice, filter, period, instanceNo) => if filter <= 0 or period <= 0 tprice else change = fchange(tprice, 0) achang = fachange(tprice, period) for i = 1 to period change := change + fchange(tprice, i) achang := achang + fachange(tprice[i], period) achang := achang / period stddev = 0.0 for i = 0 to period - 1 stddev := stddev + pow(fchange(tprice, i) - achang, 2) stddev := sqrt(stddev / period) filtev = filter * stddev if abs(change) < filtev tprice[1] else tprice // Calculate OBV values obv_raw = cum(close > close[1] ? volume : close < close[1] ? -volume : 0) obv_filt = iFilter(obv_raw, FilterType == "Price" or FilterType == "All" ? inpFilSize : 0, inpFilPeriod, 0) // Plot OBV values plot(obv_filt, title="OBV", color=color.blue, linewidth=2, style=plot.style_line)