Hello everyone,
I’m struggling with implementing a proper range compression check in my screener. The requirement is:
Current candle’s range (high and low) must be fully contained within the range established by bars 5-14 ago (10 bars total).
I’ve tried several approaches but stocks making new highs are still appearing in results:
// Attempt 1: Using built-in functions
startIdx = 5
length = 10
windowHigh = Highest[length](High[startIdx])
windowLow = Lowest[length](Low[startIdx])
rangeCompression = High <= windowHigh AND Low >= windowLow
// Attempt 2: Manual FOR loop
windowStart = 5
windowEnd = 14
windowHighestHigh = High[windowStart]
windowLowestLow = Low[windowStart]
FOR i = windowStart TO windowEnd DO
IF High[i] > windowHighestHigh THEN
windowHighestHigh = High[i]
ENDIF
IF Low[i] < windowLowestLow THEN
windowLowestLow = Low[i]
ENDIF
NEXT
rangeCompression = High <= windowHighestHigh AND Low >= windowLowestLow
What am I missing? I’ve confirmed that stocks breaking to new highs (where current High > any High from 5-14 bars ago) are somehow passing this filter.
Could anyone spot an issue with my implementation or suggest a bulletproof way to ensure the current candle is ENTIRELY contained within the historical range?
Thanks in advance!
David
JSParticipant
Senior
Hi David,
I tested your first version of the screener on the U.S. stock market, and the results were in line with the screener itself…
Do you have an example of where things are going wrong on your end?
Hi, I have tried it too and it works correctly.
Is it possible that you have tested it with the market open on assets that you don’t have real time? In that case you have to look at the previous candle.