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

How to understand this code?

petech

Member
I'm reading someone else's code that I got elsewhere online, this only a portion of it...


def EarnPerShareY = if isNaN(EarningsPerShareTTM())
then EarnPerShareY[1]
else EarningsPerShareTTM();

I'm don't code (much), so I'm having a hard time understanding what I am reading. I've been looking up the learning center for thinkscript.
  • def EarnPerShareY, defining a variable
  • isNaN, this one returns true or false depending if the value is a number
  • EarningsPerShareTTM(), this gives quarterly EPS for the trailing 12 months
  • then EarnPerShareY[1], some sort of variable with an array being setup? I don't understand what is happening here.
  • else EarningsPerShareTTM(), I'm not sure what this line is about either

Basically it reads like if EarningsPerShareTTM() is a number, then EarnPerShareY[1], if it is not a number else EarningsPerShareTTM().

At this point I'm still not understanding what it is that I'm reading. Or how the logic of the script works. Can someone be so kind to explain it to me?
 
Scripts are iterated on a bar by bar basis. Meaning, they are basically ran over and over again, once per each bar. All variables are technically arrays, indexed by bar. The code is basically checking to see if the value for this bar is blank. If it is blank, the value for this bar is assigned the value of the previous bar, otherwise it is assigned the new value.
 
Scripts are iterated on a bar by bar basis. Meaning, they are basically ran over and over again, once per each bar. All variables are technically arrays, indexed by bar. The code is basically checking to see if the value for this bar is blank. If it is blank, the value for this bar is assigned the value of the previous bar, otherwise it is assigned the new value.
Thanks
 

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
321 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