# IsNaN Question

#### jngy2k

##### Member
Anyone have some simple code examples that can explain the function?

You can try the following links:
Wish I could help. I have only been using `double.nan` so I'm not sure.

Last edited:
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);

Double.Nan is used to make a variable assignment... IsNan is a comparator used to test numeric presence...

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.

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
390 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?