Include blank values in a scan

wchillman

New member
Here is the situation. I ran a simple scan that looked for:

plot scan = [Criteria] > 20;

Of course, it worked perfectly by excluding all entries for which the criteria were less than or equal to 20. However, it also excluded entries that were blank (actually, when I ran my cursor over them it indicated “N/A”.

Now, what do I have to do to get these blank entries included with the original scan?
 
Last edited by a moderator:

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

Ruby,

Thank you for your reply. It sure looked like it was going to work! However, I am at a loss here to explain why it doesn't. Let's narrow the playing field to:

plot scan = Close > 2 AND Close < 3 AND Volume < 2000;

Now add this as a column to the scan:

def LB = 252;
def HH = Highest(High,LB);
def LL = Lowest(Low, LB);
plot DR = 100*(HH/LL-1);


You will see many "N/A" entries. If I add the following scan,

def LB = 252;
def HH = Highest(High, LB);
def LL = Lowest(Low, LB);
def Criteria = 100*(HH/LL-1);
plot scan = IsNaN(Criteria) or Criteria > 20;


I lose all the "N/A" entries. Obviously, all those entries are stocks that have less than 252 days of trading history. What do I need to do to get them included?
 
Having a NaN value appear on either side of a logical (or), comparison (>), or arithmetic operator will cause the entire expression to resolve to NaN. If Criteria's value is NaN, then NaN > 20 resolves to NaN, and then Anything Or NaN will also resolve to NaN. This can only be handled by a conditional expression, and in the correct order. You must ensure that the value isn't NaN (if) before attempting to resolve it (else if).

Plot Scan =
if isNaN(Criteria) then Yes
else if Criteria > 20 then Yes
else No;

This will not work:
Plot Scan =
if Criteria > 20 then Yes
else if isNaN(Criteria) then Yes
else No;
 
Joshua,

Thank you for your explanation. Here’s my scan with your revision. First, I narrowed the playing field with this scan:

plot Scan = Close > 2 AND Close < 3 AND Volume < 2000;

It yields over 100 stocks and many of them show a result of “N/A”. Next, if I add this revised scan,

def LB = 252;
def HH = Highest(High, LB);
def LL = Lowest(Low, LB);
def Criteria = 100*(HH/LL-1);
plot Scan =
if isNaN(Criteria) then Yes
else if Criteria > 20 then Yes
else No;

I still lose all the “N/A” entries. What am I missing?
 
There is a hard left edge at the absolute beginning of the existing data, it behaves quite differently than the right side expansion area. Nothing beyond that edge can be retrieved or evaluated at all, attempting to do so doesn't even produce a NaN value.

I would suggest determining when you're within 252 bars of the right side edge, by using an IsNaN() check against a forward offset. Once you're within that range, start tabulating the highest high and lowest low manually.

If there are less than 252 bars, you'll end up with the highest and lowest out of what ever number of bars there are. You can also count the bars to determine if there are less than 252, and handle that how ever you want.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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