Set Global Color/Style for all Plots

jondstone

New member
Good evening, long time user of the ToS platform but relatively new to writing ThinkScripts.

Question 1:
I am writing a script that will plot multiple lines (lets say 12+), but I would like to globally set the color and style for all lines, instead of per "plot" (see sample code below). I have searched and I cannot find a way to do this in ThinkScript. Is this possible?

# Instead of setting color and style for each plot, globally declare for all plots in script here

plot line1 = 410;
line1.SetDefaultColor(color.PINK);
line1.SetStyle(3);

plot line2 = 415;
line2.SetDefaultColor(color.PINK);
line2.SetStyle(3);

Question 2:
Essentially I am wanting to create "price levels" via ThinkScript instead of right clicking the chart and adding them. You know how you can add a label text to be displayed to the right or left of the price level? How can I do this in ThinkScript? I'd like to add a text label for each line I plot that sits just on top of the plotted line.

Thanks!
 
Solution
Hello halcyonguy,

I guess my questions where not clear. I was looking to declare color, style, etc, once and not reference it again. Think CSS. If I declare the font color in the style, I don't have to "set it" again in the HTML body.
---------
DefineGlobalColor("GlobalColor", CreateColor(255, 192, 203));

plot Line01 = if GetSymbol() == "SPY" then 440 else double.nan;
Line01.SetDefaultColor(GlobalColor("GlobalColor"));
Line01.SetStyle(3);
----------
I want to clean up my code, having a "SetDefaultColor" and "SetStyle" for every line, especially when I have dozens is not clean code. After spending time with ToS support, I guess this is not possible.

Second, I don't want labels or bubbles. I want to mimic the "Price Level"...
Good evening, long time user of the ToS platform but relatively new to writing ThinkScripts.

Question 1:
I am writing a script that will plot multiple lines (lets say 12+), but I would like to globally set the color and style for all lines, instead of per "plot" (see sample code below). I have searched and I cannot find a way to do this in ThinkScript. Is this possible?

# Instead of setting color and style for each plot, globally declare for all plots in script here

plot line1 = 410;
line1.SetDefaultColor(color.PINK);
line1.SetStyle(3);

plot line2 = 415;
line2.SetDefaultColor(color.PINK);
line2.SetStyle(3);

Question 2:
Essentially I am wanting to create "price levels" via ThinkScript instead of right clicking the chart and adding them. You know how you can add a label text to be displayed to the right or left of the price level? How can I do this in ThinkScript? I'd like to add a text label for each line I plot that sits just on top of the plotted line.

Thanks!

a general answer on searching, that ends up with
DefineGlobalColor

when i want to search for a thinkscript function on my cell, i use the same words in google, so they show up at top of the google suggested search words.
( so i don't have to type them every time)

thinkscript color

search...
click on top link
go to a tos site for thinkscript
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color

click on 3 lines at top of page,
and search for color (or whatever)

tap on this
DefineGlobalColor
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/DefineGlobalColor

=======

searching this site for horizontal lines

https://usethinkscript.com/search/1066785/?q=horizontal+lines&o=date

many variations on this thread
https://usethinkscript.com/threads/horizontal-lines-in-thinkorswim.3472/#post-32134

-------

a thread with posts on bubble placement
https://usethinkscript.com/threads/display-bubble-on-the-right-edge.3037/#post-28031
 
Hello halcyonguy,

I guess my questions where not clear. I was looking to declare color, style, etc, once and not reference it again. Think CSS. If I declare the font color in the style, I don't have to "set it" again in the HTML body.
---------
DefineGlobalColor("GlobalColor", CreateColor(255, 192, 203));

plot Line01 = if GetSymbol() == "SPY" then 440 else double.nan;
Line01.SetDefaultColor(GlobalColor("GlobalColor"));
Line01.SetStyle(3);
----------
I want to clean up my code, having a "SetDefaultColor" and "SetStyle" for every line, especially when I have dozens is not clean code. After spending time with ToS support, I guess this is not possible.

Second, I don't want labels or bubbles. I want to mimic the "Price Level" drawing "bubble". You know when you add a price level to the chart, right click > properties > type in a name > select "on the left" or "on the right" it displays text above the price level?

Apparently that also can't be done with thinkscript.

 
Hello halcyonguy,

I guess my questions where not clear. I was looking to declare color, style, etc, once and not reference it again. Think CSS. If I declare the font color in the style, I don't have to "set it" again in the HTML body.
---------
DefineGlobalColor("GlobalColor", CreateColor(255, 192, 203));

plot Line01 = if GetSymbol() == "SPY" then 440 else double.nan;
Line01.SetDefaultColor(GlobalColor("GlobalColor"));
Line01.SetStyle(3);
----------
I want to clean up my code, having a "SetDefaultColor" and "SetStyle" for every line, especially when I have dozens is not clean code. After spending time with ToS support, I guess this is not possible.

Second, I don't want labels or bubbles. I want to mimic the "Price Level" drawing "bubble". You know when you add a price level to the chart, right click > properties > type in a name > select "on the left" or "on the right" it displays text above the price level?

Apparently that also can't be done with thinkscript.

The ToS platform does not provide the ability to set global defaults.
 
Solution

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