an example study, to show 10 shades of a selected color

halcyonguy

Moderator - Expert
VIP
Lifetime
an example study,
...to show 10 shades of a selected color and
...how to pick a color from a list of quoted text.

input color1 = {default "Green", "Lime", "Red", "Pink", "Orange", "Yellow", "Cyan", "Blue", "Light_Purple", "Purple", "Magenta" };

there are 2 ways to use a variable like color1.

check the value of it,
... if color1 == color1."Green" then ...


or check the sequence number of the chosen item, from the list,
... if color1 == 2 then ...

when the variable is compared to a constant, the value is treated like a number, that is the sequence number of the selected data. the sequence starts counting at 0. so pick the 4th color, and the equivelent number is 3.
i set a new variable,
def c = color1 * 1;
although it may not be necessary


------------------------

pick a color (1 of 11)
plot 10 lines, of different shades of that color

uses DefineGlobalColor()


Code:
# global_colors_ex1

# pick a color (1 of 11)
# plot 10 lines, of different shades of that color
# ref- came from this post
# https://usethinkscript.com/threads/new-high-low-breakout-for-thinkorswim.15142/

# 0
DefineGlobalColor("G0", CreateColor(0, 255, 0));  #Green
DefineGlobalColor("G1", CreateColor(0, 229, 0));  #Green
DefineGlobalColor("G2", CreateColor(0, 206, 0));  #Green
DefineGlobalColor("G3", CreateColor(0, 186, 0));  #Green
DefineGlobalColor("G4", CreateColor(0, 167, 0));  #Green
DefineGlobalColor("G5", CreateColor(0, 151, 0));  #Green
DefineGlobalColor("G6", CreateColor(0, 136, 0));  #Green
DefineGlobalColor("G7", CreateColor(0, 122, 0));  #Green
DefineGlobalColor("G8", CreateColor(0, 109, 0));  #Green
DefineGlobalColor("G9", CreateColor(0,  98, 0));  #Green

#1
DefineGlobalColor("L0", CreateColor(128, 255, 0));  #Lime
DefineGlobalColor("L1", CreateColor(113, 224, 0));  #Lime
DefineGlobalColor("L2", CreateColor( 99, 197, 0));  #Lime
DefineGlobalColor("L3", CreateColor( 87, 174, 0));  #Lime
DefineGlobalColor("L4", CreateColor( 77, 153, 0));  #Lime
DefineGlobalColor("L5", CreateColor( 66, 135, 0));  #Lime
DefineGlobalColor("L6", CreateColor( 59, 118, 0));  #Lime
DefineGlobalColor("L7", CreateColor( 52, 104, 0));  #Lime
DefineGlobalColor("L8", CreateColor( 46,  92, 0));  #Lime
DefineGlobalColor("L9", CreateColor( 41,  81, 0));  #Lime

#2
DefineGlobalColor("R0", CreateColor(255, 0, 0));  #Red
DefineGlobalColor("R1", CreateColor(224, 0, 0));  #Red
DefineGlobalColor("R2", CreateColor(197, 0, 0));  #Red
DefineGlobalColor("R3", CreateColor(174, 0, 0));  #Red
DefineGlobalColor("R4", CreateColor(153, 0, 0));  #Red
DefineGlobalColor("R5", CreateColor(135, 0, 0));  #Red
DefineGlobalColor("R6", CreateColor(118, 0, 0));  #Red
DefineGlobalColor("R7", CreateColor(104, 0, 0));  #Red
DefineGlobalColor("R8", CreateColor( 92, 0, 0));  #Red
DefineGlobalColor("R9", CreateColor( 81, 0, 0));  #Red

#3
DefineGlobalColor("Pi0", CreateColor(255, 96, 128));  #Pink
DefineGlobalColor("Pi1", CreateColor(224, 84, 113));  #Pink
DefineGlobalColor("Pi2", CreateColor(197, 74,  99));  #Pink
DefineGlobalColor("Pi3", CreateColor(174, 65,  87));  #Pink
DefineGlobalColor("Pi4", CreateColor(153, 58,  77));  #Pink
DefineGlobalColor("Pi5", CreateColor(135, 51,  68));  #Pink
DefineGlobalColor("Pi6", CreateColor(118, 45,  59));  #Pink
DefineGlobalColor("Pi7", CreateColor(104, 39,  52));  #Pink
DefineGlobalColor("Pi8", CreateColor( 92, 35,  46));  #Pink
DefineGlobalColor("Pi9", CreateColor( 81, 30,  41));  #Pink

#4
DefineGlobalColor("O0", CreateColor(255, 128, 0));  #Orange
DefineGlobalColor("O1", CreateColor(237, 106, 0));  #Orange
DefineGlobalColor("O2", CreateColor(221,  88, 0));  #Orange
DefineGlobalColor("O3", CreateColor(205,  73, 0));  #Orange
DefineGlobalColor("O4", CreateColor(191,  61, 0));  #Orange
DefineGlobalColor("O5", CreateColor(177,  50, 0));  #Orange
DefineGlobalColor("O6", CreateColor(165,  42, 0));  #Orange
DefineGlobalColor("O7", CreateColor(153,  33, 0));  #Orange
DefineGlobalColor("O8", CreateColor(143,  29, 0));  #Orange
DefineGlobalColor("O9", CreateColor(133,  24, 0));  #Orange

#5
DefineGlobalColor("Y0", CreateColor(255, 255, 0));  #Yellow
DefineGlobalColor("Y1", CreateColor(234, 234, 0));  #Yellow
DefineGlobalColor("Y2", CreateColor(216, 216, 0));  #Yellow
DefineGlobalColor("Y3", CreateColor(198, 198, 0));  #Yellow
DefineGlobalColor("Y4", CreateColor(182, 182, 0));  #Yellow
DefineGlobalColor("Y5", CreateColor(168, 168, 0));  #Yellow
DefineGlobalColor("Y6", CreateColor(155, 155, 0));  #Yellow
DefineGlobalColor("Y7", CreateColor(142, 142, 0));  #Yellow
DefineGlobalColor("Y8", CreateColor(131, 131, 0));  #Yellow
DefineGlobalColor("Y9", CreateColor(120, 120, 0));  #Yellow

#6
DefineGlobalColor("C0", CreateColor(0, 255, 255));  #Cyan
DefineGlobalColor("C1", CreateColor(0, 219, 219));  #Cyan
DefineGlobalColor("C2", CreateColor(0, 188, 189));  #Cyan
DefineGlobalColor("C3", CreateColor(0, 161, 162));  #Cyan
DefineGlobalColor("C4", CreateColor(0, 137, 139));  #Cyan
DefineGlobalColor("C5", CreateColor(0, 117, 119));  #Cyan
DefineGlobalColor("C6", CreateColor(0, 100, 103));  #Cyan
DefineGlobalColor("C7", CreateColor(0,  86,  89));  #Cyan
DefineGlobalColor("C8", CreateColor(0,  72,  76));  #Cyan
DefineGlobalColor("C9", CreateColor(0,  62,  66));  #Cyan

#7
DefineGlobalColor("B0", CreateColor(0, 128, 255));  #Blue
DefineGlobalColor("B1", CreateColor(0, 117, 234));  #Blue
DefineGlobalColor("B2", CreateColor(0, 108, 216));  #Blue
DefineGlobalColor("B3", CreateColor(0,  99, 198));  #Blue
DefineGlobalColor("B4", CreateColor(0,  91, 182));  #Blue
DefineGlobalColor("B5", CreateColor(0,  84, 168));  #Blue
DefineGlobalColor("B6", CreateColor(0,  78, 155));  #Blue
DefineGlobalColor("B7", CreateColor(0,  71, 142));  #Blue
DefineGlobalColor("B8", CreateColor(0,  66, 131));  #Blue
DefineGlobalColor("B9", CreateColor(0,  60, 120));  #Blue

#8
DefineGlobalColor("LP0", CreateColor(170, 149, 255));  #Light Purple
DefineGlobalColor("LP1", CreateColor(156, 137, 234));  #Light Purple
DefineGlobalColor("LP2", CreateColor(144, 126, 216));  #Light Purple
DefineGlobalColor("LP3", CreateColor(132, 116, 198));  #Light Purple
DefineGlobalColor("LP4", CreateColor(122, 107, 182));  #Light Purple
DefineGlobalColor("LP5", CreateColor(112,  98, 168));  #Light Purple
DefineGlobalColor("LP6", CreateColor(103,  90, 155));  #Light Purple
DefineGlobalColor("LP7", CreateColor( 95,  83, 142));  #Light Purple
DefineGlobalColor("LP8", CreateColor( 87,  76, 131));  #Light Purple
DefineGlobalColor("LP9", CreateColor( 80,  70, 120));  #Light Purple

#9
DefineGlobalColor("P0", CreateColor(128, 0, 255));  #Purple
DefineGlobalColor("P1", CreateColor(117, 0, 234));  #Purple
DefineGlobalColor("P2", CreateColor(108, 0, 216));  #Purple
DefineGlobalColor("P3", CreateColor( 99, 0, 198));  #Purple
DefineGlobalColor("P4", CreateColor( 91, 0, 182));  #Purple
DefineGlobalColor("P5", CreateColor( 84, 0, 168));  #Purple
DefineGlobalColor("P6", CreateColor( 78, 0, 155));  #Purple
DefineGlobalColor("P7", CreateColor( 71, 0, 142));  #Purple
DefineGlobalColor("P8", CreateColor( 66, 0, 131));  #Purple
DefineGlobalColor("P9", CreateColor( 60, 0, 120));  #Purple

#10
DefineGlobalColor("M0", CreateColor(255, 0, 255));  #Magenta
DefineGlobalColor("M1", CreateColor(224, 0, 224));  #Magenta
DefineGlobalColor("M2", CreateColor(197, 0, 197));  #Magenta
DefineGlobalColor("M3", CreateColor(174, 0, 174));  #Magenta
DefineGlobalColor("M4", CreateColor(153, 0, 153));  #Magenta
DefineGlobalColor("M5", CreateColor(135, 0, 135));  #Magenta
DefineGlobalColor("M6", CreateColor(118, 0, 118));  #Magenta
DefineGlobalColor("M7", CreateColor(104, 0, 104));  #Magenta
DefineGlobalColor("M8", CreateColor( 92, 0,  92));  #Magenta
DefineGlobalColor("M9", CreateColor( 81, 0,  81));  #Magenta

DefineGlobalColor("Gray", CreateColor(28, 28, 28));  #Gray
# GlobalColor("x")

declare lower;

# pick 1 of 11 colors
input color1 = {default "Green", "Lime", "Red", "Pink", "Orange", "Yellow", "Cyan", "Blue", "Light_Purple", "Purple", "Magenta" };

def c = color1 * 1;
addlabel(1, color1, color.yellow);
addlabel(1, c, color.yellow);
def linewidth = 4;

def sp = 1;
plot zZ1 = -1 * sp;
plot zZ2 = 10 * sp;
zz1.SetDefaultColor(Color.black);
zz1.hidebubble();
zz2.SetDefaultColor(Color.black);
zz2.hidebubble();


plot z0 = 0 * sp;
z0.AssignValueColor( 
     if c == 0 then GlobalColor("G0")
else if c == 1 then GlobalColor("L0")
else if c == 2 then GlobalColor("R0")
else if c == 3 then GlobalColor("PI0")
else if c == 4 then GlobalColor("O0")
else if c == 5 then GlobalColor("Y0")
else if c == 6 then GlobalColor("C0")
else if c == 7 then GlobalColor("B0")
else if c == 8 then GlobalColor("LP0")
else if c == 9 then GlobalColor("P0")
else if c == 10 then GlobalColor("M0")
else color.gray);
z0.setlineweight(linewidth);
z0.hidebubble();

plot z1 = 1 * sp;
z1.AssignValueColor( 
     if c == 0 then GlobalColor("G1")
else if c == 1 then GlobalColor("L1")
else if c == 2 then GlobalColor("R1")
else if c == 3 then GlobalColor("PI1")
else if c == 4 then GlobalColor("O1")
else if c == 5 then GlobalColor("Y1")
else if c == 6 then GlobalColor("C1")
else if c == 7 then GlobalColor("B1")
else if c == 8 then GlobalColor("LP1")
else if c == 9 then GlobalColor("P1")
else if c == 10 then GlobalColor("M1")
else color.gray);
z1.setlineweight(linewidth);
z1.hidebubble();

plot z2 = 2 * sp;
z2.AssignValueColor( 
     if c == 0 then GlobalColor("G2")
else if c == 1 then GlobalColor("L2")
else if c == 2 then GlobalColor("R2")
else if c == 3 then GlobalColor("PI2")
else if c == 4 then GlobalColor("O2")
else if c == 5 then GlobalColor("Y2")
else if c == 6 then GlobalColor("C2")
else if c == 7 then GlobalColor("B2")
else if c == 8 then GlobalColor("LP2")
else if c == 9 then GlobalColor("P2")
else if c == 10 then GlobalColor("M2")
else color.gray);
z2.setlineweight(linewidth);
z2.hidebubble();

plot z3 = 3 * sp;
z3.AssignValueColor( 
     if c == 0 then GlobalColor("G3")
else if c == 1 then GlobalColor("L3")
else if c == 2 then GlobalColor("R3")
else if c == 3 then GlobalColor("PI3")
else if c == 4 then GlobalColor("O3")
else if c == 5 then GlobalColor("Y3")
else if c == 6 then GlobalColor("C3")
else if c == 7 then GlobalColor("B3")
else if c == 8 then GlobalColor("LP3")
else if c == 9 then GlobalColor("P3")
else if c == 10 then GlobalColor("M3")
else color.gray);
z3.setlineweight(linewidth);
z3.hidebubble();

plot z4 = 4 * sp;
z4.AssignValueColor( 
     if c == 0 then GlobalColor("G4")
else if c == 1 then GlobalColor("L4")
else if c == 2 then GlobalColor("R4")
else if c == 3 then GlobalColor("PI4")
else if c == 4 then GlobalColor("O4")
else if c == 5 then GlobalColor("Y4")
else if c == 6 then GlobalColor("C4")
else if c == 7 then GlobalColor("B4")
else if c == 8 then GlobalColor("LP4")
else if c == 9 then GlobalColor("P4")
else if c == 10 then GlobalColor("M4")
else color.gray);
z4.setlineweight(linewidth);
z4.hidebubble();

plot z5 = 5 * sp;
z5.AssignValueColor( 
     if c == 0 then GlobalColor("G5")
else if c == 1 then GlobalColor("L5")
else if c == 2 then GlobalColor("R5")
else if c == 3 then GlobalColor("PI5")
else if c == 4 then GlobalColor("O5")
else if c == 5 then GlobalColor("Y5")
else if c == 6 then GlobalColor("C5")
else if c == 7 then GlobalColor("B5")
else if c == 8 then GlobalColor("LP5")
else if c == 9 then GlobalColor("P5")
else if c == 10 then GlobalColor("M5")
else color.gray);
z5.setlineweight(linewidth);
z5.hidebubble();

plot z6 = 6 * sp;
z6.AssignValueColor( 
     if c == 0 then GlobalColor("G6")
else if c == 1 then GlobalColor("L6")
else if c == 2 then GlobalColor("R6")
else if c == 3 then GlobalColor("PI6")
else if c == 4 then GlobalColor("O6")
else if c == 5 then GlobalColor("Y6")
else if c == 6 then GlobalColor("C6")
else if c == 7 then GlobalColor("B6")
else if c == 8 then GlobalColor("LP6")
else if c == 9 then GlobalColor("P6")
else if c == 10 then GlobalColor("M6")
else color.gray);
z6.setlineweight(linewidth);
z6.hidebubble();

plot z7 = 7 * sp;
z7.AssignValueColor( 
     if c == 0 then GlobalColor("G7")
else if c == 1 then GlobalColor("L7")
else if c == 2 then GlobalColor("R7")
else if c == 3 then GlobalColor("PI7")
else if c == 4 then GlobalColor("O7")
else if c == 5 then GlobalColor("Y7")
else if c == 6 then GlobalColor("C7")
else if c == 7 then GlobalColor("B7")
else if c == 8 then GlobalColor("LP7")
else if c == 9 then GlobalColor("P7")
else if c == 10 then GlobalColor("M7")
else color.gray);
z7.setlineweight(linewidth);
z7.hidebubble();

plot z8 = 8 * sp;
z8.AssignValueColor( 
     if c == 0 then GlobalColor("G8")
else if c == 1 then GlobalColor("L8")
else if c == 2 then GlobalColor("R8")
else if c == 3 then GlobalColor("PI8")
else if c == 4 then GlobalColor("O8")
else if c == 5 then GlobalColor("Y8")
else if c == 6 then GlobalColor("C8")
else if c == 7 then GlobalColor("B8")
else if c == 8 then GlobalColor("LP8")
else if c == 9 then GlobalColor("P8")
else if c == 10 then GlobalColor("M8")
else color.gray);
z8.setlineweight(linewidth);
z8.hidebubble();

plot z9 = 9 * sp;
z9.AssignValueColor( 
     if c == 0 then GlobalColor("G9")
else if c == 1 then GlobalColor("L9")
else if c == 2 then GlobalColor("R9")
else if c == 3 then GlobalColor("PI9")
else if c == 4 then GlobalColor("O9")
else if c == 5 then GlobalColor("Y9")
else if c == 6 then GlobalColor("C9")
else if c == 7 then GlobalColor("B9")
else if c == 8 then GlobalColor("LP9")
else if c == 9 then GlobalColor("P9")
else if c == 10 then GlobalColor("M9")
else color.gray);
z9.setlineweight(linewidth);
z9.hidebubble();
#

5oXQwoH.jpg
 

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

Thread starter Similar threads Forum Replies Date
C Major issues with conditional orders using a study Playground 1

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
391 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