Reference Other Symbols Based On Current Symbol

bri8htf1y

New member
Hi all, this one seems simple but its eluding me. My system requires frequent comparisons between the same pairs of symbols.

For the sake of this question, a simple example:

input Other = "/NQ";
plot data = close;
plot dataOther = close(Other);

This works to plot both symbols, the current and the input.

But it would be much faster if it were automatic. Since the "Other" symbol is always the same based on the current symbol in my system, it seems that a variable could be defined so that, ie:

def Other = if getSymbol() == "AAPL" then "/NQ" else double.nan;
plot data = close;
plot dataOther = close(Other);

This way whenever I select one symbol, another symbol is automatically the referenced.
Is this a syntax issue or is this just not possible? Thanks in advance!
 
Solution
Hi all, this one seems simple but its eluding me. My system requires frequent comparisons between the same pairs of symbols.

For the sake of this question, a simple example:

input Other = "/NQ";
plot data = close;
plot dataOther = close(Other);

This works to plot both symbols, the current and the input.

But it would be much faster if it were automatic. Since the "Other" symbol is always the same based on the current symbol in my system, it seems that a variable could be defined so that, ie:

def Other = if getSymbol() == "AAPL" then "/NQ" else double.nan;
plot data = close;
plot dataOther = close(Other);

This way whenever I select one symbol, another symbol is automatically the referenced.
Is this a syntax issue or is this...
Hi all, this one seems simple but its eluding me. My system requires frequent comparisons between the same pairs of symbols.

For the sake of this question, a simple example:

input Other = "/NQ";
plot data = close;
plot dataOther = close(Other);

This works to plot both symbols, the current and the input.

But it would be much faster if it were automatic. Since the "Other" symbol is always the same based on the current symbol in my system, it seems that a variable could be defined so that, ie:

def Other = if getSymbol() == "AAPL" then "/NQ" else double.nan;
plot data = close;
plot dataOther = close(Other);

This way whenever I select one symbol, another symbol is automatically the referenced.
Is this a syntax issue or is this just not possible? Thanks in advance!

This seems to work syntax wise and covers the situation where there is missing data in dataother to match that of data's data, especially during afterhours.

Capture.jpg
Capture.jpg
Ruby:
input Othersym = " ";
plot data      = close;
def NQ         = if IsNaN(close("/NQ")) then NQ[1] else close("/NQ");
def Other      = if IsNaN(close(Othersym)) then Other[1] else close(Othersym);
plot dataOther = if GetSymbol() == "AAPL" then NQ else Other;


#Test
input test   = yes;
AddLabel(test, GetSymbol() + " " + data + 
              " || " +
              (if GetSymbol() == "AAPL"
               then " /NQ " + dataOther
               else if Other == 0
               then " No Other Symbol Input "
               else " " + Othersym + " " + dataOther),
               Color.YELLOW);
 

Attachments

  • Capture.jpg
    Capture.jpg
    16.7 KB · Views: 432
Solution
Hi all, this one seems simple but its eluding me. My system requires frequent comparisons between the same pairs of symbols.

For the sake of this question, a simple example:

input Other = "/NQ";
plot data = close;
plot dataOther = close(Other);

This works to plot both symbols, the current and the input.

But it would be much faster if it were automatic. Since the "Other" symbol is always the same based on the current symbol in my system, it seems that a variable could be defined so that, ie:

def Other = if getSymbol() == "AAPL" then "/NQ" else double.nan;
plot data = close;
plot dataOther = close(Other);

This way whenever I select one symbol, another symbol is automatically the referenced.
Is this a syntax issue or is this just not possible? Thanks in advance!

i took your question to mean, you have several pairs of stocks in mind. when the primary one is displayed on the chart, then look up the secondary stock price.
i made up 4 pairs of stocks.

Code:
def sec_stk;
if GetSymbol() == "AAPL" then {
sec_stk = close("/NQ");
} else if GetSymbol() == "KO" then {
sec_stk = close("V");
} else if GetSymbol() == "WMT" then {
sec_stk = close("F");

# copy these 2 lines to add more pairs
} else if GetSymbol() == "GOOG" then {
sec_stk = close("T");

} else {
sec_stk = 0;
}
#
plot z = sec_stk;
#

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetSymbol
 
This seems to work syntax wise and covers the situation where there is missing data in dataother to match that of data's data, especially during afterhours.
Yep that works.

Looks like other symbols can only be referenced generally as inputs. I see I just need to start coding individual data point sets for each specific reference symbol, then assign them as default partners for regular current selections.

Thank you, much appreciated.

(First post btw, been lurking for a long time and I have to say this community is the best. Happy Trading!)
 
i took your question to mean, you have several pairs of stocks in mind. when the primary one is displayed on the chart, then look up the secondary stock price.
i made up 4 pairs of stocks.

Code:
def sec_stk;
if GetSymbol() == "AAPL" then {
sec_stk = close("/NQ");
} else if GetSymbol() == "KO" then {
sec_stk = close("V");
} else if GetSymbol() == "WMT" then {
sec_stk = close("F");

# copy these 2 lines to add more pairs
} else if GetSymbol() == "GOOG" then {
sec_stk = close("T");

} else {
sec_stk = 0;
}
#
plot z = sec_stk;
#

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetSymbol
Basically yes, but I usually have many data points other than "close", so I've been using the input otherSymbol = "XYZ" to assign a general variable to it that can be used in all the expressions in the script. But since I regularly use the same "pairs", I thought I could skip the input step in setting each time I switched by using def otherSymbol = if GetSymbol() = "ABC" then "XYZ" else double.NaN. Seems thats not possible, so above def works, can just expand to include other data.

Thank you sir!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
355 Online
Create Post

Similar threads

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.
Back
Top