Set watchlist color based on days until earnings



Once again thanks for your help with the label of the Advanced Declined Cumulative Average. My apologises for having another question with regards to labels.

I will like to add the days to earnings column to the watchlist. I have actually create the column based on what you recommend in a previous question posed on the forum based on the GetEventOffset function in TOS. However, i will like to change the colour of the number (as in the number of days) in the column. I am looking at

If number of days is more than 7, green numbers. if number of days is 7 or less, red colour. Appreciated if you can help me once again. Thank you


Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 21, 2022 10:05 pm
Private answer
  1. Since you are asking for a watchlist column solution I moved your question out of the Chart Studies topic and into the Watch Lists topic.
  2. The title of your question has been updated so that is clearly describes what this solution does.
  3. Whenever you reference another resource, you should provide a link to that resource so the rest of our viewers will be able to follow along and get the complete context of your question:

Please keep this details in mind as you post new questions in this forum.

Here is the code for the solution you requested. I took the code from the previous solution I linked to in bullet point 3 and I added two lines of code. One to contain the number of days and another to dynamically set the color of the value based on that number.

input limit = 7;
plot data = GetEventOffset("eventType" = Events.EARNINGS);
data.AssignValueColor(if data < -limit then Color.GREEN else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 3932)
Answered on November 22, 2022 1:32 pm
Noted on your comments. And your code works perfectly. Thanks a lot. You have make my charts and columns so much more comprehensive. By the way, i just found a thinkscript code below that manages to exclude the negative sign for days. However, i cant seem to get the label right. Any days less than 7 becomes a NaN on the column. How can i modify the label? def bn = BarNumber(); def na = Double.NaN; def getNextEarnings = AbsValue(GetEventOffset(Events.EARNINGS, 0)); def findDay = GetDayOfMonth(GetYYYYMMDD()); def findMonth = GetMonth(); def findYear = GetYear(); def getNextEarningsBarNumber = if !isNaN(getNextEarnings) then bn + getNextEarnings else na; def NextEarnings = bn == HighestAll(getNextEarningsBarNumber); def getNextEarningsMonth = HighestAll(if NextEarnings then findMonth else na); def getNextEarningsDay = HighestAll(if NextEarnings then findDay else na); def getNextEarningsYear = HighestAll(if NextEarnings then findYear else na); plot DaysToEarnings = getNextEarningsBarNumber; DaysToEarnings.Hide(); AddLabel(getNextEarnings > – 0, ”” + getNextEarnings + if getNextEarnings > 1 then ”” else ””,; AddLabel(getNextEarnings < 7, "", Color.RED);
( at November 22, 2022 7:15 pm)

I can tell you how to reverse the negative value to a positive value on the solution that I provided. Change the last TWO lines of code to the following: plot data = GetEventOffset(”eventType” = Events.EARNINGS) * -1; data.AssignValueColor(if data > limit then Color.GREEN else Color.CURRENT);

( at November 22, 2022 7:52 pm)
Again it works. Thanks so much. You are a great help. But i am sorry that i need to ask how can we delete the decimal point? Right now it is 30.0 or 4.0. I am using this code input limit = 14; plot data = GetEventOffset(”eventType” = Events.EARNINGS, + Round (data, 2)) * -1; data.AssignValueColor(if data > limit then Color.light_GRAY else Color.yellow); But the code doesnt work with the reason being: Too early to access data at 3:69 Only constants expected here: data CL dynamic param at 3:69 I am sorry to trouble you again
( at November 23, 2022 12:58 am)
It is not possible to delete the decimal point. Your modification creates invalid syntax. You will just have to live with the decimal points. It may be possible to convert those values to text, in which case you would have to replace the plot statement with an AddLabel() statement. But then you loose the ability to sort your watchlist by those values. Try not to fuss over things that don't matter and focus on accomplishing what you need to perform task as a trader.
( at November 23, 2022 8:51 am)
Hi Pete, yeah i agreed. Thanks a lot for your help. Really appreciated you taking your time to help us. But probably need some help with regards to bid ask spread label soon. But for now, let me go through what will really help me in my trading before asking you. Have a good end to year..Cheers
( at November 24, 2022 12:28 am)