BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: or/and conditions in same scan
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

or/and conditions in same scan

 Post Reply Post Reply
Author
Message / View First Unread Post
cudderbean View Drop Down
Regular
Regular
Avatar

Joined: 02 Oct 2006
Location: Thailand
Posts: 40
Post Options Post Options   Quote cudderbean Quote  Post ReplyReply Direct Link To This Post Topic: or/and conditions in same scan
    Posted: 02 Oct 2006 at 11:41am

I am loving Bullcharts but I am still on a learning curve with Bullscipt. Apologies to members if it’s something I’ve missed..Could someone please write a simple Bullscript which demonstrates how to write two sets of “alternative” conditions all in the “same” scan…like Excel’s IF(OR(AND(…,…),(AND…,…)).

For example,

I want to grab both sets of contingencies in the “same” scan..

EITHER

the close is greater than the simple 14 day MA of the close AND the MACD Histogram is greater than 0

OR,

the close is greater than the simple 14 day MA of the close AND Directional Movement +DI crosses above the Directional Movement -DI

 

 

{Variables}

_var1 := ma(Close,14,Simple);

_var2 := formula("MACD Histogram", 12, 26, 9);

_var3 := formula("Directional Movement +DI", 14);

_var4 := formula("Directional Movement -DI", 14);

 

{Condition}

{EITHER} filter := (Close > _var1)

             and (_var2 > 0)

 

{OR}

             and (Close > _var1)

             and (cross(_var3, _var4));

filter;

 

Thank you for your help.

Back to Top
cudderbean View Drop Down
Regular
Regular
Avatar

Joined: 02 Oct 2006
Location: Thailand
Posts: 40
Post Options Post Options   Quote cudderbean Quote  Post ReplyReply Direct Link To This Post Posted: 10 Oct 2006 at 1:11am

I think I've answered my own question by doing the obvious... RTBM - "Read The Blinking Manual!". Durrrrh! I'm always like this with new software, like a kid, rip open the Christmas parcel and start playing without reading the instructions. Anyway, for the benefit of other newbies in the same boat as me, here is the solution:

Under the section Logical Operators in the Bullscript Help Files:

"Note in the table above that AND has a higher order of precedence than OR. The AND and OR operators behave like multiply and plus with respect to each other. For example, the expression: "tea OR coffee AND sugar" is actually interpreted to be "tea OR (coffee AND sugar)". Parentheses must be manually added to force the OR to have a higher precedence, such as in: "(tea OR coffee) AND sugar" This may seem counter intuitive at first, but it is standard in most computer languages."

Here's the answer I was looking for. Note the brackets!

{Variables}

_var1 := ma(Close,14,Simple);
_var2 := formula("MACD Histogram", 12, 26, 9);
_var3 := formula("Directional Movement +DI", 14);
_var4 := formula("Directional Movement -DI", 14);

 {Condition}
filter := ((Close > _var1)
              and (_var2 > 0))
 or

              ((Close > _var1)
              and (cross(_var3, _var4)));
filter;

Thumbs up to the BC development team: I'm thoroughly enjoying your product.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz