# Help coding Weighted OBV

#### QUIKTDR1

##### Member
VIP
I am toying with a weighted OBV which I used in Worden's TC 2000. Here is the code I was using and want to convert to TOS

4.5 * OBV + 3.5 * OBV1.1 + 2.5 * OBV1.2 + 1.5 * OBV1.3 + .5 * OBV1.4 > .5 * OBV1.5 + 1.5 * OBV1.6 + 2.5 * OBV1.7 + 3.5 * OBV1.8 + 4.5 * OBV1.9

I want to use it as an indicator and a scanner based on the premise that volume precedes price moves.

Last edited:

#### QUIKTDR1

##### Member
VIP
I started code with
def OBV = TotalSum(Sign(close - close[1]) * volume);

4.5 * OBV + 3.5 * OBV1.1 + 2.5 * OBV1.2 + 1.5 * OBV1.3 + .5 * OBV1.4 > .5 * OBV1.5 + 1.5 * OBV1.6 + 2.5 * OBV1.7 + 3.5 * OBV1.8 + 4.5 * OBV1.9
but code is not recognized from 4.5 on

#### MerryDay

##### Well-known member
VIP
@QUIKTDR1 Oh my! That is one butt-ugly math expression. Syntax in Thinkscript is universal. See how you started your code? You need a def statement for every variable.
Ruby:
``````def OBV = TotalSum(Sign(close - close[1]) * volume);
def OBV1.1 =  "WHAT??" ;
def OBV1.2 =  "What??" ;
# and so on and so on. You must have a def statement all the way to OBV1.9``````

AFTER you have defined all your variables, NOW you can write your mathematical expression:
HTH

Last edited:

#### QUIKTDR1

##### Member
VIP
ThankYou MerryDay! I'm trying to develop it!

#### QUIKTDR1

##### Member
VIP
I think this is the next step...

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

def OBV = 4.5 * OBV + 3.5;
def OBV1.1 = OBV1.1 + 2.5 ;
def OBV1.2 = OBV1.2 + 1.5 ;
def OBV1.3 = OBV1.3 + .5 ;
def OBV1.4 = OBV1.4 > .5;
def OBV1.5 = OBV1.5 + 1.5 ;
def OBV1.6 = OBV1.6 + 2.5;
def OBV1.7 = OBV1.7 + 3.5;
def OBV1.8 = OBV1.8 + 4.5.
def OBV1.9 = OBV1.9

#### QUIKTDR1

##### Member
VIP
Anyone who wants to help me is more than welcome!

#### MerryDay

##### Well-known member
VIP
@QUIKTDR1 At this point I think I have to say you don't have the necessary math background to create an indicator. And no one can create it for you because you can't explain in mathematical terms what you are trying to do.

This is how you defined your 1st variable. That just isn't math.
Define X = X +2.5

Sorry.

#### MerryDay

##### Well-known member
VIP
Okay so while I have no idea what those strange 9 variables in @QUIKTDR1 math expression are supposed to be doing.
I did find some information about the Weighted OBV Indicator. This could be a useful study:

But this is STILL not enough information to define the weighted OBV, right? Oh Great @Welkin, is this something worthwhile?
I have found the @Welkin OBV histogram invaluable. You are my go-to guru for all things volume.

PS: I found this in this awesome weird GITHUB link (posters, this is not TOS code, do NOT attempt to cut and paste). It is just to help point us in the direction of what we are looking for in the logic.
Ruby:
`````` @classmethod
@inputvalidator(input_="ohlcv")
def WOBV(cls, ohlcv: DataFrame, column: str = "close") -> Series:
"""
Weighted OBV
Can also be seen as an OBV indicator that takes the price differences into account.
In a regular OBV, a high volume bar can make a huge difference,
even if the price went up only 0.01, and it it goes down 0.01
instead, that huge volume makes the OBV go down, even though
hardly anything really happened.
"""

wobv = pd.Series(ohlcv["volume"] * ohlcv[column].diff(), name="WOBV")
return wobv.cumsum()``````

Last edited:

#### QUIKTDR1

##### Member
VIP
I need help, please in coding this OBV indicator/ scan

TY'all

#### QUIKTDR1

##### Member
VIP
I am not a programmer and still learning TOS I have my WTD OBV from TC2000 and was using the first breakout to verify the trend. I am not trying to reinvent the wheel I was just trying to code my formula into TOS. TY again MerryDay! Let's see if someone else will help I think it may be a helpful indicator and scan.

##### Well-known member
VIP
@QUIKTDR1 You don't need to keep posting... If someone can help, and has the time to, they will... Your apparent lack of desire to learn to help yourself doesn't mean others are going to run to your rescue... You could be learning rather than just waiting impatiently, right...??? Take the sound of crickets as an indicator... You won't learn if you never make an effort... How do you think those of us who know how to code learned...??? We started...!!! Don't take this the wrong way, I'm just trying to help you - perhaps the way you need rather than the way you want... Dig in...!!!

#### QUIKTDR1

##### Member
VIP
Okay, I understand it is just frustrating when I am indeed reading and investigating and using it in another venue efficiently. Don't get your panties in a wad I apologize if I disrupted you I was just excited to share something that I think is effective for all and recognize it is beyond my expertise right now. I will continue to profit using it on the other venue. Sorry for the bother.

#### halcyonguy

##### Active member
VIP
do you have any links, describing what it is you are trying to do?

Code:
`` def OBV1.1 = OBV1.1 + 2.5 ;``

there are a couple of things wrong with this line.

can't use a period like that, in a variable name.
i think _ (underscore) is the only character that be used in a variable name, as is.
to use other characters, you have to wrap the variable name in quotes, everywhere it is used. "abc+" "OBV1.1"
i use _ to separate words in variable names.

can't use the same variable name on both sides of = sign. in the old days of dos basic , that worked to update a variable.
but in tos , use [number] after a variable, to read a value from a different bar.
this will read the value from 1 bar back in time and add it to 2.5, and assign it to the current bar.

Code:
``  def OBV1 = OBV1[1] + 2.5 ;``

https://tlc.thinkorswim.com/center/...utorials/Basic/Chapter-1---Defining-Variables

https://tlc.thinkorswim.com/center/...nced/Chapter-10---Referencing-Historical-Data