IsNaN Question

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);
 

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)
 

Similar threads

Top