52 week New Highs for S&P 500
Author: smiranda
Creation Date: 4/6/2010 8:33 AM
profile picture

smiranda

#1
Hello,

I am looking to graph the 52 week new highs for the S&P 500 & the Russell 2000. Any ideas as to how this can be done?

Many Thanks in advance.
Sameer
profile picture

Eugene

#2
Is this what you had in mind (from a daily chart)?
CODE:
Please log in to see this code.
profile picture

smiranda

#3
Hello Eugene,


I probably was not clear in my initial question. Hopefully I do a better job here.
What I want is to chart the number of stocks in the S&P 500 that are making new 52 week highs each day.

Thanks for your reply.
profile picture

Eugene

#4
Not a problem either. Code below will give you a "design pattern" to look for the number of stocks in a portfolio that meet some criteria. In this case, hitting a 252-day high (i.e. roughly the number of trading sessions in 52 weeks to simplify coding):
CODE:
Please log in to see this code.
profile picture

smiranda

#5
Thanks Eugene, I think that I am getting closer. It works however I think that I am missing something.
Here is what I did, I opened a daily chart of .spx & put this code in the strategy & I can now see the histogram.
However how does the code know the individual stocks of the .spx as I do not provide this information anyway to the strategy.
profile picture

Eugene

#6
I forgot to mention that you should run this code not on a chart of .SPX, but on the DataSet that contains the complete set of S&P 500 symbols. Only in this case will the strategy "know" the individual components of the index, be it Russell 2000 or the S&P 500. In other words, code is DataSet-dependent. QuickRef for how the DataSetSymbols method works.
profile picture

smiranda

#7
Sorry to bug you. this is really dumb, how do I execute the strategy for a dataset ?
I opened the strategy monitor, selected the strategy that I created using the code that you provided, selected the dataset in strategy activation settings. I then chose "Run this strategy Now". However nothing happens. I do not see any chart.

Any ideas what I am doing wrong?
profile picture

Eugene

#8
There is no point to run this code in SM now, as it does not have any trading rules yet.

With the Strategy Window open, clicking on any symbol of the DataSet will execute this specific strategy "for a dataset". It's programmed to loop over the symbols in a DataSet, so you can even run it in single symbol mode. Make sure at least 252 bars of data are loaded (i.e. Data Range).

In short, just open a strategy window and click on any symbol. The histogram you'll see on the bottom should be identical regardless of the symbol clicked (provided that they have an equal amount of bars, of course.)