• Get $40 off VIP by signing up for a free account! Sign Up

Chart Labels (i.e. SPY, VIX etc) For ThinkOrSwim

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

Howdy and good evening,

I am including some script that I put together/modified to allow the users to select which colors they want to show when market indices are positive/negative/neutral. The problem I can't figure out is that when they select a color, it doesn't show up on the chart label background color on the chart. It appears to select the color 5 colors down from wherever it's initially selected.

If someone could, look into the script to see what I am missing. Whatever the color the trader select, that color needs to be applied to the chart label when the condition is met.

Here is the code:
input Label_Neutral_Color = {"magenta", "dark_red", "dark_green", "red", "white", "plum", "dark_orange", "green", "pink", "orange", default "yellow", "cyan", "blue", "gray", "violet"};

input Label_Positive_Color = {"magenta", "dark_red", "dark_green", "yellow", "white", "plum", "dark_orange", "red", "pink", "orange", default "green", "cyan", "blue", "gray", "violet"};

input Label_Negative_Color = {"magenta", "dark_red", "dark_green", "yellow", "white", "plum", "dark_orange", "green", "pink", "orange", default "red", "cyan", "blue", "gray", "violet"};


def Post = SecondsFromTime(1600);
def Pre = SecondsTillTime(930);
def Closed = Post >= 0 or Pre >= 0;
def DayClose = If (Post >= 0, close(period = "Day"), close(period = "Day")[1]);



#*************************************************
# Vix Aggregate Period and Last Price *
#*************************************************
def VxxLowPeriod = low(symbol = "VIX", period = AggregationPeriod.DAY);
def VxxHighPeriod = high(symbol = "VIX", period = AggregationPeriod.DAY);
def VxxClosePeriod = close(symbol = "VIX", period = AggregationPeriod.DAY);

#Dow Open Close & Last Price
def Vxx_ClosePrice = close(symbol = "VIX", period = AggregationPeriod.DAY)[1];


def Vxx_Close = close (symbol = "VIX", period = AggregationPeriod.DAY);
def Vxx_change = ( Vxx_Close / Vxx_ClosePrice - 1);
def Vxx_value_change = Vxx_Close - Vxx_ClosePrice ;
def Vxx_percent_change = Vxx_change * 100 ;
## End of VXX Section


#VXX
def VxxhiDiff = VxxHighPeriod - VxxHighPeriod[1];
def VxxloDiff = VxxLowPeriod[1] - VxxLowPeriod;


def VxxplusDM = if VxxhiDiff > VxxloDiff and VxxhiDiff > 0 then VxxhiDiff else 0;
def VxxminusDM = if VxxloDiff > VxxhiDiff and VxxloDiff > 0 then VxxloDiff else 0;


#Define VIx ATR
#*********************************
def VxxATR = MovingAverage(AverageType.WILDERS, TrueRange(VxxHighPeriod, VxxClosePeriod, VxxLowPeriod), 14);

#Plotting & Hiding
plot VxxDMP = 100 * MovingAverage(AverageType.WILDERS, VxxplusDM, 14) / VxxATR;
VxxDMP.Hide();

plot VxxDMM = 100 * MovingAverage(AverageType.WILDERS, VxxminusDM, 14) / VxxATR;
VxxDMM.Hide();

AddLabel(yes, "VIX: " + AsText(Vxx_Close) + " ( " + AsText(Vxx_value_change) + " / " + Round(Vxx_percent_change, 2) + "%) ", (if Vxx_value_change > 0 then GetColor( Label_Positive_Color) else if Vxx_value_change == 0 then GetColor( Label_Neutral_Color) else GetColor( Label_Negative_Color)));

Here are the shared items:

Dow Jones: http://tos.mx/u3PgaNm

NASDAQ: http://tos.mx/oaTMhXK

SPY: http://tos.mx/u4ezLnW

SPX: http://tos.mx/RptikL3

VIX: http://tos.mx/hhCyjfz

Russell: http://tos.mx/paSduwX

thanks in advance.
question what are the percentages to the left of the vix price in parenthesis telling me
 
Try this Modified it to add color automatically...
def Post = SecondsFromTime(1600);
def Pre = SecondsTillTime(930);
def Closed = Post >= 0 or Pre >= 0;
def DayClose = If (Post >= 0, close(period = "Day"), close(period = "Day")[1]);



#*************************************************
# Vix Aggregate Period and Last Price *
#*************************************************
def VxxLowPeriod = low(symbol = "VIX", period = AggregationPeriod.DAY);
def VxxHighPeriod = high(symbol = "VIX", period = AggregationPeriod.DAY);
def VxxClosePeriod = close(symbol = "VIX", period = AggregationPeriod.DAY);

#Dow Open Close & Last Price
def Vxx_ClosePrice = close(symbol = "VIX", period = AggregationPeriod.DAY)[1];


def Vxx_Close = close (symbol = "VIX", period = AggregationPeriod.DAY);
def Vxx_change = ( Vxx_Close / Vxx_ClosePrice - 1);
def Vxx_value_change = Vxx_Close - Vxx_ClosePrice ;
def Vxx_percent_change = Vxx_change * 100 ;
## End of VXX Section


#VXX
def VxxhiDiff = VxxHighPeriod - VxxHighPeriod[1];
def VxxloDiff = VxxLowPeriod[1] - VxxLowPeriod;


def VxxplusDM = if VxxhiDiff > VxxloDiff and VxxhiDiff > 0 then VxxhiDiff else 0;
def VxxminusDM = if VxxloDiff > VxxhiDiff and VxxloDiff > 0 then VxxloDiff else 0;


#Define SpX/VIx ATR
#*********************************


def VxxATR = MovingAverage(AverageType.WILDERS, TrueRange(VxxHighPeriod, VxxClosePeriod, VxxLowPeriod), 14);



#Plotting & Hiding


plot VxxDMP = 100 * MovingAverage(AverageType.WILDERS, VxxplusDM, 14) / VxxATR;
VxxDMP.Hide();

plot VxxDMM = 100 * MovingAverage(AverageType.WILDERS, VxxminusDM, 14) / VxxATR;
VxxDMM.Hide();

AddLabel(yes, "VIX: " + AsText(Vxx_Close) + " ( " + AsText(Vxx_value_change) + " / " + Round(Vxx_percent_change, 2) + "%) ", (if Vxx_value_change > 0 then Color.GREEN else if Vxx_value_change == 0 then color.yellow else color.dark_red));
 
Index Label
https://usethinkscript.com/threads/trending-chart-setup-for-thinkorswim.10833/
Ruby:
# scripted by ZupDog

input symbol = "$DJI" ;
def C_now = close("$DJI");
def c = close(symbol, period = AggregationPeriod.day)[1];
def Change = (C_now/c - 1);
Def value_change = C_now - c;
AddLabel(1, Symbol +" = " + value_change, if value_change > 0 then color.DARK_GREEN else color.DARK_RED);

Ruby:
# Scripted by ZupDog

input symbol = "$TRIN" ;

def C_now = close("$TRIN");
def c = close(symbol, period = AggregationPeriod.day)[1];
def Change = (C_now/c - 1);Def value_change = C_now - c;

#AddLabel(1, Symbol +" = " + value_change, if value_change > 0 then color.GREEN else color.PINK);
def Price = close("$TRIN");

#AddLabel( Price, "Curr. Price: " + Price , Color.PINK);
AddLabel( 1, Symbol +" = " + price, if price < 0.80 then color.PLUM else if price > 1.00 then color.CYAN else color.GRAY );

Ruby:
# TRIX
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Converted to Label Study by ZupDog

input Label = yes;
input length = 9;
input colorNormLength = 14;
input price = close;
input signalLength = 3;

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), length), length), length);

def TRIX = (tr - tr[1]) * 10000;
def Signal = ExpAverage(TRIX, signalLength);
def ZeroLine = 0;

rec countup = if TRIX > 0 then countup[1] + 1 else 0;
rec countdn = if TRIX < 0 then countdn[1] - 1 else 0;

#AddLabel(label, Concat("TRIX ", if TRIX > Signal  then  countup else countdn), if TRIX > Signal then Color.GREEN else if TRIX < Signal then Color.PLUM else Color.WHITE );

AddLabel(label, Concat("TRIX ", if TRIX > 0  then  countup else countdn), if TRIX > 0 then Color.GREEN else if TRIX < 0 then Color.PLUM else Color.WHITE );

TRIX
Ruby:
# TRIX
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Verticals added by ZupDog
# Label added by ZupDog

declare lower;

input showverticals = No;
input Label = No;
input length = 9;
input colorNormLength = 14;
input price = close;
input signalLength = 3;

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), length), length), length);

plot TRIX = (tr - tr[1]) * 10000;
plot Signal = ExpAverage(TRIX, signalLength);
plot ZeroLine = 0;

TRIX.DefineColor("Highest", Color.YELLOW);
TRIX.DefineColor("Lowest", Color.LIGHT_RED);
TRIX.AssignNormGradientColor(colorNormLength, TRIX.color("Lowest"), TRIX.color("Highest"));

Signal.setDefaultColor(GetColor(3));
ZeroLine.SetDefaultColor(GetColor(5));

AddVerticalLine(showverticals and crosses (TRIX, 0, CrossingDirection.ABOVE), " TRIX_Cross Above", Color.GREEN, 3);
AddVerticalLine(showverticals and crosses (TRIX, 0, CrossingDirection.BELOW), "TRIX_Cross Below",  Color.MAGENTA, 3);


rec countup = if TRIX > 0 then countup[1] + 1 else 0;
rec countdn = if TRIX < 0 then countdn[1] - 1 else 0;

#AddLabel(label, Concat("TRIX ", if TRIX > Signal  then  countup else countdn), if TRIX > Signal then Color.GREEN else if TRIX < Signal then Color.PLUM else Color.WHITE );

AddLabel(label, Concat("TRIX ", if TRIX > 0  then  countup else countdn), if TRIX > 0 then Color.GREEN else if TRIX < 0 then Color.PLUM else Color.WHITE );
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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