How to change color of text in ThinkScript?

B

Buckbull

Member
How would I change the color of the text To Black what do I have to change or add ? Thank You

Code:
# creates custom watch list column that says "bullish" in green when both price > 50sma AND 50sma > 200sma
# or that says "bearish" in red when both price < 50sma AND 50sma < 200sma

# note the two risky or uncertain times are currently blank cells, both critera have been defined so that risky50over200 and risky200over50 could be used to create labels and/or color-coding for those conditions as well (via editing the AddLabel and/or the AssignBackgroundColor lines of code)

def x = SimpleMovingAvg("length" = 50);
def y = SimpleMovingAvg("length" = 200);

def risky50over200 = x > y AND close < x;
def risky200over50 = x < y AND close > x;

def bullish = close > x AND x > y;
def bearish = close < x AND x < y;

AddLabel (yes, if bearish then "bearish  " else if bullish then "bullish  " else " ");

AssignBackgroundColor (if bearish then color.RED else if bullish then color.GREEN else color.LIGHT_GRAY);
 
Last edited by a moderator:
T

tomsk

Well-known member
VIP
How would I change the color of the text To Black what do I have to change or add ? Thank You

Code:
# creates custom watch list column that says "bullish" in green when both price > 50sma AND 50sma > 200sma
# or that says "bearish" in red when both price < 50sma AND 50sma < 200sma

# note the two risky or uncertain times are currently blank cells, both critera have been defined so that risky50over200 and risky200over50 could be used to create labels and/or color-coding for those conditions as well (via editing the AddLabel and/or the AssignBackgroundColor lines of code)

def x = SimpleMovingAvg("length" = 50);
def y = SimpleMovingAvg("length" = 200);

def risky50over200 = x > y AND close < x;
def risky200over50 = x < y AND close > x;

def bullish = close > x AND x > y;
def bearish = close < x AND x < y;

AddLabel (yes, if bearish then "bearish  " else if bullish then "bullish  " else " ");

AssignBackgroundColor (if bearish then color.RED else if bullish then color.GREEN else color.LIGHT_GRAY);
@Buckbull To change the text to black, just replace your AddLabel statement with the following

AddLabel (yes, if bearish then "bearish " else if bullish then "bullish " else " ", Color.BLACK);
 
B

Buckbull

Member
@tomsk Could I trouble for one more thing ? If possible How would I add Average Daily Volume to this

Code:
#HINT: This study plots a chart label for Net Change and Percent Change from prior day's (regardless of time period of the chart). \n\n Label color is red if today's price is lower than yesterday's close.  \n\n And label color is green if today's price is higher than yesterday's close.  \n\n Label color is gray if today's price is identcal to yesterday's close.

input show_label = yes;
input show_bubble = no;


def period_Type = AggregationPeriod.DAY;

def begin = close(period = period_Type)[1];
def end = close(period = period_Type);
def NetChg = end - begin;
def PctChg = (end / begin) - 1;
def DayVolume =  volume(period = "DAY");

AddLabel(show_label, "Last: " + close + "  " + "Net Change:  " + AsDollars(NetChg) + "  " + "Percent Change: " + AsPercent(PctChg) + "  " + "Total Volume for the Day:  " + DayVolume , if NetChg > 0 then Color.GREEN else if NetChg < 0 then Color.RED else Color.LIGHT_GRAY);


def bar = if IsNaN(close)
             then if yes
                     then bar[1]
                     else Double.NaN
             else BarNumber();
def ThisBar = HighestAll(bar);
def barCount   = if bar == ThisBar
                 then close
                 else Double.NaN;

AddChartBubble(if show_bubble and bar == ThisBar then yes else no, if NetChg > 0 then high * 1.10 else low * 0.90, " Last: " + close + "  " + "\n Net Change:  " + AsDollars(NetChg) + "  " + "\n Percent Change: " + AsPercent(PctChg), if NetChg > 0 then Color.GREEN else if NetChg < 0 then Color.RED else Color.LIGHT_GRAY,  if NetChg > 0 then yes else no) ;
 
Last edited by a moderator:
T

tomsk

Well-known member
VIP
@Buckbull Sure, I have added the average daily volume over 20 days in the label. You can adjust the number of periods you wish via the input variable "periods_AvgDailyVolume" via the user interface

Code:
#HINT: This study plots a chart label for Net Change and Percent Change from prior day's (regardless of time period of the chart). \n\n Label color is red if today's price is lower than yesterday's close.  \n\n And label color is green if today's price is higher than yesterday's close.  \n\n Label color is gray if today's price is identcal to yesterday's close.

input show_label = yes;
input show_bubble = no;
input periods_AvgDailyVolume = 20;

def period_Type = AggregationPeriod.DAY;

def begin = close(period = period_Type)[1];
def end = close(period = period_Type);
def NetChg = end - begin;
def PctChg = (end / begin) - 1;
def DayVolume =  volume(period = "DAY");
def AvgDailyVolume = Average(DayVolume, periods_AvgDailyVolume);

AddLabel(show_label, "Last: " + close + "  " + "Net Change:  " + AsDollars(NetChg) + "  " + "Percent Change: " + AsPercent(PctChg) + "  " + "Total Volume for the Day:  " + DayVolume + " Average Daily Volume: " + AvgDailyVolume, if NetChg > 0 then Color.GREEN else if NetChg < 0 then Color.RED else Color.LIGHT_GRAY);

def bar = if IsNaN(close)
             then if yes
                     then bar[1]
                     else Double.NaN
             else BarNumber();
def ThisBar = HighestAll(bar);
def barCount   = if bar == ThisBar
                 then close
                 else Double.NaN;

AddChartBubble(if show_bubble and bar == ThisBar then yes else no, if NetChg > 0 then high * 1.10 else low * 0.90, " Last: " + close + "  " + "\n Net Change:  " + AsDollars(NetChg) + "  " + "\n Percent Change: " + AsPercent(PctChg), if NetChg > 0 then Color.GREEN else if NetChg < 0 then Color.RED else Color.LIGHT_GRAY,  if NetChg > 0 then yes else no) ;
 

Similar threads

Top