def symbol0 = getsymbol();

davidlymburner

New member
VIP
Hello,

When I attempt to assign the current chart's symbol to a variable called "symbol0", I get an "Expected double" error. Is there a way to assign the value of the current chart's symbol to a variable?

Thanks in advance!
 
Solution
Hello,

When I attempt to assign the current chart's symbol to a variable called "symbol0", I get an "Expected double" error. Is there a way to assign the value of the current chart's symbol to a variable?

Thanks in advance!
While @rad14733 and @Pensar are correct, you can partly get around it by using an input switch and assigning a numeric value based on the switch...
Code:
input symbol = {default "VIX", "SPY", "Current"};
def price;
switch (symbol)
{
case VIX:
     price = close("VIX");
case SPY:
     price = close("SPY");
default:
     price = close();
}
or something along those lines... I don't have an editor available at the moment.

happy trading,
mashume
@davidlymburner Regrettably, only numbers can be assigned to variables... There is no way to assign text to a variable in Thinkscript... While it may seem logical that something like def symbol = GetSymbol(); should work, it won't... Yet while GetSymbol() will return the current symbol for purposes such as displaying via AddLabel(), etc., it just can't be stored... Unfortunately, we have to live within the limitations of Thinkscript, whether we like it or not...
 
Hello,

When I attempt to assign the current chart's symbol to a variable called "symbol0", I get an "Expected double" error. Is there a way to assign the value of the current chart's symbol to a variable?

Thanks in advance!
While @rad14733 and @Pensar are correct, you can partly get around it by using an input switch and assigning a numeric value based on the switch...
Code:
input symbol = {default "VIX", "SPY", "Current"};
def price;
switch (symbol)
{
case VIX:
     price = close("VIX");
case SPY:
     price = close("SPY");
default:
     price = close();
}
or something along those lines... I don't have an editor available at the moment.

happy trading,
mashume
 
Solution
Hello.

I am looking to create a watchlist based on the parabolicsar. If the index I am looking at is /ES, I want to plot the parabolicsar of the VIX. If the index I am looking at is the /NQ, I want to plot the parabolicsar of the VXN. Is there a way to program this so that the script identifies the current symbol, and plot the PSAR of the corresponding index?

Current code posted below:


input ticker1 = "VIX";
input TimeFrame1 = AggregationPeriod.TWO_MIN;

def close = Close(Period = TimeFrame1, symbol = ticker1);

def low = Low(Period = TimeFrame1, symbol = ticker1);

def high = High(Period = TimeFrame1, symbol = ticker1);

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;

assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high)
then {
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = extreme[1];
} else {
state = state.short;
if (low < extreme[1])
then {
acc = min(acc[1] + accelerationFactor, accelerationLimit);
extreme = low;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = max(max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
}
case long:
if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = min(min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
}
}

def DotsBuy = if high > SAR then 1 else 0;
def Dot_Buy = DotsBuy;

plot buy = Dot_Buy is true;

AddLabel(yes,
if buy >= 0 then "-"
else "-" );

plot data = double.nan;

assignbackgroundColor(if buy == 1 then color.green else color.red);
 
Hello.

I am looking to create a watchlist based on the parabolicsar. If the index I am looking at is /ES, I want to plot the parabolicsar of the VIX. If the index I am looking at is the /NQ, I want to plot the parabolicsar of the VXN. Is there a way to program this so that the script identifies the current symbol, and plot the PSAR of the corresponding index?
Why would you be using a corresponding symbol in a watchlist?
Please provide an example of what your watchlist would look like.
 

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
297 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