OnBalanceVolume OBV OBVM Scan, Watchlist, Label For ThinkOrSwim

rak

New member
Lifetime
First time post and I have zero experience with writing code. I've opened scripts and added "plot" line or "addcloud" but that's about it. I currently just drop a SMA in the lower study panel on top of the OBV but that's not very accurate. I would like a 200 SMA of the OBV to plot for confirmation of who is in control.

I would appreciate someone sharing if they have this or something similar.
 
@rad14733 how can scan the two pikes?

def obv = TotalSum(Sign(close - close[1]) * volume);
plot scan = obv >1 and obv[1] <0 ;

d041v7j.png


The pikes from the study, the script i posted above. I hope someone can help me other alternative way to scan these pikes.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@mmct Your code above should work just fine in a scan... The issue is that scans are not intended to find distant historical events and that is what those two indicator spikes are on your chart... We can specify how many bars/candles back we want our scan criteria to consider valid for short-term lookback
 
Last edited by a moderator:
I have a quick question. So I'm trying to add a level line at -5 on the OBVModified script on TOS. Here's the code for it

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2020-2021
#

declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;

input levelLine = -5;
plot Level = levelLine;


def obv = reference OnBalanceVolume();

plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));

So I wrote the input levelLine = -5; plot Level = levelLine; part. The issue is for some reason the line always plots at 0. Not sure exactly why this is. Any help would be appreciated.
 
@fungus12
It's the same exact code you posted.
Just changed -5 to -5000.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2020-2021
#

declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;

input levelLine = -5000;
plot Level = levelLine;


def obv = reference OnBalanceVolume();

plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));
 
@fungus12
It's the same exact code you posted.
Just changed -5 to -5000.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2020-2021
#

declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;

input levelLine = -5000;
plot Level = levelLine;


def obv = reference OnBalanceVolume();

plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));
That was odd, it works now. Thanks for the help dude.
 
@fungus12
It's the same exact code you posted.
Just changed -5 to -5000.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2020-2021
#

declare lower;

input length = 7;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;

input levelLine = -5000;
plot Level = levelLine;


def obv = reference OnBalanceVolume();

plot OBVM = MovingAverage(averageType, obv, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));
Sorry dude just one more quick question. When I drag the OBV up to the other graph, I get these black bars on the side that say "millions". Is there any way to remove those?
 
This should get you started...

Code:
def OBV = onbalanceVolume();
AddLabel(yes,OBV,color.blue);
AddLabel(yes,if OBV > OBV[1] then "Up" else "Down",color.blue);
 
Hi Team,

Could you please assist and assign the arrows to be plotted on the actual candle of the chart?

declare lower;

input length = 7;
input maxVolumeCutOff = 2.5;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;

def OBV = TotalSum(Sign(close - close[1]) * volume);

plot OBVM = MovingAverage(averageType, OBV, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));

input showarrows = yes;
def price = close ;

def up = OBVM > Signal and Signal < OBVM ;
def dn = OBVM < Signal and Signal > OBVM ;
def neutral = between(close,min(OBVM,SIGNAL),max(SIGNAL,OBVM));

def x = CompoundValue(1,
if x[1]>=0 and (dn[1] or up[1]==0) and up
then 1
else if x[1]>=1 and (up or !dn)
then x[1]+1
else 0, 1);
def y = CompoundValue(1,
if y[1]<=0 and (up[1] or dn[1]==0) and dn
then 1
else if y[1]>=1 and (dn or !up)
then y[1]+1
else 0, 1);

plot uparrow = if showarrows and x == 3 and up then 1 else 0;
uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uparrow.SetLineWeight(1);
uparrow.SetDefaultColor(Color.yellow);

plot dnarrow = if showarrows and y == 3 and dn then 1 else 0;
dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnarrow.SetLineWeight(1);
dnarrow.SetDefaultColor(Color.white);
#
 
Last edited:
Hi Team,

Could you please assist and assign the arrows to be plotted on the actual candle of the chart?

declare lower;

input length = 7;
input maxVolumeCutOff = 2.5;
input signalLength = 10;
input averageType = AverageType.EXPONENTIAL;

def OBV = TotalSum(Sign(close - close[1]) * volume);

plot OBVM = MovingAverage(averageType, OBV, length);
plot Signal = MovingAverage(averageType, OBVM, signalLength);

OBVM.SetDefaultColor(GetColor(8));
Signal.SetDefaultColor(GetColor(2));

input showarrows = yes;
def price = close ;

def up = OBVM > Signal and Signal < OBVM ;
def dn = OBVM < Signal and Signal > OBVM ;
def neutral = between(close,min(OBVM,SIGNAL),max(SIGNAL,OBVM));

def x = CompoundValue(1,
if x[1]>=0 and (dn[1] or up[1]==0) and up
then 1
else if x[1]>=1 and (up or !dn)
then x[1]+1
else 0, 1);
def y = CompoundValue(1,
if y[1]<=0 and (up[1] or dn[1]==0) and dn
then 1
else if y[1]>=1 and (dn or !up)
then y[1]+1
else 0, 1);

plot uparrow = if showarrows and x == 3 and up then 1 else 0;
uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
uparrow.SetLineWeight(1);
uparrow.SetDefaultColor(Color.yellow);

plot dnarrow = if showarrows and y == 3 and dn then 1 else 0;
dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnarrow.SetLineWeight(1);
dnarrow.SetDefaultColor(Color.white);
#

The indicator along with the arrows will move to the upper panel when you just change this
Code:
declare lower;
to this
Code:
#declare lower;
 
Awesome! Could also help me combine an additional indicator? It is the built in ROC indicator from TOS.
Basically I would like arrows to plot only if the OBV UpArrow is true and a confirmed ROC is greater than ZeroLine. And the opposite for the DnArrow so then plot the OBV DnArrow when combined with the ROC when its smaller than ZeroLine and confirmed.

input length = 14;
input signalLength = 26;
input averageType = AverageType.EXPONENTIAL;
input showarrows = yes;

def OBV = TotalSum(Sign(close - close[1]) * volume);
def OBVM = MovingAverage(averageType, OBV, length);
def Signal = MovingAverage(averageType, OBVM, signalLength);
def price = close ;
def up = OBVM > Signal and Signal < OBVM ;
def dn = OBVM < Signal and Signal > OBVM ;
def neutral = between(close,min(OBVM,SIGNAL),max(SIGNAL,OBVM));
def x = CompoundValue(1,
if x[1]>=0 and (dn[1] or up[1]==0) and up
then 1
else if x[1]>=1 and (up or !dn)
then x[1]+1
else 0, 1);
def y = CompoundValue(1,
if y[1]<=0 and (up[1] or dn[1]==0) and dn
then 1
else if y[1]>=1 and (dn or !up)
then y[1]+1
else 0, 1);
def uparrow = if showarrows and x == 1 and up then 1 else 0;
#uparrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#uparrow.SetLineWeight(1);
#uparrow.SetDefaultColor(Color.yellow);

def dnarrow = if showarrows and y == 1 and dn then 1 else 0;
#dnarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#dnarrow.SetLineWeight(1);
#dnarrow.SetDefaultColor(Color.white);

###

input length2 = 14;
input colorNormLength = 14;

assert(length2 > 0, "'length' must be positive: " + length2);

def ROC = if price[length2] != 0 then (price / price[length2] - 1) * 100 else 0;
def ZeroLine = 0;

#ROC.DefineColor("Highest", Color.YELLOW);
#ROC.DefineColor("Lowest", Color.LIGHT_RED);
#ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
#ZeroLine.SetDefaultColor(GetColor(5));

def highestROC = HighestAll(ROC);
def lowestROC = LowestAll(ROC);
def midPtHighestROC = highestROC/2;
def midPtLowestROC = lowestROC/2;

#highestROC.setLineWeight(3);
#lowestROC.setLineWeight(3);
#highestROC.setDefaultColor(Color.Red);
#lowestROC.setDefaultColor(Color.Green);

#midPtHighestROC.setLineWeight(1);
#midPtLowestROC.setLineWeight(1);
#midPtHighestROC.setStyle(Curve.Short_Dash);
#midPtLowestROC.setStyle(Curve.Short_Dash);
#midPtHighestROC.setDefaultColor(Color.light_red);
#midPtLowestROC.setDefaultColor(Color.light_green);


def extremeHigh = ROC < HighestROC and ROC >= midPtHighestROC;
def extremeLow = ROC > LowestROC and ROC <= midPtLowestROC;
def ROCUpSignal = extremeLow and (ROC > ROC[1]);
def ROCDownSignal = extremeHigh and (ROC < ROC[1]);

plot bullSignal = if UpArrow and ROC > ZeroLine and ZeroLine < ROC then UpArrow else double.nan;
plot bearSignal = if DnArrow and ROC < ZeroLine and ZeroLine > ROC then DnArrow else double.nan;

bullSignal.setPaintingStrategy(PaintingStrategy.Arrow_Up);
bullSignal.setDefaultColor(Color.Green);
bullSignal.setLineWeight(3);

bearSignal.setPaintingStrategy(PaintingStrategy.Arrow_Down);
bearSignal.setDefaultColor(Color.Red);
bearSignal.setLineWeight(3);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
325 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top