Convert obv adl combination to ThinkorSwim?

D

diazlaz

Well-known member
VIP
Warehouse
@NEKSUS here you go - took a first pass, if anyone has any good ideas on how to use it, trade it or have a trading plan around it or enhancements please share.



Port:




Ruby:
#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
 
Last edited by a moderator:
N

NEKSUS

New member
@diazlaz Thank you very much!
It don`t work on intraday, can you help Please?
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@NEKSUS What do you mean by that? It's working for me.
 
N

NEKSUS

New member
@BenTen
The indicator does not draw on the timeframe below the daily

 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@NEKSUS You have pre-market on. Turn it off and it should work. Not sure why that happened.
 
N

NEKSUS

New member
@BenTen It help, thank you! But this is a problem for me. I really need it to work at the premarket.
And this does not work on all tickers. For example, yesterday's ADS
Maybe @diazlaz can solve this problem?
 
Last edited:
D

diazlaz

Well-known member
VIP
Warehouse
@BenTen It help, thank you! But this is a problem for me. I really need it to work at the premarket.
And this does not work on all tickers. For example, yesterday's ADS
Maybe @diazlaz can solve this problem?
Hi @NEKSUS, not sure - I will play with it some more over the weekend and report back. - I think it's going to skew the results, as this indicator is heavily dependent on volume, the pre-market volume could skew the overall results.
 

Top