New version 18 available now


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


New account application Trading resources
Margin rates Stock & option commissions

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

Fun with Logical Operators Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Al_Gorithm
Posted : Saturday, February 09, 2019 1:04:13 PM

Gold Customer Gold Customer

Joined: 6/30/2017
Posts: 1,211

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.

HarleyBD
Posted : Sunday, February 10, 2019 8:12:44 AM
Gold Customer Gold Customer

Joined: 6/30/2014
Posts: 55

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

 

bcochrane
Posted : Sunday, February 10, 2019 9:00:37 AM
Registered User
Joined: 9/17/2010
Posts: 468

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

Al_Gorithm
Posted : Sunday, February 10, 2019 4:07:16 PM

Gold Customer Gold Customer

Joined: 6/30/2017
Posts: 1,211

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 back-of-the-napkin 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))

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?

Bruce_L
Posted : Monday, February 11, 2019 11:44:13 AM


Worden Trainer

Joined: 10/7/2004
Posts: 64,759

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
Al_Gorithm
Posted : Monday, February 11, 2019 12:49:31 PM

Gold Customer Gold Customer

Joined: 6/30/2017
Posts: 1,211

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

Bruce_L
Posted : Monday, February 11, 2019 1:11:35 PM


Worden Trainer

Joined: 10/7/2004
Posts: 64,759

You're welcome.



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