#### Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

# Using Addition and Subtraction in StockChart Scans

I'm sure I've missed this in the scan documentation, so I have to ask. Among other uses, I am trying to scan for stocks which have closed in the top 25% of their daily high-low range.

So this would be the test:

[Close > (High - (High - Low)*.0.25)]

Simple, but the syntax is wrong and the "+" and "-" aren't recognized. How do I implement addition and subtraction in scans?

Are there other ways to scan for this condition?

I've moved your question from the Post Testing Area to the Scanning section.

A few different problems;

- ( ) are for functions, use square brackets to group items [ ] .
- also extra decimal in front of the 0.25
- finally math functions are performed left to right so you can change the order or use extra brackets to make sure the operations are performed in the desired order.

Your scan syntax is incorrect. Could not parse "" located in the clause "CLOSE > (HIGH - (HIGH - LOW)*.0.25)"

Try this.

and [Close > High - [High - Low] * 0.25]

edit: correction we need an extra set of brackets, should really be,

and [Close > High - [ [High - Low] * 0.25 ] ]

• Thanks! The use of the square brackets vs parenthesis for grouping was the key I was missing. The extra decimal was a typo in the question.
• Gord,
You fixed my syntax on the addition subtraction issue. Thanks. But the scan is returning stocks that don't meet the criteria:

[Close > High - [High - Low]*0.25]

and I can't figure it out. For example, AGN is included in the scan results (with many others that don't meet the above condition). Oct 31 data: H = 191.90, L = 188.74, C=190.06.

Evaluating the above criterion yields:

190.06 > 191.11, which is false! What's up? Numerous other examples are in scan result. What am I missing?

Entire scan is:

[type = stock] AND [Daily SMA(20,Daily Volume) > 400000]
and [SMA(50) > SMA(100)]
and [Close > SMA(50)]
and [Close > Open]
and [Close > [High - [High - Low]*0.25] ]
and [Optionable is true]
jjkumpel, I moved your comment from my personal wall to here so all the comments are together and others can learn in the future.

Yep I see there is an extra set of brackets that would be required when writing it in this order.

and [Close > High - [ [High - Low]*0.25 ] ]

I prefer to write it in a more simple order as follows; (less brackets required)

and [close > range * 0.75 + low]

or you could write it as;

and [Close > 0.75 * [High - Low] + low ]
• Thanks. What finally worked was:

[Close >= [ [0.75*High] + [0.25*Low] ] ]

Apparently each operation needs to be enclosed in it own set of square brackets when addition or subtraction is involved. Multiplication and division don't require separate bracketed clauses.
Yes and No, here's the section on math functions from the documentation on advanced scan syntax.

Arithmatic Expressions

Arithmatic Expressions are evaluated from left to right and ignore prescedence. Therefore if prescedence matters, one must again use brackets to make the computation explicit:

The following expression would evaluate to -3:

1 + 2 / 3 - 4

Use brackets to specify your intended order if it is something different:

[[1 + 2] / [3 - 4]]

******************
Depending on how your mind likes to think of relationships we will all write it a little differently. As of today the following clauses when used in your scan all return the same 201 hits.

and [Close > High - [ [High - Low]*0.25 ] ]
and [Close > 0.75 * [High - Low] + low ]
and [close > range * 0.75 + low]

With respect to your solution clause;
and [Close > [ [0.75*High] + [0.25*Low] ] ]
its actually a variation of the second clause above.

For more details on the subject of math functions and the different ways they can be written see this article.

http://stockcharts.com/articles/scanning/2014/02/writing-a-scan-how-does-your-mind-think.html