Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Average True Range Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
rutz
Posted : Sunday, June 25, 2006 6:01:06 PM
Registered User
Joined: 12/18/2004
Posts: 1
Hi
Would anyone know how to create a PCF for calculating the 20 day Average True Range for a selection of stocks ?

Thanks
Silvano
Craig_S
Posted : Sunday, June 25, 2006 8:18:46 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
Check out this post:

AVERAGE TRUE RANGE PCF

I found this by searching the forums. You too can search these forums for anything. Watch this short video on how to get the most from these forums: Learn how to use the forums: post a new topic, reply, Search existing topics

- Craig
Here to Help!
ritaritzw
Posted : Tuesday, July 4, 2006 1:31:28 PM
Registered User
Joined: 4/10/2006
Posts: 10
Craig

Please help me write PCF for indicator of : 3 period simple moving average of 5 period average true range.

Thanks,

Alexander
Bruce_L
Posted : Tuesday, July 4, 2006 5:10:57 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
ritaritzw,
Please try the following:

XAVG(AVGH3,9) - XAVG(AVGL3,9) + .033375339 * (ABS(H - C1) + ABS(L - C1) - H + L + 1.8 * (ABS(H1 - C2) + ABS(L1 - C2) - H1 + L1 + 61 / 45 * (ABS(H2 - C3) + ABS(L2 - C3) - H2 + L2 + .8 * (ABS(H3 - C4) + ABS(L3 - C4) - H3 + L3 + .8 * (ABS(H4 - C5) + ABS(L4 - C5) - H4 + L4 + .8 * (ABS(H5 - C6) + ABS(L5 - C6) - H5 + L5 + .8 * (ABS(H6 - C7) + ABS(L6 - C7) - H6 + L6 + .8 * (ABS(H7 - C8) + ABS(L7 - C8) - H7 + L7 + .8 * (ABS(H8 - C9) + ABS(L8 - C9) - H8 + L8 + .8 * (ABS(H9 - C10) + ABS(L9 - C10) - H9 + L9 + .8 * (ABS(H10 - C11) + ABS(L10 - C11) - H10 + L10 + .8 * (ABS(H11 - C12) + ABS(L11 - C12) - H11 + L11 + .8 * (ABS(H12 - C13) + ABS(L12 - C13) - H12 + L12 + .8 * (ABS(H13 - C14) + ABS(L13 - C14) - H13 + L13 + .8 * (ABS(H14 - C15) + ABS(L14 - C15) - H14 + L14 + .8 * (ABS(H15 - C16) + ABS(L15 - C16) - H15 + L15 + .8 * (ABS(H16 - C17) + ABS(L16 - C17) - H16 + L16 + .8 * (ABS(H17 - C18) + ABS(L17 - C18) - H17 + L17 + .8 * (ABS(H18 - C19) + ABS(L18 - C19) - H18 + L18 + .8 * (ABS(H19 - C20) + ABS(L19 - C20) - H19 + L19 + .8 * (ABS(H20 - C21) + ABS(L20 - C21) - H20 + L20 + .8 * (ABS(H21 - C22) + ABS(L21 - C22) - H21 + L21 + .8 * (ABS(H22 - C23) + ABS(L22 - C23) - H22 + L22 + .8 * (ABS(H23 - C24) + ABS(L23 - C24) - H23 + L23 + .8 * (ABS(H24 - C25) + ABS(L24 - C25) - H24 + L24 + .8 * (ABS(H25 - C26) + ABS(L25 - C26) - H25 + L25 + .8 * (ABS(H26 - C27) + ABS(L26 - C27) - H26 + L26 + .8 * (ABS(H27 - C28) + ABS(L27 - C28) - H27 + L27 + .8 * (ABS(H28 - C29) + ABS(L28 - C29) - H28 + L28 + .8 * (ABS(H29 - C30) + ABS(L29 - C30) - H29 + L29 + .8 * (ABS(H30 - C31) + ABS(L30 - C31) - H30 + L30)))))))))))))))))))))))))))))))

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Tuesday, July 4, 2006 11:18:03 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

My compliments on your approach.

I was also going to tell you that the 0.033366378 should be changed to 0.033375339, but I see that you have already made that change. The difference is not noticable, but I found the discrepancy while verifying your coefficients.

Thanks,
Jim Murphy

PS. I'll bet he wanted the ATR(5) to be an SMA rather than Wilder Smoothing? Do you think he knows where that 9 comes from?
Bruce_L
Posted : Wednesday, July 5, 2006 8:11:09 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (bustermu)
My compliments on your approach.

Thanks. It wasn't the first approach I tried, but it did seem to be the cleanest. I'm not sure it would have worked out so well if the SMA had a longer period (I haven't tried it, but suspect the coefficients would get rather messy). A 3-Period Simple Moving Average didn't present any problems however.

QUOTE (bustermu)
I was also going to tell you that the 0.033366378 should be changed to 0.033375339, but I see that you have already made that change. The difference is not noticable, but I found the discrepancy while verifying your coefficients.

The post was originally based on using the results of an Average True Range spreadsheet I already had, nesting the initial averages and adjusting the coefficients for the first three terms (but all I did with the first term was divide it by three). I had manually checked the results against values returned on the charts and the difference was "not noticeable". I did eventually adjust the initial coefficient for unity (but apparently not before it was noticed).

QUOTE (bustermu)
I'll bet he wanted the ATR(5) to be an SMA rather than Wilder Smoothing? Do you think he knows where that 9 comes from?

I'm sure ritaritzw will let us know if the supplied formula is not adequate. Following Craig's first link brings up a formula for True Range and a list of topics that include explanations on the use of Wilder's Smoothing when calculating Average True Range.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Wednesday, July 5, 2006 10:11:41 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

I would expect one without your ability to have averaged three EMA9 series approximations each using the same number of terms. It would work, but where is the elegance in that?

Thanks,
Jim Murphy
Bruce_L
Posted : Wednesday, July 5, 2006 10:48:18 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bustermu,
I wish I could claim the formula was the result of logical thinking on my part, but must admit averaging three EMA9 series approximations was my first thought and that the resulting formula was more the result of taking the path of least resistance than any sort of inspiration. This first method was quickly discarded, not for reasons of elegance, but because it would obviously be well... long (I didn't even go through the exercise of actually creating the formula).

My second thought was to use Theorem 2 from Cascades of Moving Averages (AVG(EVG(X,P),Q) = AVG(X,Q)-((P-1)/(2*Q))*EVG((X-XQ),P)). It might have simplified down into something reasonable, but it seemed that this approach would also produce a rather long formula (I didn't think about it too much and again decided against actually creating it).

Pre-calculating the coefficients was my next thought (and the least elegant so far, but short and simple) and the easiest way to do this was to create a spreadsheet. Modifying an existing spreadsheet is easier than creating a new one and it seemed logical to start with what was already written for Average True Range. But it quickly became apparent that the simplest spreadsheet modification was also both shorter and far more elegant than pre-calculation (and that was that).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Wednesday, July 5, 2006 2:03:05 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

If we are interested in elegance, we should replace the TR PCF:

(H-L+ABS(H-C1)+ABS(C1-L))/2

by the TR PCF:

H-L+(C1>H)*(H-C1)+(C1<L)*(C1-L)

This places the filter approximation on a much smaller nonnegative quantity (usually zero).

I'm sure this will cause you to rewrite all of those ATRs with Wilder Smoothing. Right?

Thanks,
Jim Murphy
Bruce_L
Posted : Wednesday, July 5, 2006 2:48:40 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (bustermu)
I'm sure this will cause you to rewrite all of those ATRs with Wilder Smoothing. Right?

I would have thought outlining my rather haphazard thinking earlier would have made it fairly obvious that I have only a limited interest in elegance (at least for the sake of elegance itself), but let's take a look:

H-L+(C1>H)*(H-C1)+(C1<L)*(C1-L) appears to produce the same results as (H-L+ABS(H-C1)+ABS(C1-L))/2.
H-L+(C1>H)*(H-C1)+(C1<L)*(C1-L) doesn't appear to be faster than (H-L+ABS(H-C1)+ABS(C1-L))/2.
H-L+(C1>H)*(H-C1)+(C1<L)*(C1-L) is several characters longer than (H-L+ABS(H-C1)+ABS(C1-L))/2.
H-L+(C1>H)*(H-C1)+(C1<L)*(C1-L) uses unsupported conditionals, while (H-L+ABS(H-C1)+ABS(C1-L))/2 uses only supported functions.

I don't think I'll rewrite them just yet (although I suppose I might produce formulas based on H-L+(C1>H)*(H-C1)+(C1<L)*(C1-L) if specifically requested).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Wednesday, July 5, 2006 4:06:20 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

The point was that the EMA approximating series was applied to a very much smaller quantity when the second form for TR is used. Thus, for the same number of terms in the EMA series approximation, the use of the second form is much more accurate.

You could write TR as:

H-L+(ABS(H-C1)+ABS(C1-L)-H+L)/2

and apply the approximating series to the entire expression:

(ABS(H-C1)+ABS(C1-L)-H+L)/2

and regain the lost accuracy. But, the last expression is equivalent to:

(C1>H)*(H-C1)+(C1<L)*(C1-L)

I'll bet we could apply the series to the first form for TR and then cut the number of terms in the series in half using the second form for TR and still be more accurate (for SP-500).

Thanks,
Jim Murphy
Bruce_L
Posted : Wednesday, July 5, 2006 4:54:26 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
OK. Increased accuracy interests me.

Spreadsheets rewritten.

-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.