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.
Scan Help, support/resistance
Hello,
I want to create a scan that can look for stocks that have broken through major resistance and then have come back to retest that resistance turned support days or weeks later. Also on a downtrend, stocks that have broken major support, and then days or weeks later, comes back and retests those levels.
I am having a hard time trying to figure out how to create a scan for this where it finds stocks at former support/resistance levels.
Any help would be appreciated
Thanks
0
Comments
I think your best bet is to experiment with price channels.
So, your first test would be for an upper price channel that was flat during some period in the past. If the price channel is flat, then price must be under that upper channel. So lets say 60 days ago upper price channel = 40 days ago upper price channel ( you have to experiment with a length for the upper price channel and the length of time it is flat).
Then you want to test for a more recent price above the old upper price channel value, so maybe 20 days ago close > 40 days ago upper price channel (maybe time 1.10, or ten per cent higher).
Finally, you want to test for a current price back near the upper price channel, so maybe close < 40 days ago upper price channel * 1.01, and close > upper price channel * .99 - in other words, within about 1 per cent plus or minus.
You will have to experiment (probably a lot) with the parameters to get decent results. Also, try back dating the scan to see how it works in different markets.
If you'd like to give it a shot, here's a summary of the rules from an earlier post:
Basic rules for the scan engine
Every statement begins with “and” except the first one
Every statement, except the word “and”, goes between square brackets [ ]
NOTE: Parentheses are reserved for indicators and functions, like RSI(14) or max(10,close). If you need to group arithmetic expressions, use more square brackets, not parentheses: For instance:
And [ [high – close]/max(10, close) > 10]
Every statement contains an operator. Valid operator are: is, is not, >, <, =, !=, >=, <=, x, contains, not contains.” !=” means “not equal to”. “x” means “crosses above”.
Every statement has one value preceding the operator and one value after the operator. Values can be indicators, overlays, numbers, reserved words like group, market cap, close, etc. (see drop downs on Advanced Scan page) or expressions using these values. Some examples:
[group is SP500] // note: this would be a first scan statement because it doesn’t begin with “and”
And [MACD Line(12,26,9] > 20]
And [MACD Line(12,26,9) x MACD Signal(12,26,9)]
You can also write “or” statements. “Or” statements need to be isolated with an extra set of brackets
// begin scan
[group is sp500]
// get bullish and bearish crossovers
And
[
[ MACD Signal (12,26,9) x 20]
Or
[ 80 x MACD Signal(12,26,9)]
]
// end scan
The double slashes "//" tell the scan engine to ignore everything on that same line that comes after the "//". So you can use that space to explain to yourself (for later) what you thought you were trying to do in the scan code.
NOTES on scan logic with “and” and “or”:
If a scan has ONLY “and” statements, all the “and” statements must be true for the scan to return a symbol.
If a scan has ONLY “or” statements, then only one condition must be true to return a symbol.
If a scan has a mix of “and” and “or” statements, the results depend on whether you isolated the “or” statement with extra brackets as shown above:
If you don’t use the brackets, then only one condition in the entire scan has to be true to return a symbol.
If you do use brackets, then every “and” condition must be true AND at least one “or” condition must be true to return a symbol.
Start simple.
It's actually harder to figure out WHAT to code than HOW to code.
For instance, how would you code for a rising SMA 200?
You need to think about what would be true if the SMA 200 really is rising. First thought - the value today would be different from the value yesterday, or maybe 10 days ago or 100 days ago.
And it would be greater because it is rising. So the scan would compare today's SMA 200 to the past SMA 200 and it would be greater, so:
and [sma(200,close) > 10 days ago sma(200, close)]
and [3 month ago low *.95> 2 month ago low]
and [group is SP500]
and[exchange = nyse]
if not, change 3 month ago to 63 days ago, 2 month ago to 42 days ago. A scan will be more accurate if you keep everything in one time frame (in this case, daily). Assumes 21 trading days in a month - in fact it varies between 19 and 22, so 20 or 21 works pretty well.
Also, better to put group and exchange at the top of the scan - remember, first character of the first line of any scan must be a bracket; all subsequent lines start with "and".