OnBalanceVolume OBV OBVM 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.
 

horserider

Well-known member
VIP
@rak
Code:
# OBV and MovingAverage average of OBV
# Horserider 1/23/2020

declare lower;
input length = 200;
plot OBV = TotalSum(Sign(close - close[1]) * volume);
plot obvma = Average(obv, length);
OBV.SetDefaultColor(GetColor(8));
obvma.setDefaultColor(GetColor(1));
 

Rojo Grande

Member
VIP
Hello to all,

I have tried using the TOS scan tool to scan for stocks where the OBV is greater than or less than the previous time frame, but keep getting no results. It does not matter how many bars back I go or what time frame I use. Any help appreciated.

Thanks.
 

BenTen

Administrative
Staff member
Staff
VIP
@Rojo Grande Use the script below:

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

declare lower;

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

plot scan = if OBV > OBV[1] then 1 else double.nan;

Add it as an indicator and then set up your scanner to something like this:

AVdhTKS.png
 

Rojo Grande

Member
VIP
Hello to all,

I like the modified On Balance Volume. I altered it for color change when direction changes. I tried to make a column using the code, and eliminating the signal plot portion. The numbers I get don't match the numbers on my chart, and I do not get the color change either. Below is what I am using, any help is appreciated, thank you.

Code:
declare lower;

input length = 7;
input signalLength = 7;
input averageType = AverageType.Wilders;

def obv = reference OnBalanceVolume();

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

OBVM.AssignValueColor(if OBVM > OBVM[1] then color.GREEN else if OBVM < OBVM[1] then color.RED else color.gray);
#Signal.SetDefaultColor(GetColor(2));

#Alert(OBVM crosses Signal, "", Alert.BAR, Sound.Bell);
 

Rojo Grande

Member
VIP
When volume is increasing or ascending, it would generate a up green arrow. And naturally if the volume is decreasing or descending, a red down arrow would be generated. For instance, some RSI watchlist columns display the number in one color if its increasing, and another if its decreasing. Thank you.
 

BenTen

Administrative
Staff member
Staff
VIP
@Rojo Grande The only way to define if the volume is decreasing or increasing is by comparing it to the previous bar. I can do that. But if you have another definition, I'm afraid I would not be able to help.

If you look at the code you posted, the following line will do just that:

Code:
OBVM.AssignValueColor(if OBVM > OBVM[1] then color.GREEN else if OBVM < OBVM[1] then color.RED else color.gray);

If current OBV is higher than previous OBV then green or if current OBV is less than previous OBV then color red.
 

Rojo Grande

Member
VIP
Thank you Ben, I believe I need to uninstall and reinstall TOS. I'm using the same script for both the watch list column and for a lower indicator on my chart, but both the numbers and colors do not match up. Any idea's?
 

mmct

New member
@Rojo Grande Use the script below:

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

declare lower;

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

plot scan = if OBV > OBV[1] then 1 else double.nan;

Add it as an indicator and then set up your scanner to something like this:

AVdhTKS.png
hi Ben,
could you help me on the script that scan obv just cross above 0 line:

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

I don't know what wrong, it doesn't give me the right list.
thanks Ben
 

Similar threads

Top