or/and conditions in same scan |
Post Reply |
Author | |
cudderbean
Regular Joined: 02 Oct 2006 Location: Thailand Posts: 40 |
Post Options
Quote Reply
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. |
|
cudderbean
Regular Joined: 02 Oct 2006 Location: Thailand Posts: 40 |
Post Options Quote Reply 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); {Condition} ((Close > _var1) Thumbs up to the BC development team: I'm thoroughly enjoying your product. |
|
Post Reply |
Forum Jump | Forum Permissions 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 |