Having a rough time understanding IsNaN coding function


Well-known member
When you search this forum for Isnan, it comes back with 751 examples of it used


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


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

hello im new to this tos script. is there any way i could add this with moving avg ema. 5,10,21, for the upper chart?

# Swing Trade Indicator
# Momentum Belt

declare lower;
input price = close;
input BBlength = 5;
input BBNum_Dev = 0.5;
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 5;
input percentKLength = 7;

def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;

def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);

def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;

plot AvgSMI = expaverage(smi, percentDLength);

plot overbought = over_bought;

plot oversold = over_sold;

plot BB_Upper = reference BollingerBands(price = AvgSMI, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).UpperBand;
plot BB_Lower = reference BollingerBands(price = AvgSMI, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).Lowerband;
plot BB_Midline = reference BollingerBands(price = AvgSMI, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).MidLine;


plot Avg_SMI = AvgSMI > AvgSMI[1] and AvgSMI[1] < AvgSMI[2] and AvgSMI < Oversold ;​



Well-known member
  1. Why did you post your question in this thread?
  2. Why did you make your whole post in a bold headline font?
I have to tell you I find your post too difficult to read. Please edit your post. Cut out the code you posted and re-paste it as follows:
To share code in your post, click on this icon at the top of your post and then paste the script.

Lastly, be concise and complete in your query. A one sentence question doesn't tell us what you are looking for? Are you looking to understand isnan coding which is the title of your post? Are you looking to plot an EMA line which was part of your question? And what does any of it have to do with the script that you provided? A Pictures are worth 1000 words. Please provide a marked-up screenshot of what you are looking to do. Not providing screenshots severely limits the type of assistance that can be given.
How To Include Images In Your Post

Similar threads