Format Watchlist Text In ThinkOrSwim

Buckbull

Active 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:
Edited: You can select Text Note from the Tools menu... Select the "T" symbol from the Drawing Set to make it your Active Tool... Right Click where you want the upper left corner of the note and select Add Drawing... Select "T" again and a popup box will appear... Type in the text you want to display and press Ok...

What I'm looking to do is this:
I have a Label on the chart that calculates the shares to buy based on the amount of money. I have.
What I'd like to do is be able to edit the amount on the label on the fly so I don't have to keep going into the study setup changing the amount in the input field there
 
What I'm looking to do is this:
I have a Label on the chart that calculates the shares to buy based on the amount of money. I have.
What I'd like to do is be able to edit the amount on the label on the fly so I don't have to keep going into the study setup changing the amount in the input field there
Ok... Well, not sure how well any of the Portfolio Thinkscript functions work in realtime... So you essentially want a study or strategy to calculate based on your currently available funds... Can't really play with that today due to how quirky TOS is working... I'll check around as I think there was a recent topic regarding Portfolio functions...
 
@machie38

What you need is the following snippet of code in your script... Note: Make sure you adhere to the limitations of Portfolio Functions... Each function may also have limitations, the main one being that Show Extended-Hours Trading must be enabled for the instrument type being displayed on your chart... There are also aggregation period limitations...

Code:
def price = close;
def MaxShares = Round(GetTotalCash() / price, 0);
AddLabel(yes, "MaxShares = " + MaxShares, Color.GRAY);
 
I can figure out more complex things but adding a chart label, my brain is hurting..:p

this works but how do I change the color of the label?

AddLabel(yes, if Daygreen then "Long" else if Dayred then "Short" else " ");


Everything I try comes up with an error.

Thank you
 
It's as easy as adding color.green right before closing the code.

Example:

Code:
AddLabel(yes, "Short Term", color.green);
 
Howdy and good am,

Is there a way to change the text label color to white or bright white. Right now it comes up as dark gray and makes it hard to see on a gray background screen.

Code:
AddLabel(yes, "SPX: " + AsText(Spy_Close) + "  ( " + AsText(Spy_value_change) + "  / " + Round(Spy_percent_change, 2) + "%) ", (if Round(Spy_percent_change, 2) > 0 then Color.DARK_GREEN else Color.rED));
 
Yeaph...thanks. I was pulling what little hair i had left out my head to figure it out LOL..

Ahhh, i thnk i see why...the label TEXT color is adopted from the background color of chart...
 
Hi, is there anyway to change the foreground color of a text label? I changed the chart background to black and it is hard to see the black text of the label but it shows up well on a light background. This is the script for the label:
addLabel(yes, "Ch: " + chday, if pos then color.dark_green else color.dark_RED);

I tried to insert the images but it wouldn't accept it, so here is a link below

Darktext.png


light.png
 
I have the background set for green for up net change or red for down net change so I can easily visually see it. If I were to change it to white it would defeat that purpose which is why I was hoping to be able to change the foreground color. Thanks
 
I know the available colors but how do you change the foreground text color? White text with green background or white text with red background
No matter how many times members ask, we cannot manually change foreground (text) color, its line weight, etc... TOS does have limitations and this is one of them and we all have to learn to live with it until such time that the developers decide to add more Look and Feel features...
 
@TCB, I feel your pain. I am not a coder, but learning bits and pieces. I wanted to have a simple watchlist column that wound display the "spread", or difference between the ask and the bid so I could quickly filter out stocks with BIG spreads. I found this example on the internet, sorry I can't give the author credit, as I can't find the URL for the video. You can change text color, per the following examples of code:

Code:
plot DiffSpread = (ask - bid);
DiffSpread.setDefaultColor (color.WHITE);
DiffSpread.DefineColor ("Above" , color.RED);
DiffSpread.DefineColor ("Below" , color.White);
DiffSpread. AssignValueColor (if DiffSpread < 0.05 then DiffSpread.color ("Below") else DiffSpread.color ("Above"));

You will get NaN for column results if using an intraday timeframe unless you check "Include Extended Hours Trading session". I believe this is due to the fact that ask and bid can not be used historically. Sometimes I find I get NaN for results if I set chart timeframe to DAY, which is confusing as that issue seems to be intermittent.

Below is another simple watchlist column, also borrowed from the internet that tracks Relative Volume, which is not available in TOS, however, RelativeVolumeStDev is a great study that is included.

Code:
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def vol = if isRollover and beforeStart then volume else if beforeStart then vol[1] + volume else Double.NaN;
def PMV = if IsNaN(vol) then PMV[1] else vol;
def AV = AggregationPeriod.DAY;
def x = Average(Volume(period=AV)[1],60);
def y1 = Round((PMV/x),2);
def L = Lg(y1);
def p = if L>=1 then 0 else if L>=0 then 1 else 2;
def y2 = Round(y1,p);
plot z = y2;
z.assignValueColor(if z>=7 then color.CYAN else if z>=1 then createcolor(255,153,153) else createcolor(0,215,0));

This code requires your chart timeframe be set to DAY.

This last example below, also borrowed but not credited to the author, plots Relative Volume %. If you run it you can see that the author picked colors that makes it extremely difficult to see the text in the box:

Code:
input offset = 1;
def rVol = volume(period = AggregationPeriod.Day) / Average(volume(period = AggregationPeriod.DAY), 63) [offset];
AddLabel(yes, Round(rVol, 2), Color.BLACK);
AssignBackgroundColor(if rVol > 10 then Color.BLUE
else if rVol > 8 then Color.DARK_GREEN
else if rVol > 6 then Color.GREEN
else if rVol > 4 then Color.LIGHT_GREEN
else if rVol > 2 then Color.LIME
else if rVol > 1 then Color.YELLOW
else if rVol < 1 then Color.PINK else Color.BLACK);
AddLabel(yes, asPercent(rVol));

If some generous coder out there could show me how to combine text and background colors, I would appreciate it. I want Green, Yellow ,and Red background for relative volume watchlist columns with text that would be visible. Yellow background with White text as an example just does not show.

I don't know if this helps you TCB?
Pat M
 
From a script perspective, is there any code that I can add to a script so the labels on the chart are smaller; say 25% to 50% smaller?
I have a 4x5 grid (20 charts) on my main monitor but when I add a study with labels, the labels are HUGE on the smaller charts, where real estate is at a premium....Have a great day!!!
 

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