(Cindy was one of the original script masters that worked for TOS)
#HINT: watchlist label that shows days-to-earnings and next earnings date (if next earnings date is available). Includes a visual alert if "EARNINGS TODAY"
#def allows you to teach ThinkScript new "words" to save time and typing by using your new "words" later in the code
def bn = BarNumber();
def na = Double.NaN;
def getNextEarnings = AbsValue(GetEventOffset(Events.EARNINGS, 0));
def findDay = GetDayOfMonth(GetYYYYMMDD());
def findMonth = GetMonth();
def findYear = GetYear();
#ThinkScript thinks in numbers, including converting dates into numbers and viewing each bar on the chart as a number. Therefore you can use BarNumber to tell ThinkScript which bar, and use lines in ThinkScript code to 'trick' ThinkScript into displaying that daily bar in date format
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 tells ThinkScript what data you want displayed. Hide() is used in this case because desired display is the label and not the numberic equivalent of the data
plot DaysToEarnings = getNextEarningsBarNumber;
DaysToEarnings.Hide();
#AddLabel makes the data more user friendly when viewing the watchlist column
AddLabel(if getNextEarnings > 1 then yes else no, getNextEarnings + ";" + " Date= " + (getNextEarningsMonth) + "-"+ (getNextEarningsDay) + "-" + AsPrice((getNextEarningsYear)) , Color.BLACK);
AssignBackgroundColor(color.LIGHT_GRAY);
#because of the condition at beginning of AddLabel, if today is earnings date then days-to-earnings label will be hidden and this visual alert label will be visible
AddLabel(if getNextEarnings == 0 then yes else no, " EARNINGS TODAY !!!", color.RED);