Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Dealing with OBV & MS in PCF's - how to interp their "values" Topic Rating:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Tanstaafl
Posted : Friday, December 24, 2004 3:08:44 PM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
First of all, let's keep in mind that the formula for OBV is an infinite cumulative series:
if C>C1, then OBVnew = OBVprev + V
if C<C1, then OBVnew = OBVprev - V
The actual value of OBV depends on where you start in the series - any PCF's you write MUST take this into account.

The MoneyStream formula is proprietary, but is similarly cumulative like the OBV ... so the comments and conclusions below can be applied equally well to it.

The way that OBV is handled in the TC plots, and displayed in the databox, is related to the Zoom factor and the other indicators present on the chart. To demo this, plot OBV on the top pane, in Zoom 5, and turn on the databox to see its value. Now, plot a totally separate 500-day Simple MA of price in the same pane. Voila! The OBV value changes, since, TC starts its OBV series-calc with the OLDEST bar that is required for ANY indicator being displayed at the time - and the addition of the 500dSMA forced the OBV calc to "go back" a lot further.

However, if you check the DIFFERENCE between OBV today and OBV yesterday using the databox, with and without the 500-day Price SMA present, you will find that the two differences are (essentially) equal. There *is* a bug in TC ... the difference SHOULD be exactly equal in magnitude to today's VOLUME ... which it isn't ... but it's close enuf for plotting purposes ... probably some kind of goofy internal roundoff error.

The way that OBV works in PCF's is sort of similar ... but it is not related to the chart. Instead, TC decides what the OLDEST bar required for the PCF is, then calc's the OBV from that value forward. This makes the OBV calc as efficient as possible, btw. To see how this works, create the following PCF and use the Test function to find the internal values:
(Abs(OBV.0-OBV.1) - V) * C0/C0
Note that the Result of this equation will ALWAYS be zero, for any day and for any symbol. OBV.0 is the 1-day SMA of the OBV value, as of today, and OBV.1 is the 1-day SMA of the OBV value, as of yesterday. They are syntactically equivalent to OBV1.0 and OBV1.1

OK, now change that PCF to:
(Abs(OBV.0-OBV.1) - V) * C1/C1
Check the Test values ... the two OBV's are the same. Now try:
(Abs(OBV.0-OBV.1) - V) * C2/C2
Check the Test values ... the two OBV's again are the same. Now try:
(Abs(OBV.0-OBV.1) - V) * C3/C3
Check the Test values ... the two OBV's are DIFFERENT. Why?

In order to calculate OBV.1, TC has to use THREE bars ... it needs to know the C2, C1, C0, V1 and V0 in order to fulfill the demands of the logic. So, for the first three cases, the final Cx/Cx term did not "push back" the earliest required bar ... thus the OBV calc's were the same in all three cases.

However the fourth case, with C3/C3 at the end, forced the OBV calcs to go back one bar earlier since C3 is older. Therefore, V2 was included in the OBV.0 and OBV.1 calc in that formula.

W recommends that any time you work with cumulative indicators such as OBV and MS you should always use a difference vs a prior OBV or MS baseline value ... or (less reliable) divide by that prior baseline value. Although this does work, it sometimes forces the user to morph their formulae to something unnecessarily complex and time-consuming to calc.

Instead of doing that, we can take advantage of the internal calc-rule derived above to force an OBV baseline, without requiring subtraction or division by another OBV or MS value. We can keep the "baseline limit" simple by just multiplying by Cx/Cx, where "x" is at least one bar OLDER than the oldest OBV or MS function in the PCF. Even tho the MS formula is proprietary and I've not been privy to it from W, I've demonstrated to my own satisfaction that MS1.0 relies only on today's and yesterday's values ... therefore, as with OBV, only one extra day "older" is required.

If you want to find the Min or Max OBV during the past 4 days, for instance, you can use the equation:
Min(OBV,4) * C4/C4
Max(OBV,4) * C4/C4
Check it out yourself ... compare the Test results of those PCF's with the values:
OBV*C4/C4, OBV.1*C4/C4, OBV.2*C4/C4, OBV.3*C4/C4
You will find that the Min and the Max value in fact equal one of the individual OBV's during that period.

Alternatively, you could ADD the quantity (C4-C4) instead of multiplying by the quotient ... probably a better longterm solution, since it's less likely to create floating-point or divide-by-zero error in odd casess.

HOWEVER, if you leave out the C4/C4 term, or if you use something less than "4", then the OBV values are not interpreted properly. Keep in mind: Min & Max(OBV,4) look at the last four bars, which requires FIVE bars of info to calc the OBV from. C4 is the FIFTH closing value back, including today (C0).

Now, for a semi-practical application ... let's create an OSCILLATOR that shows what today's OBV is as a percentage of the difference between the Max and Min OBV value of the past 16 days ....
100* (OBV-Min(OBV,16)) / (Max(OBV,16) - Min(OBV,16))
This uses the typical W-recommended method of using differences (for the numerator) ... and relies on the "fixed anchor" method in the denominator. The C16/C16 multiplier is NOT needed.

Let's look at a little bit more interesting example ... find the 1-standard deviation upper Bollinger Band around the 5-day moving average of the OBV. As documented elsewhere, the formula for this upper-BB based on Close is:
AvgC5 + 1 * Sqr( ( ( C*C + C1*C1 + C2*C2 + C3*C3 + C4*C4 ) - 5 * AvgC5*AvgC5 ) / 4 )

If we want to use OBV instead, then we should be able to substitute it in for C:
Avg(OBV,5) + 1 * Sqr( ( ( OBV*OBV + OBV.1*OBV.1 + OBV.2*OBV.2 + OBV.3*OBV.3 + OBV.4*OBV.4 ) - 5 * Avg(OBV,5)*Avg(OBV,5) ) / 4 )

The question is ... will this be a legit value? Answer ... yes, as long as we remember that the OBV values in the formula are all calc'd from five days ago, forward.

Let's write a PCF for the OBV crossing its upper 5,10 BB, so we can compare it to the TC plotted results:
OBV today > its UBB
and
OBV yesterday < its UBB

The full form of that would be:
OBV > Avg(OBV,5) + 1 * Sqr( ( ( OBV*OBV + OBV.1*OBV.1 + OBV.2*OBV.2 + OBV.3*OBV.3 + OBV.4*OBV.4 ) - 5 * Avg(OBV,5)*Avg(OBV,5) ) / 4 )
and
OBV.1 < Avg(OBV.1,5) + 1 * Sqr( ( ( OBV.1*OBV.1 + OBV.2*OBV.2 + OBV.3*OBV.3 + OBV.4*OBV.4 + OBV.5*OBV.5 ) - 5 * Avg(OBV.1,5)*Avg(OBV.1,5) ) / 4 )

Save this PCF, recalc it, and Sort the SP-500 watchlist by it so that the Trues are on top of the list. Now plot the OBV in the top pane, and apply a 5,10 BB child to it. Zoom 9 to see things clearly. Spacebar through the WL ... you will see that the PCF correctly models what is shown on the graph.

Why does this work? The plotted OBV values are much different than the PCF-calc'd values ... we know from the discussion above that the PCF calc's only work with the past six bars, but the plotted values in Zoom 9 are working with something more than 20 bars (W does not reveal how much additional lookback is going on). So ... why does it work?

The answer is, we are comparing apples with apples in each case. We are NOT comparing the PCF value of OBV to the plotted value of the 5,10 BB of OBV ... if we did (try it!), there would be a huge discrepancy. Instead, we are keeping each of the two comparisons internally self-consistent ... the PCF contains its own baseline, and the plot contains its own baseline ... but BOTH of those baselines are long enough to handle the calculation that is being asked of them.

** So what's the big deal, anyways? **

Why write up this long thing to just show that the PCF's work fine?

The problem that sometimes arises is that people take a look at the OBV values in a Test window, or as the result of a value-based OBV PCF, or in the databox for a plotted OBV, and get all (unpleasantly) excited about lack of agreement between them.

Hopefully this long writeup will not only have clearly explained the how's and do's/don'ts of OBV-ing things, but also will have provided a couple of useful indicators along the way.

Have Fun!

Jim Dean

jfh123
Posted : Friday, December 24, 2004 9:20:59 PM
Registered User
Joined: 12/17/2004
Posts: 143
Jim,

I'm not sure where to begin to respond -- you have provided so much info. that reading it is a bit like drinking from a fire hose. As well, you have taken the care to try to respond now to a concern voiced days ago. Thank you! Here's my response:

I have a process, which involves volume, which I want to put into a PCF. When I first tried to do so, using OBV, I had so much trouble (with values varying dramatically in the visual display, and with dividing by negative numbers ... no, using absolute values didn't really work out, and with OBV's constant's not staying constant), I re-wrote it to use volume directly. Now all I need is the ability to tell where, within a 16-day range, a custom indicator falls. Toward that end, I am working on simplifying my series of abs statements I told you about in the previous thread, but I doubt I can get it small enough to work.

It may be that it's better to use OBV. But, to do so, I'd need to read through all you've written, and understand it. Then I'd have to rewrite the process, using OBV, and ensure it gives the same result. While it's easy to create an OBV oscillator, what I need is more like a MACD oscillator. So ... while you've written lots which is valuable, using it will not be easy. If and when I conclude the MACD-type oscillator PCF is too long, I will come back to this thread.

In the meantime, if you have any helpful thought re simplifying the MACD-type oscillator, I'd love to have them.

Thanks!

PS: Merry Christmas!
Tanstaafl
Posted : Sunday, December 26, 2004 10:52:49 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
I posted a response re the MACD thing in the original thread.

jfh123
Posted : Sunday, December 26, 2004 7:44:24 PM
Registered User
Joined: 12/17/2004
Posts: 143
Jim,

I'm guessing you mean the following response, which you posted a few days ago. My problem is TC2k already takes about 5 minutes just to fully open, now that I have this massive PCF, and that's for only one day! So, while I agree excel & concatenation is great (and I use it for backtesting), I fear the final PCF will be too long to open, display on the chart, or sort. But, with Bruce's 30% reduction (mentioned in the other thread), I'll see. Thanks again.

Suggestion: if you are adept with Excel, you can use it to automate the development (and debugging) of stuff like this. Write an Excel equation that creates the string for a single bar's formula-component, then copy that formula down a column with appropriate increments for each new bar. Concatenate all those strings with a formula at the top of the column.

Copy the final results to NotePad (or to the TC edit window) ... don't use Wordpad as the target or the formula-string will get truncated.

This is a method that I've used for several years now to solve a huge number of seemingly-impossible or impractical tasks in PCF-eze.

Even tho the formulae are long, the PCF interpreter can and will reliably deal with them.
Tanstaafl
Posted : Friday, February 4, 2005 6:46:29 PM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
I'm not sure which "massive PCF" you are referring to.

There are usually ways of speeding things up ... post the PCF that you are describing, and I'll be happy to offer suggestions.

Jim Dean

jfh123
Posted : Friday, February 4, 2005 7:25:58 PM
Registered User
Joined: 12/17/2004
Posts: 143
Jim,

I'm done with that PCF. Using RSI worked just as well. THanks, anyway.

John
leeatnyc
Posted : Monday, February 20, 2006 11:07:02 AM
Registered User
Joined: 12/30/2004
Posts: 40
Dear Sir:

I have plotted the following in several middle windows:

- Money Stream
- A 21 Day moving average of money stream
- Bollinger Bands around Money Stream of 1 standard deviation above and below the 21 day moving average of money stream

Can you supply a formula that will tell me the following?

- when MS breaks above the upper band line (1 standard deviation of the 21 MS MA) from below that upper band line and

- when MS breaks below the upper band line from above the same line

Thanks very much

Lee Klein #47144
Bruce_L
Posted : Tuesday, March 28, 2006 1:20:42 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
leeklein,
If I'm understanding your question correctly, the following should tell you both:

SGN(MS1 - MS21 - SQR(ABS(MS1^2 + MS1.1^2 + MS1.2^2 + MS1.3^2 + MS1.4^2 + MS1.5^2 + MS1.6^2 + MS1.7^2 + MS1.8^2 + MS1.9^2 + MS1.10^2 + MS1.11^2 + MS1.12^2 + MS1.13^2 + MS1.14^2 + MS1.15^2 + MS1.16^2 + MS1.17^2 + MS1.18^2 + MS1.19^2 + MS1.20^2 - 21 * MS21^2) / 20)) - SGN(MS1.1 - MS21.1 - SQR(ABS(MS1.1^2 + MS1.2^2 + MS1.3^2 + MS1.4^2 + MS1.5^2 + MS1.6^2 + MS1.7^2 + MS1.8^2 + MS1.9^2 + MS1.10^2 + MS1.11^2 + MS1.12^2 + MS1.13^2 + MS1.14^2 + MS1.15^2 + MS1.16^2 + MS1.17^2 + MS1.18^2 + MS1.19^2 + MS1.20^2+ MS1.21^2 - 21 * MS21.1^2) / 20))

The formula will return values between +2 and -2:

+2: MoneyStream crossing up through the Upper Bollinger Band.
+1: MoneyStream crossing up through the Upper Bollinger Band (but matching at some point).
0: MoneySream not crossing the Upper Bollinger Band.
-1: MoneyStream crossing down through the Upper Bollinger Band (but matching at some point).
-2: MoneyStream crossing down through the Upper Bollinger Band.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
ffarron
Posted : Thursday, October 28, 2010 3:41:57 AM
Registered User
Joined: 11/7/2009
Posts: 25
QUOTE (Tanstaafl)
First of all, let's keep in mind that the formula for OBV is an infinite cumulative series:
if C>C1, then OBVnew = OBVprev + V
if C<C1, then OBVnew = OBVprev - V
The actual value of OBV depends on where you start in the series - any PCF's you write MUST take this into account.

The MoneyStream formula is proprietary, but is similarly cumulative like the OBV ... so the comments and conclusions below can be applied equally well to it.

The way that OBV is handled in the TC plots, and displayed in the databox, is related to the Zoom factor and the other indicators present on the chart. To demo this, plot OBV on the top pane, in Zoom 5, and turn on the databox to see its value. Now, plot a totally separate 500-day Simple MA of price in the same pane. Voila! The OBV value changes, since, TC starts its OBV series-calc with the OLDEST bar that is required for ANY indicator being displayed at the time - and the addition of the 500dSMA forced the OBV calc to "go back" a lot further.

However, if you check the DIFFERENCE between OBV today and OBV yesterday using the databox, with and without the 500-day Price SMA present, you will find that the two differences are (essentially) equal. There *is* a bug in TC ... the difference SHOULD be exactly equal in magnitude to today's VOLUME ... which it isn't ... but it's close enuf for plotting purposes ... probably some kind of goofy internal roundoff error.

The way that OBV works in PCF's is sort of similar ... but it is not related to the chart. Instead, TC decides what the OLDEST bar required for the PCF is, then calc's the OBV from that value forward. This makes the OBV calc as efficient as possible, btw. To see how this works, create the following PCF and use the Test function to find the internal values:
(Abs(OBV.0-OBV.1) - V) * C0/C0
Note that the Result of this equation will ALWAYS be zero, for any day and for any symbol. OBV.0 is the 1-day SMA of the OBV value, as of today, and OBV.1 is the 1-day SMA of the OBV value, as of yesterday. They are syntactically equivalent to OBV1.0 and OBV1.1

OK, now change that PCF to:
(Abs(OBV.0-OBV.1) - V) * C1/C1
Check the Test values ... the two OBV's are the same. Now try:
(Abs(OBV.0-OBV.1) - V) * C2/C2
Check the Test values ... the two OBV's again are the same. Now try:
(Abs(OBV.0-OBV.1) - V) * C3/C3
Check the Test values ... the two OBV's are DIFFERENT. Why?

In order to calculate OBV.1, TC has to use THREE bars ... it needs to know the C2, C1, C0, V1 and V0 in order to fulfill the demands of the logic. So, for the first three cases, the final Cx/Cx term did not "push back" the earliest required bar ... thus the OBV calc's were the same in all three cases.

However the fourth case, with C3/C3 at the end, forced the OBV calcs to go back one bar earlier since C3 is older. Therefore, V2 was included in the OBV.0 and OBV.1 calc in that formula.

W recommends that any time you work with cumulative indicators such as OBV and MS you should always use a difference vs a prior OBV or MS baseline value ... or (less reliable) divide by that prior baseline value. Although this does work, it sometimes forces the user to morph their formulae to something unnecessarily complex and time-consuming to calc.

Instead of doing that, we can take advantage of the internal calc-rule derived above to force an OBV baseline, without requiring subtraction or division by another OBV or MS value. We can keep the "baseline limit" simple by just multiplying by Cx/Cx, where "x" is at least one bar OLDER than the oldest OBV or MS function in the PCF. Even tho the MS formula is proprietary and I've not been privy to it from W, I've demonstrated to my own satisfaction that MS1.0 relies only on today's and yesterday's values ... therefore, as with OBV, only one extra day "older" is required.

If you want to find the Min or Max OBV during the past 4 days, for instance, you can use the equation:
Min(OBV,4) * C4/C4
Max(OBV,4) * C4/C4
Check it out yourself ... compare the Test results of those PCF's with the values:
OBV*C4/C4, OBV.1*C4/C4, OBV.2*C4/C4, OBV.3*C4/C4
You will find that the Min and the Max value in fact equal one of the individual OBV's during that period.

Alternatively, you could ADD the quantity (C4-C4) instead of multiplying by the quotient ... probably a better longterm solution, since it's less likely to create floating-point or divide-by-zero error in odd casess.

HOWEVER, if you leave out the C4/C4 term, or if you use something less than "4", then the OBV values are not interpreted properly. Keep in mind: Min & Max(OBV,4) look at the last four bars, which requires FIVE bars of info to calc the OBV from. C4 is the FIFTH closing value back, including today (C0).

Now, for a semi-practical application ... let's create an OSCILLATOR that shows what today's OBV is as a percentage of the difference between the Max and Min OBV value of the past 16 days ....
100* (OBV-Min(OBV,16)) / (Max(OBV,16) - Min(OBV,16))
This uses the typical W-recommended method of using differences (for the numerator) ... and relies on the "fixed anchor" method in the denominator. The C16/C16 multiplier is NOT needed.

Let's look at a little bit more interesting example ... find the 1-standard deviation upper Bollinger Band around the 5-day moving average of the OBV. As documented elsewhere, the formula for this upper-BB based on Close is:
AvgC5 + 1 * Sqr( ( ( C*C + C1*C1 + C2*C2 + C3*C3 + C4*C4 ) - 5 * AvgC5*AvgC5 ) / 4 )

If we want to use OBV instead, then we should be able to substitute it in for C:
Avg(OBV,5) + 1 * Sqr( ( ( OBV*OBV + OBV.1*OBV.1 + OBV.2*OBV.2 + OBV.3*OBV.3 + OBV.4*OBV.4 ) - 5 * Avg(OBV,5)*Avg(OBV,5) ) / 4 )

The question is ... will this be a legit value? Answer ... yes, as long as we remember that the OBV values in the formula are all calc'd from five days ago, forward.

Let's write a PCF for the OBV crossing its upper 5,10 BB, so we can compare it to the TC plotted results:
OBV today > its UBB
and
OBV yesterday < its UBB

The full form of that would be:
OBV > Avg(OBV,5) + 1 * Sqr( ( ( OBV*OBV + OBV.1*OBV.1 + OBV.2*OBV.2 + OBV.3*OBV.3 + OBV.4*OBV.4 ) - 5 * Avg(OBV,5)*Avg(OBV,5) ) / 4 )
and
OBV.1 < Avg(OBV.1,5) + 1 * Sqr( ( ( OBV.1*OBV.1 + OBV.2*OBV.2 + OBV.3*OBV.3 + OBV.4*OBV.4 + OBV.5*OBV.5 ) - 5 * Avg(OBV.1,5)*Avg(OBV.1,5) ) / 4 )

Save this PCF, recalc it, and Sort the SP-500 watchlist by it so that the Trues are on top of the list. Now plot the OBV in the top pane, and apply a 5,10 BB child to it. Zoom 9 to see things clearly. Spacebar through the WL ... you will see that the PCF correctly models what is shown on the graph.

Why does this work? The plotted OBV values are much different than the PCF-calc'd values ... we know from the discussion above that the PCF calc's only work with the past six bars, but the plotted values in Zoom 9 are working with something more than 20 bars (W does not reveal how much additional lookback is going on). So ... why does it work?

The answer is, we are comparing apples with apples in each case. We are NOT comparing the PCF value of OBV to the plotted value of the 5,10 BB of OBV ... if we did (try it!), there would be a huge discrepancy. Instead, we are keeping each of the two comparisons internally self-consistent ... the PCF contains its own baseline, and the plot contains its own baseline ... but BOTH of those baselines are long enough to handle the calculation that is being asked of them.

** So what's the big deal, anyways? **

Why write up this long thing to just show that the PCF's work fine?

The problem that sometimes arises is that people take a look at the OBV values in a Test window, or as the result of a value-based OBV PCF, or in the databox for a plotted OBV, and get all (unpleasantly) excited about lack of agreement between them.

Hopefully this long writeup will not only have clearly explained the how's and do's/don'ts of OBV-ing things, but also will have provided a couple of useful indicators along the way.

Have Fun!

Jim Dean
Is there a glossary somewhere that translates this alphabet soup into English? thanks, ffarron
Bruce_L
Posted : Thursday, October 28, 2010 8:13:00 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
ffarron,
The only alphabet soup I see in Tanstaafl's post is math, the Personal Criteria Formula Language and his abbreviation of Upper Bollinger Band to UBB (only used after the longer version).

I can't help you with the math and the use of UBB has already been explained, but the following topics contain a fairly comprehensive list of the syntax that is valid in TeleChart's Personal Criteria Formula Language and some examples of basic formulas.

PCF Formula Descriptions
Handy PCF example formulas to help you learn the syntax of PCFs!

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.