Days B4 Earnings Label

c3rfc1

New member
VIP
I have a script that displays the number of days before earnings. I think I have made it too complex and it is not displaying exactly as I would like. The problems are:
1. On stocks that do not have earings it displays loading, I would like to see N/A.
2. If earnings are greater than 15 days it displays > 15 days yet from 1 to 14 it only displays the number of days.
3. The day of earnings it does not appear to be displaying B4 Open or After Close.

Would appreciate some help on this code.

def pg = GetEventOffset(Events.earnings, 0);
def isAfter = HasEarnings(EarningTime.AFTER_MARKET);
def isBefore = HasEarnings(EarningTime.BEFORE_MARKET)[-1];
addlabel(!isnan(pg) and pg<=0,
if pg == -14 then " 14" else
if pg == -13 then " 13" else
if pg == -12 then " 12" else
if pg == -11 then " 11" else
if pg == -10 then " 10" else
if pg == -9 then " 9" else
if pg == -8 then " 8" else
if pg == -7 then " 7" else
if pg == -6 then " 6" else
if pg == -5 then " 5" else
if pg == -4 then " 4" else
if pg == -3 then " 3" else
if pg == -2 then " 2" else
if pg == -1 and isBefore then " 1-B4 Open" else
if pg == -1 then " 1" else
if ((pg == 0 and isafter == 1) ) then "After Close" else "> 15 Days",Color.white);
 
I have a script that displays the number of days before earnings. I think I have made it too complex and it is not displaying exactly as I would like. The problems are:
1. On stocks that do not have earings it displays loading, I would like to see N/A.
2. If earnings are greater than 15 days it displays > 15 days yet from 1 to 14 it only displays the number of days.
3. The day of earnings it does not appear to be displaying B4 Open or After Close.

Would appreciate some help on this code.

def pg = GetEventOffset(Events.earnings, 0);
def isAfter = HasEarnings(EarningTime.AFTER_MARKET);
def isBefore = HasEarnings(EarningTime.BEFORE_MARKET)[-1];
addlabel(!isnan(pg) and pg<=0,
if pg == -14 then " 14" else
if pg == -13 then " 13" else
if pg == -12 then " 12" else
if pg == -11 then " 11" else
if pg == -10 then " 10" else
if pg == -9 then " 9" else
if pg == -8 then " 8" else
if pg == -7 then " 7" else
if pg == -6 then " 6" else
if pg == -5 then " 5" else
if pg == -4 then " 4" else
if pg == -3 then " 3" else
if pg == -2 then " 2" else
if pg == -1 and isBefore then " 1-B4 Open" else
if pg == -1 then " 1" else
if ((pg == 0 and isafter == 1) ) then "After Close" else "> 15 Days",Color.white);
https://usethinkscript.com/threads/label-showing-next-earnings-date.14660/
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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