Get the Index of the Stock with AddChart?


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 would sure help me know if I need to press the get out button because Poppa Powell said something Mr. Market didn't like...

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?

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);


New member
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?


Well-known 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.

Similar threads