Chart Labels (i.e. SPY, VIX etc) Coding

DoQtorNo

Member
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.
 
Last edited:

andre.muhammad

Member
VIP
@DoQtorNo Thank you for these labels, but the color of these labels is hard for me to read as a magenta color. Is it possible that these labels could be red when they down and green when they are up on the day? Thanks in advance for anyone who can help with this.
 

Similar threads

Top