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 |

Modelling Bollinger Bands (& Standard Deviation) in a TC PCF Topic Rating:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Tanstaafl
Posted : Saturday, December 18, 2004 10:00:53 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA

Please see the Bollinger Bands (BB), Bollinger Bands %B, Bollinger Bandwidth (BBW), and Standard Deviation (SD) topics for improved syntax in TC2000 v17+.

Here is the general formula, and a couple of examples, for how you can model the upper or lower Bollinger Bands *efficiently* in TC's PCF-eze. Also it shows the general formula for StdDev, which is useful for other things like volatility analysis. Please note that these formulae will precisely match the internal calc's used in TC to plot the BB envelopes (tho if you put them up as custom indicators, they will use different y-axis scales).

General Bollinger Band formula
BB(Pds,SDs)= SMA(Pds) +/- SDs*StdDev
Add/Sub final term to get Top/Bot BB
Middle BB line = SMA(Pds)

Standard Deviation PCF (per TC plot)
SQR( ( ( C*C + C1*C1 + ...+ Cn*Cn )
- ( p * AvgCp * AvgCp ) ) / n )
where p = SMAPds and n = Pds-1

Example: Pds = 10 days, 2x SD Top BB
TC requires 2x to be input as "20"

BB(10,2) = AvgC10 + 2 * SQR((( C*C +C1*C1
+C2*C2 +C3*C3 +C4*C4 +C5*C5 +C6*C6
+C7*C7 +C8*C8 +C9*C9 ) - ( 10 * AvgC10 *
AvgC10 ) ) / 9 )

Example: Pds = 20 days, 1x SD Bot BB
TC requires 1x to be input as "10"

BB(20,1) = AvgC20 - 1 * SQR((( C*C +C1*C1
+C2*C2 +C3*C3 +C4*C4 +C5*C5 +C6*C6
+C7*C7 +C8*C8 +C9*C9 +C10*C10
+C11*C11 +C12*C12 +C13*C13 +C14*C14
+C15*C15 +C16*C16 +C17*C17 +C18*C18
+C19*C19 ) - ( 20 * AvgC20*AvgC20 ) ) / 19 )

Important note: you can use other "roots" besides the Closing price in this equation - H,L,O,V are obvious alternatives. However, you can also use FUNCTIONS in place of Close ... for example you can substitute "TSV5.1" in place of "C" above, and get the StdDev &/or BB for the 5-day average of Time Segmented Volume, as of one day ago. Please note that for those kinds of substitutions, different syntax is required for the Averages: "AvgC10" becomes "Avg(TSV5.1,10)

Jim Dean



Bruce_L
Posted : Sunday, December 19, 2004 11:33:54 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Selecting Plot using price scale should bring the y-axis scales into alignment when setting up the Bollinger Band envelopes as Custom Indicators.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Tanstaafl
Posted : Sunday, December 19, 2004 11:54:33 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Thanks, Bruce

You are perfectly correct, as long as the root of the BB *is* a price ... OHLC or some other price-point on the bar such as (H+L)/2.

However, if you this formula with any non-price root such as volume or TSV or whatever, it is NOT a good idea to check "Plot using price scale", since the scaling of those roots is entirely different.

Jim Dean

P.S: It sure would be nice if TC allowed us to set our own scales for custom indicators, sort of like Metastock does. :~)

bustermu
Posted : Wednesday, February 9, 2005 6:19:19 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Jim D.,

QUOTE (Tanstaafl)
Standard Deviation PCF (per TC plot)
SQR( ( ( C*C + C1*C1 + ...+ Cn*Cn )
- ( p * AvgCp * AvgCp ) ) / n )
where p = SMAPds and n = Pds-1


You correctly point out that this is what TC2K uses for "standard deviation" in their calculation for Bollinger Bands. It should be emphasized that the "/n" must be replaced by "/p" to obtain the actual standard deviation.

Notice that the standard deviation of (1,-1) is 1 not 1.414... . That of (1,-1,1,-1) is 1 not 1.154... . Etc.

Thanks,
Jim Murphy
Bruce_L
Posted : Wednesday, February 9, 2005 8:01:33 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bustermu,
We could debate the appropriateness of using Standard Deviation of Sample in this situation, but it seems pointless. When the algorithm was written for Bollinger Bands in TeleChart, it was apparently decided the data points used for calculating Bollinger Bands are merely a sample of the data and that a Standard Deviation of Population would be biased. I’m not sure it is the decision I would have made, but the choice seems open to at least some interpretation considering the data points are usually just a segment of the entire data and are also frequently price points like close that are only a small portion of the actual prices during the timeframe in question.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Tanstaafl
Posted : Wednesday, February 9, 2005 8:21:50 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
I agree with both of you. (heh heh)

Jim Murphy is correct in that Bollinger Bands, *as defined by John Bollinger* (and probably by statistical guidelines as well) should be using P instead of N as the divisor. If someone really wants it done that way, a Custom Indicator can usually solve the problem (unless the root function is too hairy).

Bruce is correct in that the difference, for our purposes, is not enough to make a difference ... particularly since price series do not satisfy other criteria for true Std Dev calc's (randomness and distribution pattern), and since 99% of the use of BB's have fewer than 30 data points (I believe that a "chi" factor is supposed to be used with <30 points, according to Hoyle).

For me, the issue is settled pretty easily by simply laying the two equations on the same plot and observing just how TINY the differences are, for a typical 20,20 BB.

FWIW, John B suggests from actual testing that the 20,20 BB actually contains about 88-89% of the data points, rather than the "true" statistical prediction of about 95%. So, TC's use of the N divisor rather than the larger P divisor actually tends to push the visible bands a skosh further apart, which if anything moves the probabilities CLOSER to the "chi-factor-corrected-normal-distribution" value.

All that being said, it's comforting to know that folks at W are aware of the issue.

Jim Dean

bustermu
Posted : Wednesday, February 9, 2005 9:55:04 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

It should be pointed out that if under appropriate conditions one has an unbiased estimate of variance, its square-root is not, in general, an unbiased estimate of standard deviation.

Thus, your statement concerning biasedness more appropriately applies to variance and not to standard deviation.

Thanks,
Jim Murphy
bknight
Posted : Monday, July 11, 2005 4:11:50 AM
Registered User
Joined: 12/19/2004
Posts: 415
QUOTE (Bruce_L)
bustermu,
We could debate the appropriateness of using Standard Deviation of Sample in this situation, but it seems pointless. When the algorithm was written for Bollinger Bands in TeleChart, it was apparently decided the data points used for calculating Bollinger Bands are merely a sample of the data and that a Standard Deviation of Population would be biased. I’m not sure it is the decision I would have made, but the choice seems open to at least some interpretation considering the data points are usually just a segment of the entire data and are also frequently price points like close that are only a small portion of the actual prices during the timeframe in question.


Bruce:

For a Bolinger Band of 21 days and 2 standard deviations, the settings would be 21 and 20 in the custom indicator?
Bruce_L
Posted : Monday, July 11, 2005 10:49:09 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bknight,
The 20 sounds right for Width in a Custom Price Channel to get 2 Standard Deviations if you are using a formula with a Standard Deviation of 1, but I'm not sure where you are putting the 21 in the Custom Price Channel. Anyway here are formulas that would match your settings for use as a Personal Criteria Formula or Custom Indicator:

Upper Band:
AVGC21+2*SQR(((C-AVGC21)^2 +(C1-AVGC21)^2 +(C2-AVGC21)^2 +(C3-AVGC21)^2 +(C4-AVGC21)^2 +(C5-AVGC21)^2 +(C6-AVGC21)^2 +(C7-AVGC21)^2 +(C8-AVGC21)^2 +(C9-AVGC21)^2 +(C10-AVGC21)^2 +(C11-AVGC21)^2 +(C12-AVGC21)^2 +(C13-AVGC21)^2 +(C14-AVGC21)^2 +(C15-AVGC21)^2 +(C16-AVGC21)^2 +(C17-AVGC21)^2 +(C18-AVGC21)^2 +(C19-AVGC21)^2 +(C20-AVGC21)^2)/20)

Lower Band:
AVGC21-2*SQR(((C-AVGC21)^2 +(C1-AVGC21)^2 +(C2-AVGC21)^2 +(C3-AVGC21)^2 +(C4-AVGC21)^2 +(C5-AVGC21)^2 +(C6-AVGC21)^2 +(C7-AVGC21)^2 +(C8-AVGC21)^2 +(C9-AVGC21)^2 +(C10-AVGC21)^2 +(C11-AVGC21)^2 +(C12-AVGC21)^2 +(C13-AVGC21)^2 +(C14-AVGC21)^2 +(C15-AVGC21)^2 +(C16-AVGC21)^2 +(C17-AVGC21)^2 +(C18-AVGC21)^2 +(C19-AVGC21)^2 +(C20-AVGC21)^2)/20)

(Edited for clarity)

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bknight
Posted : Monday, July 11, 2005 1:18:15 PM
Registered User
Joined: 12/19/2004
Posts: 415
Actually I was looking for a 2 standard deviation.
Bruce_L
Posted : Monday, July 11, 2005 1:19:45 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
The formulas I provided are two standard deviations. I'll edit the original post to state try and state it better.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bknight
Posted : Monday, July 11, 2005 1:26:28 PM
Registered User
Joined: 12/19/2004
Posts: 415
Thanks, I just woke up and didn't read your whole post.
PaulEarley
Posted : Thursday, February 9, 2006 11:21:58 PM
Registered User
Joined: 8/19/2005
Posts: 5
Bruce:
Does this mean that to write a Boolean PCF that is true if a stock closes yesterday higher than the upper Bollinger band, it would read:
c1 > AVGC21+2*SQR(((C-AVGC21)^2 +(C1-AVGC21)^2 +(C2-AVGC21)^2 +(C3-AVGC21)^2 +(C4-AVGC21)^2 +(C5-AVGC21)^2 +(C6-AVGC21)^2 +(C7-AVGC21)^2 +(C8-AVGC21)^2 +(C9-AVGC21)^2 +(C10-AVGC21)^2 +(C11-AVGC21)^2 +(C12-AVGC21)^2 +(C13-AVGC21)^2 +(C14-AVGC21)^2 +(C15-AVGC21)^2 +(C16-AVGC21)^2 +(C17-AVGC21)^2 +(C18-AVGC21)^2 +(C19-AVGC21)^2 +(C20-AVGC21)^2)/20)

Paul Earley
Bruce_L
Posted : Friday, February 10, 2006 8:00:34 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
PaulEarley,
Your formula certainly looks like yesterday's price is above the 21-Period 2-Standard Deviation Upper Bollinger Band to me.


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Tanstaafl
Posted : Friday, February 10, 2006 8:44:00 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
A small correction is needed - the inner terms should start with C1, not C ... and for a 21 day band, should end with C21, not C20 ...

C1 > AVGC21+2*SQR(((C1-AVGC21)^2 +(C2-AVGC21)^2 +(C3-AVGC21)^2 +(C4-AVGC21)^2 +(C5-AVGC21)^2 +(C6-AVGC21)^2 +(C7-AVGC21)^2 +(C8-AVGC21)^2 +(C9-AVGC21)^2 +(C10-AVGC21)^2 +(C11-AVGC21)^2 +(C12-AVGC21)^2 +(C13-AVGC21)^2 +(C14-AVGC21)^2 +(C15-AVGC21)^2 +(C16-AVGC21)^2 +(C17-AVGC21)^2 +(C18-AVGC21)^2 +(C19-AVGC21)^2 +(C20-AVGC21)^2 + (C21-AVGC21)^2)/20)

Jim Dean

Tanstaafl
Posted : Friday, February 10, 2006 8:49:01 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Oops wrong again ... the Avg's also need to be shifted back ...

C1 > AvgC21.1+2*SQR(((C1-AvgC21.1)^2 +(C2-AvgC21.1)^2 +(C3-AvgC21.1)^2 +(C4-AvgC21.1)^2 +(C5-AvgC21.1)^2 +(C6-AvgC21.1)^2 +(C7-AvgC21.1)^2 +(C8-AvgC21.1)^2 +(C9-AvgC21.1)^2 +(C10-AvgC21.1)^2 +(C11-AvgC21.1)^2 +(C12-AvgC21.1)^2 +(C13-AvgC21.1)^2 +(C14-AvgC21.1)^2 +(C15-AvgC21.1)^2 +(C16-AvgC21.1)^2 +(C17-AvgC21.1)^2 +(C18-AvgC21.1)^2 +(C19-AvgC21.1)^2 +(C20-AvgC21.1)^2 + (C21-AvgC21.1)^2)/20)

If you want a more efficient form of the same thing, try this:

C1 > AvgC21.1 - 2 * SQR((( C1*C1
+C2*C2 +C3*C3 +C4*C4 +C5*C5 +C6*C6
+C7*C7 +C8*C8 +C9*C9 +C10*C10
+C11*C11 +C12*C12 +C13*C13 +C14*C14
+C15*C15 +C16*C16 +C17*C17 +C18*C18
+C19*C19 +C20*C20 +C21*C21 )
- ( 21 * AvgC21.1*AvgC21.1 ) ) / 20 )

Jim Dean

PaulEarley
Posted : Friday, February 10, 2006 9:06:37 AM
Registered User
Joined: 8/19/2005
Posts: 5
Jim and Bruce:
Thanks for all the great help. I am trying to refine my short selections.

When I apply Jim's formula to ALL stocks, I get zero items returned, despite the fact that when I review stocks I can see many closes > upper BB. Any thoughts as to what I am doing worng? (The formula tests out TRUE for IBM).

Sorry to be such a newbie. I program for a living but can't quite get this PCF thing.
Paul Earley
Craig_S
Posted : Friday, February 10, 2006 9:21:43 AM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
Double check the WatchList you are calculating against.

Click on DATABANK then PERSONAL CRITERIA FORMULAS

Be sure the WL is set to ALL STOCKS or ALL ITEMS IN THE SYSTEM.

- Craig
Here to Help!
PaulEarley
Posted : Friday, February 10, 2006 9:53:05 AM
Registered User
Joined: 8/19/2005
Posts: 5
I ensured that it was calculating against ALL STOCKS. But the formula does not seem to calculate TRUE for stocks that closed above BB. The "Test" also does not accurately depict a close above the upper BB.

Could you cross check it on your system if you have the time? I appreciate all the help.
Paul
Tanstaafl
Posted : Friday, February 10, 2006 10:05:57 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Sorry my mistake ... my "efficient" formula was for the lower band ... need to change the - to a +:

C1 > AvgC21.1 + 2 * SQR((( C1*C1
+C2*C2 +C3*C3 +C4*C4 +C5*C5 +C6*C6
+C7*C7 +C8*C8 +C9*C9 +C10*C10
+C11*C11 +C12*C12 +C13*C13 +C14*C14
+C15*C15 +C16*C16 +C17*C17 +C18*C18
+C19*C19 +C20*C20 +C21*C21 )
- ( 21 * AvgC21.1*AvgC21.1 ) ) / 20 )

The other formula works OK

Jim Dean

bustermu
Posted : Friday, February 10, 2006 10:29:55 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Jim D.,

Your more efficient second PCF is for C1 above the lower Bollinger Band rather than above the upper Band. The first "-" should be a "+". When corrected, the second can be written:

C1>AvgC21.1+2*SQR((C1^2+C2^2+C3^2+C4^2+C5^2+C6^2+C7^2
+C8^2+C9^2+C10^2+C11^2+C12^2+C13^2+C14^2+C15^2+C16^2
+C17^2+C18^2+C19^2+C20^2+C21^2-21*AvgC21.1^2)/20)

All though correct in form, the more efficient second form can lead to computational inaccuracies not present in the first form. You will please notice that Bruce does not use the second form because of this problem.

Thanks,
Jim Murphy
Tanstaafl
Posted : Friday, February 10, 2006 12:57:07 PM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Hi, JimM:

As you can see, I caught my own mistake, nearly half an hour before your reply.

What computational inaccuracies are you referring to?

The second form is algebraically identical to the first ... but since it uses fewer Avg calls, and no exponentiation, it calc's faster. The answers should be totally identical for virtually all TC applications.

Many, many people have used that second form for a long time. Please, if you are going to cast doubt on it, be specific as to why and how significant the concern is.

Thanks.

Jim

Bruce_L
Posted : Friday, February 10, 2006 1:48:49 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I use the formula with more averages because while they should be the same:

((( C1*C1 +C2*C2 +C3*C3 +C4*C4 +C5*C5 +C6*C6 +C7*C7 +C8*C8 +C9*C9 +C10*C10 +C11*C11 +C12*C12 +C13*C13 +C14*C14 +C15*C15 +C16*C16 +C17*C17 +C18*C18 +C19*C19 +C20*C20 +C21*C21 ) - ( 21 * AvgC21.1*AvgC21.1 ) ) / 20 )

Will frequently evaluate to a negative number and produce trig errors when plotted as a Custom Indicator for Intraday timeframes on symbols with infrequent trades (my understanding is CIs round more than PCFs to try to improve speed).

(((C1-AvgC21.1)^2 +(C2-AvgC21.1)^2 +(C3-AvgC21.1)^2 +(C4-AvgC21.1)^2 +(C5-AvgC21.1)^2 +(C6-AvgC21.1)^2 +(C7-AvgC21.1)^2 +(C8-AvgC21.1)^2 +(C9-AvgC21.1)^2 +(C10-AvgC21.1)^2 +(C11-AvgC21.1)^2 +(C12-AvgC21.1)^2 +(C13-AvgC21.1)^2 +(C14-AvgC21.1)^2 +(C15-AvgC21.1)^2 +(C16-AvgC21.1)^2 +(C17-AvgC21.1)^2 +(C18-AvgC21.1)^2 +(C19-AvgC21.1)^2 +(C20-AvgC21.1)^2 + (C21-AvgC21.1)^2)/20)

Won't because each of the individual terms has to be positive.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Friday, February 10, 2006 4:11:28 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
Jim D.,

I did not see your post until my post was made. Sorry. I had this thread open at the time of your post so yours did not appear until I clicked "Post".

Please recall that the variance, sigma^2, of a random variable X is given by:

sigma^2 = E((X-E( X ))^2)

This is equivalent to:

sigma^2 = E(X^2)-(E( X ))^2

The computation of variance by the first equation is called the two-pass method because the first pass through the data is used to calculate E( X ) to be used in the second pass to calculate sigma^2. The computation of variance by the second equation is called the one-pass method because the sigma^2 can be calculated with one pass through the data.

The one-pass method is frequently given to students as an example of what not to do. The problem is that the computer is asked to subtract two numbers which may be quite large compared to their difference. As we know, computers are notoriously bad at that. I have read that Excel switched from the one-pass method to the two-pass method in about 2003 because of the problems.

To illustrate the problem in TC2005 please use the PCF's:

Variance Two-Pass:
1000000*(((C1-AVGC21.1)^2+(C2-AVGC21.1)^2+(C3-AVGC21.1)^2+(C4-AVGC21.1)^2
+(C5-AVGC21.1)^2+(C6-AVGC21.1)^2+(C7-AVGC21.1)^2+(C8-AVGC21.1)^2
+(C9-AVGC21.1)^2+(C10-AVGC21.1)^2+(C11-AVGC21.1)^2+(C12-AVGC21.1)^2
+(C13-AVGC21.1)^2+(C14-AVGC21.1)^2+(C15-AVGC21.1)^2+(C16-AVGC21.1)^2
+(C17-AVGC21.1)^2+(C18-AVGC21.1)^2+(C19-AVGC21.1)^2+(C20-AVGC21.1)^2
+(C21-AVGC21.1)^2)/21))

Variance One-Pass:
1000000*(((C1*C1+C2*C2+C3*C3+C4*C4+C5*C5+C6*C6+C7*C7+C8*C8+C9*C9
+C10*C10+C11*C11+C12*C12+C13*C13+C14*C14+C15*C15+C16*C16
+C17*C17+C18*C18+C19*C19+C20*C20+C21*C21)
-(21*AVGC21.1*AVGC21.1))/21)

These were exscripted from your two PCF's with minor modifications. Please update and sort the All Stocks WatchList by each. You will find dissagreement the rule rather than the exception but not by much in actively traded stocks. You will find that the one-pass method gives rise to negative variances which is not possible. When square roots are taken it gives rise to the errors to which Bruce referred. Ordinarily, this is not a problem, but it can be for large periods.

Thanks,
Jim Murphy

PaulEarley
Posted : Friday, February 10, 2006 4:32:16 PM
Registered User
Joined: 8/19/2005
Posts: 5
I know I am on this thread on a totally different level (although I have appreciated trying to recall my statistics). When I use either formula, I get a value of about 27.6 for a test on a stock that had an upper BB at about 87.4 on the day under consideration.

Am I misunderstanding the use of the equation? I was trying to scan for stocks that close above their upper BB "yesterday".

Paul Earley
Bruce_L
Posted : Friday, February 10, 2006 9:53:29 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
PaulEarley,
Much of the above has strayed from your question (the topic itself is far more general than your question). Correct answers to your question would be contained in the Friday, February 10, 2006 8:49:01 AM, Friday, February 10, 2006 10:05:57 AM and Friday, February 10, 2006 10:29:55 AM posts from Tanstaafl and Bustermu.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
PaulEarley
Posted : Saturday, February 11, 2006 9:32:22 AM
Registered User
Joined: 8/19/2005
Posts: 5
Thanks for the input. I worked through the equations carefully and adapted them slightly to get what I need. I have enjoyed this discussion, because it made me dig into the mathmatics more.
Thanks to all
Paul Earley
Tanstaafl
Posted : Monday, February 13, 2006 11:28:59 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Thanks for the explanation, JimM

The fact that the results you are concerned about need to be multiplied by a million in order to illustrate the differences is very significant.

If you do not multiply by anything, then there is no difference (except in extreme-priced stocks like BRKA)

So, from the ivory tower point of view, I agree with you. However, from a practical point of view, for a normal uses of BB's in trading analysis, I would opt for the simpler and quicker form which I suggested.

There is no need to warn people off of a "tried and true" formula on the basis of a supposed need for eight or nine significant figures ... the most that traders normally will require is about five.

"It is the mark of an educated man, and a proof of his culture, that in every problem he addresses he looks for only so much precision as its nature permits, and its solution requires" ... Aristotle / Nichomachean Ethics

Jim Dean

Doug_H
Posted : Monday, February 13, 2006 11:33:01 AM


Worden Trainer

Joined: 10/1/2004
Posts: 4,308
Welcome back, Jim....haven't seen you in here for quite awhile. I wish I had been aware of that quote a long time ago...it is the embodiment of my teaching philosophy. Start simple...only get more complex as the student is ready and motivated to assimilate! As an instructor, it's my job to figure out when that is! Thanks for sharing that!

- Doug
Teaching Online!
Tanstaafl
Posted : Monday, February 13, 2006 11:40:14 AM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Sho, nuf, Doug ... I have used that as a guiding principle in my Engineering practice for three decades. Since I have a tendency towards beating things to death, I have found it very useful to keep my time and efforts more focused.

And yes, you are very right ... a teacher must incorporate the *student's* perceptions and needs in the evaluations of "what the solution requires".

I've been "on sabbitcal" a while ... lots of personal family stuff ... but expect to be getting back on the horse fairly soon.

I hope all is well with you and the crew. Stay warm!

Jim

Doug_H
Posted : Monday, February 13, 2006 11:43:46 AM


Worden Trainer

Joined: 10/1/2004
Posts: 4,308
Three decades of engineering for you...three decades of teaching for me (this year marks the first year of decade #4!). The quote is timeless!

- Doug
Teaching Online!
Bruce_L
Posted : Monday, February 13, 2006 12:03:53 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Tanstaafl,
The example provided by bustermu may have been multiplied by a million for illustration purposes, but as I pointed out in my Friday, February 10, 2006 1:48:49 PM post, the reason I use the longer version is that the shorter version can produce trig errors in actual use in TeleChart as a Custom Indicator.

Take the formulas from your Friday, February 10, 2006 8:49:01 AM post and plot them as indicators (you'll get both Upper and Lower Bands). Everything seems great when you scroll through most symbols in Daily mode. Now switch to 1-Minute Mode and sort All Stocks by Volume 1-Day. Scroll through some symbols with very low volume (it can't be too low or there won't be enough data to calculate the indicator). You will quickly find numerous stocks that will plot for the longer version of the formula but produce trig errors for the shorter version.

Now you may say this is academic and that you would not be interested in such charts, but the change in the way I wrote the formula came only after working with multiple customers requiring formulas including Standard Deviation calculations in exactly this situation.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Tanstaafl
Posted : Monday, February 13, 2006 12:10:42 PM
Registered User
Joined: 10/7/2004
Posts: 799
Location: Duluth, GA
Thanks for the explanation, Bruce ... sorry that I missed your earlier posting.

I'm not sure what Volume has to do with it ... except that there would probably be a lot of flatline cases?

Anyways, if the program produces clearly visible "trig" (floating point?) errors when the simpler formula is applied as a Custom Indicator, then that is certainly a good, pragmatic reason to use the longer form.

I'm curious whether those discrepancies match the delta's shown when a PCF is created with one form of the calc subtracted by the other form.

However, no need to beat on this any further ... I stand corrected. I am surprised because I use BB's extensively, and have not run into any meaningful problems ... maybe because I (like most active traders) rarely mess with low-volume flat-line stocks.

Thanks for your assistance.

Jim

bustermu
Posted : Monday, February 13, 2006 12:39:23 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
That "Trig Error" of which Bruce speaks is caused by trying to take the square root of a negative number which should not be negative.

As we all know, you can be asking for trouble when you let a computer subtract two numbers which are large compared to their difference.

Bruce knows his stuff. So did the Excel people when they changed their program to avoid such problems. I also frequently use the shorter method, but I know where it can lead to trouble. I doubt most users know of the problem.

Thanks,
Jim Murphy
bustermu
Posted : Tuesday, February 14, 2006 4:56:08 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
There is a way to keep the more compact single-pass method and also stay out of trouble.

For example, simply replace:

C1>AVGC21.1+2*SQR((C1^2+C2^2+C3^2+C4^2+C5^2+C6^2+C7^2
+C8^2+C9^2+C10^2+C11^2+C12^2+C13^2+C14^2+C15^2+C16^2
+C17^2+C18^2+C19^2+C20^2+C21^2-21*AVGC21.1^2)/20)

by:

C1>AVGC21.1+2*SQR(ABS((C1^2+C2^2+C3^2+C4^2+C5^2+C6^2+C7^2
+C8^2+C9^2+C10^2+C11^2+C12^2+C13^2+C14^2+C15^2+C16^2
+C17^2+C18^2+C19^2+C20^2+C21^2-21*AVGC21.1^2)/20))

I doubt there would ever be any complaints about this solution when the Bollinger Band period is only 21 or so.

Thanks,
Jim Murphy
Winnie
Posted : Wednesday, February 15, 2006 12:15:47 PM
Registered User
Joined: 10/7/2004
Posts: 1,006
Hi Bruce,

Here I go again, looking for your help to clarify the Bollinger Bands, this is my understanding of BB, there are three lines used for the Bollinger band indicator: the upper, the lower, and the simple moving average between the two. These upper and lower bands are plotted two standard deviations away from the simple moving average. Standard deviation is a measure of volatility, so Bollinger bands adjust themselves to the market conditions. When the markets become more volatile, the bands widen, and, during less volatile periods, they contract. Wide band equals high volatility, narrow band equals low volatility of the stock, as the volatility increases the bands expand.

Width - The variation of the data around the average for the last 20 days. This variation is measured by the standard deviation (SD) of the data from the average. The actual trading band is plotted some number of standard deviations above and below the average. A width of 20 would be 2 standard deviations, 10 would be 1 standard deviation and so on.

For BB 20,17.(Which is a SD of 1.7, correct me if I am wrong)
I have searched the topics and found a lot of BB information but have not found a PCF to:

1. Find stock where prices are between the MA and the Upper Band
2. Find stock where prices are between the MA and Lower Band
3. Find stocks when the Bands are the narrowest.

Another thought, for (item number 1) is to have two PCFs, one PCF for the Upper Band and one PCF for the MA, then start the Upper Band with C< and the MA with C>, would this work?

Thanks
Winnie
Bruce_L
Posted : Wednesday, February 15, 2006 12:25:03 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You might wish to review the following:

Finding Expanding or Contracting Bollinger Bands

Your idea of combining two Personal Criteria Formulas using either an EasyScan or an AND statement is the correct approach to find values between any two lines (assuming you have the PCFs for those lines). There are plenty of BB 20,20 and BB 20,10 PCFs available in the forums. You will notice that the formulas will have the Moving Average +/- 1* or 2* an SQR() function. Changing the 1* or 2* to a 1.7* will give you a Width of 17 or 1.7 Standard Deviations.

The description in Tanstaafl's Saturday, December 18, 2004 10:00:53 AM post starting this topic provides all of the details necessary to write Standard Deviation and Bollinger Band PCFs.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Winnie
Posted : Wednesday, February 15, 2006 12:33:57 PM
Registered User
Joined: 10/7/2004
Posts: 1,006
Thanks Bruce
I'll review those topics

Winnie
Winnie
Posted : Wednesday, February 15, 2006 1:19:52 PM
Registered User
Joined: 10/7/2004
Posts: 1,006
Hi Bruce,

The formulas for items 1 & 2 work perfectly.

BB20,17 Upper Band:
AVGC20 + 1.7 * SQR (((C-AVGC20)^2 + (C1-AVGC20)^2 + (C2-AVGC20)^2 + (C3-AVGC20)^2 + (C4-AVGC20)^2 + (C5-AVGC20)^2 + (C6-AVGC20)^2 + (C7-AVGC20)^2 + (C8-AVGC20)^2 + (C9-AVGC20)^2 + (C10-AVGC20)^2 + (C11-AVGC20)^2 + (C12-AVGC20)^2 + (C13-AVGC20)^2 + (C14-AVGC20)^2 + (C15-AVGC20)^2 + (C16-AVGC20)^2 + (C17-AVGC20)^2 + (C18-AVGC20)^2 + (C19-AVGC20)^2) / 19)


BB20,17 Lower Band:
AVGC20 – 1.7 * SQR (((C-AVGC20)^2 + (C1-AVGC20)^2 + (C2-AVGC20)^2 + (C3-AVGC20)^2 + (C4-AVGC20)^2 + (C5-AVGC20)^2 + (C6-AVGC20)^2 + (C7-AVGC20)^2 + (C8-AVGC20)^2 + (C9-AVGC20)^2 + (C10-AVGC20)^2 +(C11-AVGC20)^2 + (C12-AVGC20)^2 + (C13-AVGC20)^2 + (C14-AVGC20)^2 + (C15-AVGC20)^2 + (C16-AVGC20)^2 + (C17-AVGC20)^2 + (C18-AVGC20)^2 + (C19-AVGC20)^2) / 19)

What about item number 3, to find stocks when the Bands are the narrowest.

Thanks
Winnie

Craig_S
Posted : Wednesday, February 15, 2006 1:42:35 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
Narrowest requires a time period definition... narrowest over what period?

Here is an example of what I mean:

Today is narrowest for past 5 days.

BBu= Upper Band
BBl= Lower Band

BBu-BBl<BBu1-BBul1 AND BBu-BBl<BBu2-BBl2 AND BBu-BBl<BBu3-BBl3 AND BBu-BBl<BBu4-BBl4


- Craig
Here to Help!
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.