Another isNAN() question

sevensa

New member
Hi

I'm still quite new to ThinkScript and TOS in general and I am trying to understand isNAN() function. I see there are a couple of examples and questions, but I am still not quite sure about something.

I do understand that this is used to check if a parameter value is a number or not. Where my confusion come in is when I look at the example here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/IsNaN

specifically, the first line line under Example1 from the link above:
Code:
def onExpansion = if IsNaN(close) then yes else no;
plot HighestClose = if onExpansion then HighestAll(close) else double.NaN;
plot LowestClose = if onExpansion then LowestAll(close) else double.NaN;

My question is, under what circumstances would IsNaN(close) not be number?
 
Solution
Hi

I'm still quite new to ThinkScript and TOS in general and I am trying to understand isNAN() function. I see there are a couple of examples and questions, but I am still not quite sure about something.

I do understand that this is used to check if a parameter value is a number or not. Where my confusion come in is when I look at the example here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/IsNaN

specifically, the first line line under Example1 from the link above:
Code:
def onExpansion = if IsNaN(close) then yes else no;
plot HighestClose = if onExpansion then HighestAll(close) else double.NaN;
plot LowestClose = if onExpansion then LowestAll(close) else double.NaN;

My question is...
Hi

I'm still quite new to ThinkScript and TOS in general and I am trying to understand isNAN() function. I see there are a couple of examples and questions, but I am still not quite sure about something.

I do understand that this is used to check if a parameter value is a number or not. Where my confusion come in is when I look at the example here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/IsNaN

specifically, the first line line under Example1 from the link above:
Code:
def onExpansion = if IsNaN(close) then yes else no;
plot HighestClose = if onExpansion then HighestAll(close) else double.NaN;
plot LowestClose = if onExpansion then LowestAll(close) else double.NaN;

My question is, under what circumstances would IsNaN(close) not be number?

trying to read a price, when no price data exists, results in an error , nan

-------------------------------

get in the habit of trying to use addchartbubble() to display variable values, it will help you understand what the formulas are doing.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddChartBubble

when \n is used, it forces data after it to appear on a new text line, in the bubble.
i tend to use + "\n" + out of habit.
this line,
"close" + "\n" +
could have been written as,
"close\n" +

--------------------------

this test code displays the close price on all candles.


Code:
# test_nan
def p = 100;

addchartbubble(
1, p,
"close" + "\n" +
close
,color.yellow, yes);
#


plotting bubbles at a price level of $100.
each shows the close price of a candle.
during candles, a price is shown.
after the last candle, there is no price data, so no close price exists.
so trying to read close, when no price data exists, results in an error , nan
1WI6M3d.jpg
 
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thank you, this is a very helpful tip. My confusion is that about why ThinkScript is trying to get the close for a bar that doesn't exist. If I use close, I would expect it to give me the close of the current bar. I didn't think that I need to check if ThinkScript might try to give me the close for a bar that doesn't exist beyond the current bar. But now I do and I guess the why doesn't matter, I just need to work with it. :)
 
Thank you, this is a very helpful tip. My confusion is that about why ThinkScript is trying to get the close for a bar that doesn't exist. If I use close, I would expect it to give me the close of the current bar. I didn't think that I need to check if ThinkScript might try to give me the close for a bar that doesn't exist beyond the current bar. But now I do and I guess the why doesn't matter, I just need to work with it. :)

if you use addlabel(1, close);
it will show the close of the last bar

but each time a new bar appears on the chart, all the price data from all the bars are used to redraw all the lines and shapes on the chart.
so in formulas, close will be read from all bars


the area after the last bar is the expansion area.
see image above, bubbles were drawn in the expansion area, even though no bars exist.
there is still a placeholder so to speak , for bars.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
305 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