#OBV ADL Combination Indicator
#[ST] obv adl combination v4
#https://www.tradingview.com/script/YQY0qdVr-ST-obv-adl-combination-v4/
#Original spacetrader
#1.0 2019.10.24 ported by diazlaz
#OBV takes difference between old close and new close and multiplies by volume without considering high and low.
#Accum/dist takes difference between close and high and low without considering previous close or open.
#This is attempt to combine both so relative motion between candles is detected and volume direction is assigned based relative to movement within a candle.
#+ and - depends if close is above previous close (+ if above, - if below)
#Maximum upward volume counts if close = high and previous close = low, this makes multiplier 1 and thus entire volume is counted upwards
#Maximum downward volume counts if close = low and previous close = high, this makes multiplier -1 and thus entire volume is counted downwards.
#Zero volume movement occurs when close = previous close.
#Half upward volume movement occurs if close-previous_close is half the range from high-low.
#Updates
#Open used instead of previous close due to issues with grabbing previous close on some charts. This seems more accurate for gaps without volume.
#Multiply by ohcl4 to get volume in bitcoin - this way volume is in terms of something more stable overtime
declare lower;
input averageType = AverageType.WILDERS;
input price = close;
input emalength = 24; #ema length
input rsilength = 14; #rsi length
input showobv = yes; #Show obv?
input showema = no; #Show ema?
input showrsi = no; #Show rsi of obv?
input showtopextremes = no; #show top extreme levels?
input showbottomextremes = no; #show bottom extreme levels?
input highlightbreakouts = yes; #highlight breakouts?
input toplookback = 500; #top extreme lookback?
input bottomlookback = 500; #bottom extreme lookback?
def obv_btc = (volume * (close - open)/(high-low) * hlc3);
def all_obvbtc = TotalSum(obv_btc);
def na = Double.NaN;
#HIGHS and LOWS
def highs = highest(all_obvbtc, toplookback);
def lows = lowest(all_obvbtc, bottomlookback);
#RSI
def NetChgAvg = MovingAverage(averageType, price - price[1], rsilength);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), rsilength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
#PLOTS
plot pOBV = all_obvbtc;
pOBV.SetHiding (!showobv);
plot pEMA = ExpAverage(all_obvbtc, emalength);
pEMA.SetHiding (!showema);
plot pRSI = if showrsi then RSI else na;
pRSI.SetHiding (!showrsi);
plot pHighs = highs;
pHighs.SetPaintingStrategy(paintingStrategy = PaintingStrategy.SQUARES);
pHighs.SetHiding (!showtopextremes);
plot pLows = lows;
pLows.SetPaintingStrategy(paintingStrategy = PaintingStrategy.SQUARES);
pLows.SetHiding (!showbottomextremes);
plot pHighlightBreakoutsHigh = if highs>highs[1] then highs else na;
pHighlightBreakoutsHigh.SetPaintingStrategy(paintingStrategy = PaintingStrategy.SQUARES);
pHighlightBreakoutsHigh.AssignValueColor(COLOR.LIME);
pHighlightBreakoutsHigh.SetHiding (!highlightbreakouts);
plot pHighlightBreakoutsLows = if lows<lows[1] then lows else na;
pHighlightBreakoutsLows.SetPaintingStrategy(paintingStrategy = PaintingStrategy.SQUARES);
pHighlightBreakoutsLows.AssignValueColor(COLOR.ORANGE);
pHighlightBreakoutsLows.SetHiding (!highlightbreakouts);
#end of OBV ADL Combination Indicator