Beginner's error... Discrepancy between scan results and chart.. I cannot figure it out. Help needed.

kkrac

New member
So I have a script that I saved as a setup scan, which simply does the following (the original script is a bit more complex, but for the sake of the example, I used just this portion which is still not working):

Code:
plot a = low < low[1];

If I create an indicator with the same code that prints a "1" or a "0" if the condition is met, I sometimes see unexpected results.
So the indicator does the following:

Code:
addLabel(1, low < low[1]);

which clearly just prints a "1" if the current candle's low is lower than the previous candle's low, otherwise "0".

If I use the scan with Daily timeframe (extra hours unchecked), it works... ie: for all stocks returned, the last candle's low is lower than the previous low, and I will see a "1" on the chart as expected(extra hours turned off on the chart).

But if I switch to 1 hour timeframe on the scanner (extra hours still unchecked), sometimes it doesn't work on the 1hour chart (extra hours turned off), meaning that for some stocks, the low of the last candle isn't lower than the low[1], and the label in consequence shows a "0" as expected. But the scanner still returns it, why?

How can that be?
 
Last edited:
Solution
So I have a script that I saved as a setup scan, which simply does the following (the original script is a bit more complex, but for the sake of the example, I used just this portion which is still not working):

Code:
plot a = low < low[1];

If I create an indicator with the same code that prints a "1" or a "0" if the condition is met, I sometimes see unexpected results.
So the indicator does the following:

Code:
addLabel(1, low < low[1]);

which clearly just prints a "1" if the current candle's low is lower than the previous candle's low, otherwise "0".

If I use the scan with Daily timeframe (extra hours unchecked), it works... ie: for all stocks returned, the last candle's low is lower than the previous low, and I will see a...
So I have a script that I saved as a setup scan, which simply does the following (the original script is a bit more complex, but for the sake of the example, I used just this portion which is still not working):

Code:
plot a = low < low[1];

If I create an indicator with the same code that prints a "1" or a "0" if the condition is met, I sometimes see unexpected results.
So the indicator does the following:

Code:
addLabel(1, low < low[1]);

which clearly just prints a "1" if the current candle's low is lower than the previous candle's low, otherwise "0".

If I use the scan with Daily timeframe (extra hours unchecked), it works... ie: for all stocks returned, the last candle's low is lower than the previous low, and I will see a "1" on the chart as expected(extra hours turned off on the chart).

But if I switch to 1 hour timeframe on the scanner (extra hours still unchecked), sometimes it doesn't work on the 1hour chart (extra hours turned off), meaning that for some stocks, the low of the last candle isn't lower than the low[1], and the label in consequence shows a "0" as expected. But the scanner still returns it, why?

How can that be?

what happens to this on bar #1?
..def a = low < low[1];
it tries to look back at the previous bar, which doesn't exist, so it is n/a. this n/a value may cascade through all the other bars.

you can trap it with compoundvalue().

i tend to use an if-then
a = if barnumber() == 1 then 0 else low < low[1];
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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