Custom column in Monitor Tab

stormy77

Member
VIP
Greetings!
I'm trying to find out if there's a way to add a custom column in the "position statement" on the Monitor tab under "activity and Positions" section.
I would like to get some kind of visual indicator of earnings in next 3 days. I know ToS has the built in icons that show that, but I want something more obvious
I want to create a column that shows a colored background, Orange or red along with days to earnings

I have this so far, but I'm not getting it to show the background color:

Code:
declare lower;

def offset = GetEventOffset(Events.EARNINGS, 0);
def hasEarnings = !IsNaN(offset) && offset <= 0;
def daysToEarnings = if hasEarnings then -offset else 0;

def isBefore = if hasEarnings then HasEarnings(EarningTime.BEFORE_MARKET) else no;
def isAfter  = if hasEarnings then HasEarnings(EarningTime.AFTER_MARKET)  else no;
def earnHourOffset = if isBefore then -1.0 else if isAfter then 6.5 else 0.0;
def earnBarTimeMs = if hasEarnings then GetValue(GetTime(), offset) else Double.NaN;
def earningsTimeMs = earnBarTimeMs + earnHourOffset * 3600000;
def nowMs = GetTime() + SecondsFromTime(0930) * 1000;
def hoursToEarnings = (earningsTimeMs - nowMs) / 3600000;

plot signal = if hasEarnings then daysToEarnings else 0;
signal.AssignValueColor(Color.WHITE);

AssignBackgroundColor(
    if hasEarnings && hoursToEarnings > 0 && hoursToEarnings <= 48 then Color.RED
    else if hasEarnings && daysToEarnings <= 5 then CreateColor(255, 165, 0)
    else Color.CURRENT
);


for reference, I have this daily squeeze column that i had downloaded some time ago, it perfectly shows the coloem background color and value

Code:
input BollingerDeviations = 2.0; input BollingerLength = 20.0; input KeltnerFactor = 1.5; input KeltnerLength = 20; input price = close; def bk = reference BollingerBands("num_dev_up" = BollingerDeviations, "length" = BollingerLength )."upperband" - reference KeltnerChannels("factor" = KeltnerFactor, "length" = KeltnerLength)."Upper_Band"; def grnconsecdots = if bk[0] > 0 and bk[1] > 0 and bk[2] > 0 and bk[3] > 0 and bk[4] > 0 and bk[5] > 0 and bk[6] > 0 then 7 else if bk[0] > 0 and bk[1] > 0 and bk[2] > 0 and bk[3] > 0 and bk[4] > 0 and bk[5] > 0 then 6 else if bk[0] > 0 and bk[1] > 0 and bk[2] > 0 and bk[3] > 0 and bk[4] > 0 then 5 else if bk[0] > 0 and bk[1] > 0 and bk[2] > 0 and bk[3] > 0 then 4 else if bk[0] > 0 and bk[1] > 0 and bk[2] > 0 then 3 else if bk[0] > 0 and bk[1] > 0 then 2 else if bk[0] > 0 then 1 else 0; def redconsecdots = if bk[0] < 0 and bk[1] < 0 and bk[2] < 0 then 3 else if bk[0] < 0 and bk[1] < 0 then 2 else if bk[0] < 0 then 1 else 0; plot signal = if grnconsecdots > 0 then grnconsecdots else redconsecdots + 10; signal.AssignValueColor (Color.BLACK); AssignBackgroundColor( if bk[0] < 0 then Color.RED else if grnconsecdots < 7 then Color.GREEN else Color.BLACK);

2025-10-24_01-03-50.jpg



can anyone please guide me?
 
Solution
Columns get weird with forward offsets and AssignBackgroundColor(). They're always based on the final bar, but something goes astray and creates a right side expansion area of sorts. Try this.

You can obviously change the colors, and change the label to display a space (" ") if you just want a colored box with no text.

3JpSNEQ.png


Code:
def edge = isNaN(close[-1]) && !isNaN(close);
def offset;
if edge then {
    offset = absvalue(GetEventOffset(Events.EARNINGS, 0));
} else {
    offset = Double.NaN;
}
def track =
    if (isNan(close), track[1],offset);
assignBackgroundColor(
    if track < 6 then color.blue else color.current
);
addlabel(yes, track);

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

Thank you. it sort of works, but I'm stuck on loading for ever. It took over 5 minutes to get one of the boxes to turn red. and most show loading. In the version I shared, I get no color, but the values show up instantly

This has been a common problem on the TOS platform... I had been using a Custom Watchlist Column for my SPY Options Watchlist Delta that would color the Calls Green and Puts Red but load display times after refreshes were lagging far too long... After several attempts at what little code optimization I could perform I had to remove that CWC and settle for the default Delta column... Unfortunate, but necessary for my needs... YMMV...
 
This script
Code:
declare lower;

def offset = GetEventOffset(Events.EARNINGS, 0);
def hasEarnings = !IsNaN(offset) && offset <= 0;
def days = if hasEarnings then Round(-offset, 0) else Double.NaN;

plot signal = if hasEarnings then days else Double.NaN;
signal.AssignValueColor(Color.WHITE);

AssignBackgroundColor(if hasEarnings && days <= 5 then Color.ORANGE else Color.CURRENT);

shows the values quickly, but i can't seem to get the logic for showing colors right
the columns shows days like 1.0, 3.0 etc. I can live with that, but color would be helpful
 
Columns get weird with forward offsets and AssignBackgroundColor(). They're always based on the final bar, but something goes astray and creates a right side expansion area of sorts. Try this.

You can obviously change the colors, and change the label to display a space (" ") if you just want a colored box with no text.

3JpSNEQ.png


Code:
def edge = isNaN(close[-1]) && !isNaN(close);
def offset;
if edge then {
    offset = absvalue(GetEventOffset(Events.EARNINGS, 0));
} else {
    offset = Double.NaN;
}
def track =
    if (isNan(close), track[1],offset);
assignBackgroundColor(
    if track < 6 then color.blue else color.current
);
addlabel(yes, track);
 
Solution
@stormy77 I can assure you that the color change functions are what is causing the delays... Trust me, I share your frustration... AssingValueColor() and AssignBackgroundColor() are your biggest culprits... Sometimes we have to pick our battles...
 
Columns get weird with forward offsets and AssignBackgroundColor(). They're always based on the final bar, but something goes astray and creates a right side expansion area of sorts. Try this.

You can obviously change the colors, and change the label to display a space (" ") if you just want a colored box with no text.

3JpSNEQ.png


Code:
def edge = isNaN(close[-1]) && !isNaN(close);
def offset;
if edge then {
    offset = absvalue(GetEventOffset(Events.EARNINGS, 0));
} else {
    offset = Double.NaN;
}
def track =
    if (isNan(close), track[1],offset);
assignBackgroundColor(
    if track < 6 then color.blue else color.current
);
addlabel(yes, track);
you da man! Thanks. That works. I tweaked it slightly


Code:
def edge = isNaN(close[-1]) && !isNaN(close);
def offset;
if edge then {
    offset = absvalue(GetEventOffset(Events.EARNINGS, 0));
} else {
    offset = Double.NaN;
}
def track = if (isNan(close), track[1], offset);

assignBackgroundColor(
    if track <= 2 then CreateColor(102, 204, 0)
    else if track <= 5 then CreateColor(255, 102, 0) 
    else if track <=14 then  CreateColor(255, 255, 51)
    else color.current
);

addlabel(yes, track, Color.black);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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