• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Simple Symbol Mapping Label

john5788

New member
Hello,

I'm trying to write a simple study that adds a label that decodes/maps symbols to names and I'm having trouble with the syntax/rules of thinkscript.

Code:
def currentSymbol = GetSymbol();
def label;

switch (currentSymbol)
{
    case "XLK":
        label = "Technology";
}

addLabel(1, label, color.Light_Gray);

I just need a nudge in the right direction on why I'm getting the following errors:

Code:
currentSymbol is not a valid enum input -  at 4:9
Expected double at 1:5
Incompatible parameter: "Technology" at 7:9
Expected double at 7:9

I need this because I have a 4x3 grid of all ETFs I'm interested in watching and they become so small the names don't show up. To get around that, I want to simply paint a label onto the chart.
 

Pensar

Well-known member
VIP
@john5788 Part of the error code you are getting is due to not having a proper switch input, and I also dont think GetSymbol() can be used as a input selection. But why not do something simpler like a basic label?

Code:
AddLabel(1, if GetSymbol() == "XLY" then "Cyclicals"
         else if GetSymbol() == "XLK" then "Technology"
         else if GetSymbol() == "XLI" then "Industrials"
         else if GetSymbol() == "XLB" then "Materials"
         else if GetSymbol() == "XLE" then "Energy"
         else if GetSymbol() == "XLP" then "Staples"
         else if GetSymbol() == "XLV" then "Health Care"
         else if GetSymbol() == "XLU" then "Utilities"
         else if GetSymbol() == "XLF" then "Financials"
         else if GetSymbol() == "XTL" then "Communications"
         else if GetSymbol() == "XLRE" then "Real Estate"
         else "Not A Sector ETF", Color.WHITE);
 

Pensar

Well-known member
VIP
Last edited:

Similar threads

Top