• Get $40 off VIP by signing up for a free account! Sign Up

Help with Earnings Date Watchlist column

DrOculus

New member
VIP
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

# 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
 

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

Similar to Joshua/Paris's code, this seems to work

Screenshot 2024-03-13 235814.png
Code:
def lastbar = (if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN);

def days = absvalue(GetEventOffset(Events.EARNINGS));
def day  = HighestAll(if BarNumber() == HighestAll(lastbar + days) then GetDayOfMonth(GetYYYYMMDD()) else Double.NaN);
def mon  = HighestAll(if BarNumber() == HighestAll(lastbar + days) then GetMonth() else Double.NaN);
def year = HighestAll(if BarNumber() == HighestAll(lastbar + days) then GetYear() - 2000 else Double.NaN);

AddLabel(1, mon + "/" + day + "/" + year);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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