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


Active member
I think so because several people I know look at index ticks etc, such as they may be trading Apple while they watch tikSP ...

Similar threads