Get the Index of the Stock with AddChart?

JabronLames

Member
VIP
Hi Guys,

The example code below overlays the chart of Security over the current chart. Currently Security is a list of pre-defined tickers that you can choose in the study settings.

That's fine and dandy, but with how volatile the market can be it would be nice to have the stock's corresponding index load along with the chart...it would sure help me know if I need to press the get out button because Poppa Powell said something Mr. Market didn't like...

Question:
I was wondering if there was a way to dynamically set the value of Security based on the chart that is currently loaded. Does TOS use the current ticker as a class.asItDoes with Color.example or ChartType.Example?

*Is there a way to do this? Or is this a dead-end?

Code:
declare lower;

input chartType = ChartType.CANDLE;

input Security  =  {default "SPX", "COMP", "DJX"};

AddChart( high  = high( Security ),
  low   = low( Security ),
  open  = open( Security ),
  close = close( Security ),
  type  = chartType );


AddLabel(1, if Security == Security."SPX" then "SPX = S&P 500 INDEX"

else if Security == Security."COMP" then " COMP =  NASDAQ COMPOSITE"

else if Security == Security."DJX" then " DJX =  DOW JONES INDUSTRIAL AVERAGE INDEX"

else  "ERROR – none were found", Color.WHITE);
 
I could not find any posts using TS to display candlestick charts of a group of stocks. Any comments will be appreciated.

I have 3 possible applications in mind. Basically it can be used to watch the actions of:

1). a group of leading stocks which may provide clues about market health
2). a small group of similar (same industry/etc.) stocks
3). all of my holding stocks

I've used addchart to create an equal-weighted composite index before and the result did not seem to be satisfactory. The issue may be related to how to determine the daily high and low prices of the index. Individual stocks will not act in sync. One stock may be at a daily high while others may be at daily low. So I've not figured out an easy way to calculate the daily high and low on my daily chart.

Any thought?
Thanks
 

XeoNoX

Well-known member
VIP
@JabronLames it would be possible by MANUALLY adding every symbol to the script and then defining which one goes to what index. If you have the time you soul sit there and add the 3000+ more popular symbols.

The code would be along the lines of if AMZN or APPL or NFLX or BLAH then SPX else if BL BLA BLAH then DJX.

That would be a lot of code. good luck.
 

justaguy

New member
Hi Guys,

The example code below overlays the chart of Security over the current chart. Currently Security is a list of pre-defined tickers that you can choose in the study settings.

That's fine and dandy, but with how volatile the market can be it would be nice to have the stock's corresponding index load along with the chart...it would sure help me know if I need to press the get out button because Poppa Powell said something Mr. Market didn't like...

Question:
I was wondering if there was a way to dynamically set the value of Security based on the chart that is currently loaded. Does TOS use the current ticker as a class.asItDoes with Color.example or ChartType.Example?

*Is there a way to do this? Or is this a dead-end?

Code:
declare lower;

input chartType = ChartType.CANDLE;

input Security  =  {default "SPX", "COMP", "DJX"};

AddChart( high  = high( Security ),
  low   = low( Security ),
  open  = open( Security ),
  close = close( Security ),
  type  = chartType );


AddLabel(1, if Security == Security."SPX" then "SPX = S&P 500 INDEX"

else if Security == Security."COMP" then " COMP =  NASDAQ COMPOSITE"

else if Security == Security."DJX" then " DJX =  DOW JONES INDUSTRIAL AVERAGE INDEX"

else  "ERROR – none were found", Color.WHITE);
Couldn't you just pull the array of stocks from yahoo's api's and pull the listed stocks to assign it as it's own class of values? VWAP would be interesting. Host it on an api server so its updated faster and you could add non tos code to simplify some of your goals. I might just finish this little project, if I find the time.
 
Last edited:

justaguy

New member
@JabronLames it would be possible by MANUALLY adding every symbol to the script and then defining which one goes to what index. If you have the time you soul sit there and add the 3000+ more popular symbols.

The code would be along the lines of if AMZN or APPL or NFLX or BLAH then SPX else if BL BLA BLAH then DJX.

That would be a lot of code. good luck.
value array?
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top