IsNaN Question

Use IsNaN to test whether a variable is set to a valid number versus N/A:

def myvar1 = 5;
AddLabel(yes, myvar1 + " is a number", if IsNaN(myvar1) then Color.RED else Color.GREEN);

def myvar2 = if close > 3000000 then close else double.nan;
AddLabel(yes, myvar2 + " is not a number", if IsNaN(myvar2) then Color.RED else Color.GREEN);
 
I was wondering if this could be used in the following scenario.

Problem occurs when there is no SMA 200 dosen't exist Example Ticker: AFRM

Original Code:
Code:
(SMA50>SMA200 and EMA21>SMA50 and Close>SMA50)

Tried The following Solutions:
Code:
#Solution One Using Or (Didn't Work)

(SMA50>SMA200 and EMA21>SMA50 and Close>SMA50)
Or
(EMA21>SMA50 and Close>SMA50)

#Solution Two Using If (Didn't Work)
If SMA200>0 then (SMA50>SMA200 and EMA21>SMA50 and Close>SMA50) else (EMA21>SMA50 and Close>SMA50)

#Solution Three Using if and IsNAN (Didn't Work)
If IsNaN(SMA200)==0 then (SMA50>SMA200 and EMA21>SMA50 and Close>SMA50) else (EMA21>SMA50 and Close>SMA50)
 
Trying to do the following:

input length = 200;

use in high(period = AggregationPeriod.DAY), length)

However, some stocks in my watchlist do not have data going back 200 days. Is there a way to tell the script to only look for length of days available and upto a max of 200.
 

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