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.
Scanning against Top 3 Sector (Week or Month timeframe)
I saw this
thread which is somewhat helpful but didn't say clearly.
Below is the scan code I have. I want to do this scan against the top 3 sectors listed at
https://stockcharts.com/freecharts/sectorsummary.html in the one week and one-month time periods (Either time period works).
Is it possible?
[type is stock]
and [country is US]
and [exchange != PINK]
and [sma(20,volume) > 1000000]
and [Close > 1]
and [close > SMA(200)]
and [SMA(50) > SMA(200)]
and [EMA(5) > EMA(10)]
Thanks in advance for your help
0
Comments
Add every sector to your scan preceded by "//" double forward slashes. The "//" causes the scan engine to skip that line. When you want to run the scan against a particular sector, delete the "//". Make sure all the other sectors have the ''//" in front of them. Run the scan three times, once against each top sector for that week/month.
I've deleted the first three lines because specifying the sector and exchange makes them unnecessary.
This version will run the scan conditions against the Utilities sector.
// [group is EnergySector]
// [group is MaterialsSector]
// [group is IndustrialSector]
// [group is ConsumerDiscretionarySector]
// [group is ConsumerStaplesSector]
// [group is HealthCareSector]
// [group is TechnologySector]
// [group is CommunicationServicesSector]
// [group is FinancialSector]
// [group is RealEstateSector]
[group is UtilitiesSector]
and [ [ exchange is NYSE] or [exchange is NASD] ]
and [sma(20,volume) > 1000000]
and [Close > 1]
and [close > SMA(200)]
and [SMA(50) > SMA(200)]
and [EMA(5) > EMA(10)]
To get the top sectors for the period you want, go to the Sector Summary page and click the "Period" drop down and select one week or one month (or whatever period you want).
Then sort the list on the %CHG column, and run the scan for each of the top three sectors per the directions above.
I was hoping to set up a scheduled scan. Apologies for not being clear on the "scheduled scan" part. That is where I was stuck.
https://stockcharts.com/scheduled-scans/sscans
It appears you can set up a schedule on this page - it's link is on the scan workbench page at the top.
The drop downs seem to be pretty self - explanatory. Select a scan, a day a time and a destination list. You could run weekly by selecting Saturday with a custom time. It doesn't look like you could do monthly.
However, since you would have to alter the scan as written each week according to changing sector leadership, scheduling doesn't seem to be necessary.
Alternatively, you could create a separate scan for each sector, schedule them all to run on Saturday at a custom time, e.g. 9 am, choosing "replace existing chartlist" (created beforehand, named for the sector, then selected on the scheduling page) and then review only the top 3 per the sector summary page. I say Saturday and not Friday close because the data continues to change for a couple of hours after the exchanges close.
I would add some kind of ranking to the scan - say, rank by ROC(5), or some other parameter, in case the number of results tops the chartlist limit. Also, if you only want gainers, you could add a scan condition like
and [ROC(5) > 0]
or whatever you want.
I don't use the schedule feature, so maybe others have further tips.
Pick your universe. markd gives you the Nyse and Nasdaq options. You are looking at the SPIDER data for the "top" sectors. The SPIDERS are based off the SP500 so you could use that index and add your other trend MA lines in there also. If you do, I think the two lines regarding volume and close > 1 aren't needed.
The part below the AND in this is a template option for you to
use IF you can understand this instruction. All of the group sectors are listed as individual lines. The 1st group, in this case the XLC, has nothing in front of the line. All the other group sectors have an OR in front of them. So your selections in the section will start with NOTHING in front of the 1st and OR in front of all the others you want to use.
[group is SP500]
//and [sma(20,volume) > 1000000]
//and [Close > 1]
and [close > SMA(200)]
and [SMA(50) > SMA(200)]
and [EMA(5) > EMA(10)]
and
[
[group is CommunicationServicesSector] //XLC
or [group is ConsumerDiscretionarySector] //XLY
or [group is ConsumerStaplesSector] // XLP
or [group is EnergySector] //XLE
or [group is FinancialSector] //XLF
or [group is HealthCareSector] //XLV
or [group is IndustrialSector] //XLI
or [group is MaterialsSector] //XLB
or [group is RealEstateSector] //XLRE
or [group is TechnologySector] //XLK
or [group is UtilitiesSector] //XLU
]
// adding this rank by will show the top securities by RS vs their Sector for the last "month"
rank by [PctRelative(21,$sector)]
__________________________________________________________________________
This is the example from above with only 3 sectors INCLUDED in the scan.
Let's say your "top 3" are XLC, XLB and XLK
[group is SP500]
//and [sma(20,volume) > 1000000]
//and [Close > 1]
and [close > SMA(200)]
and [SMA(50) > SMA(200)]
and [EMA(5) > EMA(10)]
and
[
[group is CommunicationServicesSector] //XLC
//or [group is ConsumerDiscretionarySector] //XLY
//or [group is ConsumerStaplesSector] // XLP
//or [group is EnergySector] //XLE
//or [group is FinancialSector] //XLF
//or [group is HealthCareSector] //XLV
//or [group is IndustrialSector] //XLI
or [group is MaterialsSector] //XLB
//or [group is RealEstateSector] //XLRE
or [group is TechnologySector] //XLK
//or [group is UtilitiesSector] //XLU
]
If you find that your top 3 are XLC, XLB and XLK, you would put double back slashes in front of all the others that aren't XLC, XLB or XLK. So you will have NOTHING in front of XLC and // in front of the or on XLY, and XLP and XLE, etc.
__________________________________________________________________________________
Another example with only 3 sectors INCLUDED in the scan.
your top 3 are XLY, XLI and XLK. NOTE the OR was removed from in front of XLY. NOTHING in front of 1st sector, OR in front of the others you want. // in front of the ones you don't want.
[group is SP500]
//and [sma(20,volume) > 1000000]
//and [Close > 1]
and [close > SMA(200)]
and [SMA(50) > SMA(200)]
and [EMA(5) > EMA(10)]
and
[
// [group is CommunicationServicesSector] //XLC
[group is ConsumerDiscretionarySector] //XLY
//or [group is ConsumerStaplesSector] // XLP
//or [group is EnergySector] //XLE
//or [group is FinancialSector] //XLF
//or [group is HealthCareSector] //XLV
or [group is IndustrialSector] //XLI
//or [group is MaterialsSector] //XLB
//or [group is RealEstateSector] //XLRE
or [group is TechnologySector] //XLK
//or [group is UtilitiesSector] //XLU
]
Below is the code I ended up with. Sharing the code for anyone else that might find it useful Below are the results: That is a VERY strong list.
I merge the results to an existing chartlist, appropriately named and then use that list in scans or reviews.
I have a SS that looks at this list and return the ones that the column reversed to O's and add those results to another appropriately named chartlist. And then another SS that looks at the O's list and returns results that had reversed back to X's and added those to another appropriately named list. After a while I ended up with too many lists with data in them that wasn't appropriate. The O list had things in X's as the O's list doesn't remove anything, only adds new ones. Same with the X's list. So scheduled scans didn't work well in this situation.
I ended up creating, what I call, referential integrity scheduled scans, to run on certain lists once a week. One scan looks at the O's list and returns the symbols that are in O's, then replaces the O's list. Same with the X's list.
You really have to experiment and think through what you want to do with Scheduled Scans and what the lists will look like over time.
I often convert many of those types of things to Alerts. You get an email with the names and you can then do with them what you wish. Add them to a chartlist, just review the charts, or ignore them completely. You do have more flexibility at the moment with scheduling the Scans vs the Alerts. Scans you can pick and choose days
If you create a scheduled scan to create new chartlists, just be aware that you do have a limit on the number of chartlists on your account, that can be quickly reached if you let the scheduled scans run amuck. If you run it 5 days a week, that's 5 new lists. After a month you have 20 or so. If you have multiple SS doing the same, you will have a lot of lists. I don't know what the SS does if you've reached your chartlist limit.
My advice is to try using your scan as an alert first. You can use the same code, it just notifies you with the list instead of making a list. If you want to take that Alert to a Scheduled Scan, then you can do so. Just be aware of the limitations.
Another difference between Alerts and Scans/Scheduled Scans is that you have saved scan code that you use for the scans. You can use the same code for the Alerts. IF YOU CHANGE your scan code for your scans, it does NOT automatically update the Alert code. The Alert code is a separate entity. So you'd need to update that, if you desire, to the updated scan code.
You would change the
[Group is SP500]
to
[[Group is SP500] or [Group is SP400]]
for example, if you wanted to include the SP midcaps.
[[Group is SP500] or [Group is SP400] or [Group is SP600]]
to use the SP1500. Expanding the range can allow you to see, possibly, better options to consider.
Also, RANK BY SCTR is going to rank by the securities that have moved the furthest from their respective intermediate and longer term moving averages as the highest value. Definitely the 'best' performers will have high SCTR values, but does that make them an opportune purchase? It all depends on your system I suppose. Many of the StockCharts.com blog authors recommend looking at the ones that are moving up into the 70/80 and above area. Moving up being the operative phrase.
If you specify the sector group in your scan - e.g. [group is FinancialSector] - and DO NOT specify an SP group - 500, 400, 600 - the scan will return ALL stocks, not just SP index stocks, included in that sector that also meet the remaining scan criteria.
To prove this - run a scan that has only one line -
[group is FinancialSector]
You should get every symbol that Stockcharts has classified as Financial Sector. There will be more symbols than can fit on the results page, but it will prove the point.