Gold Customer
Joined: 6/30/2017 Posts: 1,227

Happy Monday Bruce,
I got the following PCF from Doug Campbell over at Right Way Options. He shares it freely so there's no copyright or intellectual property issues posting it:
L <= XAVGC8 and C > XAVGC8 and (C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3)
Question: what is the precedence or order of operations for ORs and ANDs in PCFs? Even though coding is my day job, I was always too lazy (lol) to learn the rules so I use enough parentheses to leave absolutely no doubt.
I guess what I'm really asking is, ... wtf is this PCF doing? I have a general idea, but don't want to assume. :)
Thanks ... hope you enjoyed your weekend ... I'm doing laundry ... lol.

Platinum Customer
Joined: 6/30/2014 Posts: 60

I with you Mr. Gorithm.
I would have to hope for "Please Excuse My Dear Aunt Sally".
(Parentheses, Exponents, Multiplication, Division, Addition, Subtraction)
The issue is with 1/2*x or similar: does it mean (1/2)*x or does it mean 1/(2*x)?
Regards

Registered User Joined: 9/17/2010 Posts: 484

I don't know where Doug offered this PCF, but I suspect he means this
L <= XAVGC8 and C > XAVGC8 and ((C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3))
I tried scanning with the PCF as you had it, and with the above formulation, and both returned the same number of stocks (188 from High Cap 1000 today), hence I would conclude that the two are equivalent

Gold Customer
Joined: 6/30/2017 Posts: 1,227

Thanks to you both for the feedback. I just got home, am overly caffeinated and in need of a nap, but when my brain cells are fully engaged, I'll review your comments.
For now, my backofthenapkin interpretation of the logic is ...
Condition returns True if

L <= XAVGC8

and C > XAVGC8

and (C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3)
I'm not sure where on the OCD spectrum I fall, lol, but here's what I think I would code this as ...
(L <= XAVGC8) and (C > XAVGC8) and ((C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3))
I think ANDs trump ORs in the precedence heirarchy, so my extra parentheses are probably redundant, but what the h#ll  it makes sense to me. :)
As to the source, Doug has been sharing this PCF for ages in his Right Way Options chat room, and on his site. The most recent reference is a You Tube video he just recorded a few days ago. This PCF is just one condition in my larger trading plan, but the video can be found at ...
Catching Profits in the 3/8 Trap
Bruce, what do you think?

Worden Trainer
Joined: 10/7/2004 Posts: 65,138

OR does happen before AND in the Personal Criteria Formula Language, so it is possible to write this as just the following.
L <= XAVGC8 AND C > XAVGC8 AND C < XAVGC3.1 OR C < XAVGC3.2 OR C < XAVGC3.3
But I would normally add the parentheses for the sake of clarity (I frequently add unnecessary parentheses to my formulas for just this reason).
L <= XAVGC8 AND C > XAVGC8 AND (C < XAVGC3.1 OR C < XAVGC3.2 OR C < XAVGC3.3)
You can also shorten this a bit using the MAX() function. This might introduce additional clarity as to what it is actually doing or reduce it depending on how you think about these things.
L <= XAVGC8 AND C > XAVGC8 AND C < MAX(XAVGC3.1, 3)
Bruce Personal Criteria Formulas TC2000 Support Articles

Gold Customer
Joined: 6/30/2017 Posts: 1,227

Thanks, Bruce! I like this version the best ...
L <= XAVGC8 AND C > XAVGC8 AND (C < XAVGC3.1 OR C < XAVGC3.2 OR C < XAVGC3.3)
It's the closest to the way my brain is wired, and saves several pairs of parentheses over my version. :)

Worden Trainer
Joined: 10/7/2004 Posts: 65,138

You're welcome.
Bruce Personal Criteria Formulas TC2000 Support Articles
