Help Debugging Range Compression in Screener

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #248540 quote
    David1998P
    Participant
    New

    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

    #248541 quote
    JS
    Participant
    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?

    #248603 quote
    Iván González
    Moderator
    Master

    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.

    David1998P thanked this post
    #248708 quote
    David1998P
    Participant
    New

    Yes exactly this, thanks

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Help Debugging Range Compression in Screener


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
David1998P @david1998p Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by David1998P
7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/25/2025
Status: Active
Attachments: No files
Logo Logo
Loading...