Click here to Login





How to get stocks for a particular index using the global script

Updated on 2011-12-12 03:58:12

Share |

There are two ways to get a list of stock symbols for a particular index using the global script tool.

1- Create a new symbols filter using the "Symbol -> Symbols View" tool

- Right click on the control then click on "Create a new symbols filter"
- Click on "Add Condition" then select "Index"
- Double click on the cell under "Values", select an index then click on "OK"
- Type a name for this symbols filter. Example: S&P500

- Open the script editor by selecting "Tools" then "Script Editor"
- Create a new file then type the following formula:

Symbol[] symbols = Symbols.GetSymbols("S&P500", "");

This will check for the "S&P500" symbols filter item and return all stocks referenced by this filter.




2- Another way to do this is by looping through all symbols and then checking whether a symbol is referenced by a particular index such as the S&P 500, the Dow Jones or the Russell 2000.

List list = new List();
Symbol[] symbols = Symbols.GetSymbols();
for(int i=0;i < symbols.Length;i++)
{
   Symbol symbol = symbols[i];
   if(Array.IndexOf(symbol.GetIndexesFromList(), "S&P500") >= 0)
   {
      list.Add(symbol.Name);
   }
}



Note: In order to use the above scripts, indices must be referenced in symbols settings (Symbol -> Update or Symbol -> Manage Symbols)








no reviews (Log in)







Other how-to articles




How to screen for stocks having a high correlation with the Dow Jones index





How to get fundamental data for U.S. Stocks





How to quickly download the most recent EOD data for your stocks





How to display the number of stocks per day for different RSI groups





How to download earnings calendar data for various stocks





How to calculate the average of a time series using the money management tool





How to quickly select stocks based on the last value of a database field





How to download historical EOD data for penny stocks





How to display the bar index of a stock on a chart







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.