 # IsNaN Question

#### jngy2k

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

#### BenTen

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

Last edited:

#### mfsteve

##### Member
VIP
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);

• cos251 and BenTen

##### Well-known member
VIP
Double.Nan is used to make a variable assignment... IsNan is a comparator used to test numeric presence...

#### strategynode

##### New member
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)``````