Plot Only For Specific Symbols

Whistler

New member
I've programmed in Tradestation EasyLanguage for 25 years, but am finding it very difficult to transfer over to ThinkScript. I'm trying to plot a line only for certain symbols. I'm sure that there are several syntax errors in my code, but I can't figure out what should work. Can anyone help?

Code:
if GetSymbol() == "/ES"
then
{   plot Line01= 4590;
    Line01.SetDefaultColor(Color.RED);
    Line01.SetLineWeight(2);
    plot Line02= 4560;
    Line02.SetDefaultColor(Color.WHITE);
    Line02.SetLineWeight(1);}
else Double.NaN;
 
Solution
Thank you. This compiles just fine and seems to work with stock symbols, but not with futures symbols. Would you happen to know why it isn't working with futures symbols?

Ruby:
plot Line01 = if  GetSymbol() == "/ES:XCME" then 4600 else double.nan;
Line01.SetDefaultColor(Color.RED);
Line01.SetLineWeight(2);

plot Line02 = if  GetSymbol() == "/ES:XCME" then 4500 else double.nan;
Line02.SetDefaultColor(Color.WHITE);
Line02.SetLineWeight(1);
I've programmed in Tradestation EasyLanguage for 25 years, but am finding it very difficult to transfer over to ThinkScript. I'm trying to plot a line only for certain symbols. I'm sure that there are several syntax errors in my code, but I can't figure out what should work. Can anyone help?

Code:
if GetSymbol() == "/ES"
then
{   plot Line01= 4590;
    Line01.SetDefaultColor(Color.RED);
    Line01.SetLineWeight(2);
    plot Line02= 4560;
    Line02.SetDefaultColor(Color.WHITE);
    Line02.SetLineWeight(1);}
else Double.NaN;
can't put plot functions within a script function or if-then.
try using an if-then formula, for the plot formula, to test for a valid value.

Code:
plot Line01= if (GetSymbol() == "/ES" then 4590 else double.nan;
    Line01.SetDefaultColor(Color.RED);
    Line01.SetLineWeight(2);

plot Line02 = if (GetSymbol() == "/ES") then 4560 else double.nan;
    Line02.SetDefaultColor(Color.WHITE);
    Line02.SetLineWeight(1);
 
Last edited:
Thank you. This compiles just fine and seems to work with stock symbols, but not with futures symbols. Would you happen to know why it isn't working with futures symbols?

Code:
plot Line01 = if (GetSymbol() == "/ES") then 4600 else double.nan;
Line01.SetDefaultColor(Color.RED);
Line01.SetLineWeight(2);

plot Line02 = if (GetSymbol() == "/ES") then 4500 else double.nan;
Line02.SetDefaultColor(Color.WHITE);
Line02.SetLineWeight(1);
 
Thank you. This compiles just fine and seems to work with stock symbols, but not with futures symbols. Would you happen to know why it isn't working with futures symbols?

Code:
plot Line01 = if (GetSymbol() == "/ES") then 4600 else double.nan;
Line01.SetDefaultColor(Color.RED);
Line01.SetLineWeight(2);

plot Line02 = if (GetSymbol() == "/ES") then 4500 else double.nan;
Line02.SetDefaultColor(Color.WHITE);
Line02.SetLineWeight(1);
sorry, no. i am not familiar with futures.
 
Last edited:
Thank you. This compiles just fine and seems to work with stock symbols, but not with futures symbols. Would you happen to know why it isn't working with futures symbols?

Ruby:
plot Line01 = if  GetSymbol() == "/ES:XCME" then 4600 else double.nan;
Line01.SetDefaultColor(Color.RED);
Line01.SetLineWeight(2);

plot Line02 = if  GetSymbol() == "/ES:XCME" then 4500 else double.nan;
Line02.SetDefaultColor(Color.WHITE);
Line02.SetLineWeight(1);
 
Solution
I'm trying to get the following label to display the info specifically for "SPY" regardless of what ticker I am currently looking at on the chart. Line #1 works by adding ("SPY") after VWAP. However, I've tried adding ("SPY") everywhere possible in line #2, but that does not work. Any suggestions?

Code:
def s =  VWAP("SPY");
def s2 = reference MACD("fast length" = 6)."Value";

def Bullish = if s is greater than s from 1 bar ago and s2 is greater than s2 from 1 bar ago then yes else no;
def Bearish = if s is less than s from 1 bar ago and s2 is less than s2 from 1 bar ago then yes else no;

def Neutral1 = if s is less than s from 1 bar ago and s2 is greater than s2 from 1 bar ago then yes else no;
def Neutral2 = if s is greater than s from 1 bar ago and s2 is less than s2 from 1 bar ago then yes else no;

AddLabel(yes,if bullish then "RISING" else  "", if bullish then color.green else color.white);
AddLabel(yes,if bearish then "FALLING" else  "", if bearish then color.light_red else color.white);
AddLabel(yes,if neutral1 then "NEUTRAL" else  "", if neutral1 then color.gray else color.white);
AddLabel(yes,if neutral2 then "NEUTRAL" else  "", if neutral2 then color.gray else color.white);
 

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