This is a study to show the next earnings date made by Paris a few years ago. I modified it slightly to only show the date and some changes with colors. It works great on a chart (with a large expansion to the right to encompass future earnings date), but when I add it to my watchlist as a column it can't go further out then 30 days. It's correct on anything sooner than that, but if it's farther out than 30 bars it just outputs the date 30 bars away. Any suggestions?
Thanks in advance
Thanks in advance
# Next Earnings Date
# Paris
# 10.15.2019
# You have to have enough expansion area on your chart available to reach the actual Earnings date, so if you have 0 expansion area, an inconsistent date will be displayed
#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(getNextEarnings > 5, getNextEarningsMonth + "/" + getNextEarningsDay + "/" + AsPrice(getNextEarningsYear), Color.Green);
AddLabel(getNextEarnings between 1 and 5, getNextEarningsMonth + "/" + getNextEarningsDay + "/" + AsPrice(getNextEarningsYear), Color.Yellow);
AddLabel(getNextEarnings == 0, " EARNINGS TODAY ", Color.Red);
# End Next Earnings Date