Print Page | Close Window

or/and conditions in same scan

Printed From: BullCharts Forum
Category: BullCharts
Forum Name: BullScript
Forum Discription: Technical discussion related specifically to the BullScript programming language.
URL: http://www.bullcharts.com.au/forum/forum_posts.asp?TID=388
Printed Date: 24 Apr 2025 at 8:22am
Software Version: Web Wiz Forums 9.69 - http://www.webwizforums.com


Topic: or/and conditions in same scan
Posted By: cudderbean
Subject: or/and conditions in same scan
Date 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.




Replies:
Posted By: cudderbean
Date 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.



-------------



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums® version 9.69 - http://www.webwizforums.com
Copyright ©2001-2010 Web Wiz - http://www.webwiz.co.uk