New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.
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?
0
Answers
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]
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 ]
[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.
http://stockcharts.com/docs/doku.php?id=scans: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