Indicator for gaps

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #256732 quote
    theunpredictabletheunpredictable
    Participant
    New

    Hi,

    I just want to create an indicator to shows gaps (close to previous close) when they are more than 2%.

    The indicator should show a line 0 or 1.


    Here is what i thought it would work but it doesn’t:

    if close/close[1]>1.02 then
    
    x=1
    
    else
    
    x=0
    
    endif
    
    
    
    
    if close/close[1]<0.98 THEN 
    
    y=1
    
    ELSE 
    
    x=0
    
    ENDIF 
    
    
    
    
    if x=1 or y=1 THEN 
    
    Gap=1
    
    ELSE 
    
    gap=0
    
    ENDIF 
    
    
    
    
    return Gap
    


    Do you habe any ideas?

    Thx in advance.


    Greets Björn

    #256735 quote
    AI-vyAI-vy
    Moderator
    Junior

    @theunpredictable your logic is fine, but there are two issues in your code:

    • In the second IF block you set x=0 in the ELSE instead of y=0, so y can stay uninitialized/incorrect.
    • You don’t need two variables at all; you can compute the condition directly (cleaner and avoids mistakes).

    ProBuilder indicator (0/1 line) for > 2% move vs previous close:

    // Gap vs previous close greater than 2% (up or down)
    Gap = 0
    IF close[1]> 0 THEN
    IF abs(close/close[1] - 1) >= 0.02 THEN
    Gap = 1
    ENDIF
    ENDIF
    
    RETURN Gap
    


    Why this works:

    • close/close[1] – 1 gives the percentage change from the previous close (e.g., 0.021 = +2.1%).
    • abs(…) makes up and down moves equivalent, so one test covers both directions.
    • close[1] <> 0 prevents division by zero (rare, but safe).

    If you prefer your original structure, corrected:

    x = 0
    y = 0
    
    IF close[1] >0 THEN
    IF close/close[1] > 1.02 THEN
    x = 1
    ELSE
    x = 0
    ENDIF
    
    IF close/close[1] < 0.98 THEN
    y = 1
    ELSE
    y = 0
    ENDIF
    ENDIF
    
    
    IF x = 1 OR y = 1 THEN
    Gap = 1
    ELSE
    Gap = 0
    ENDIF
    
    RETURN Gap
    
    Iván González and robertogozzi thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Indicator for gaps


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by AI-vyAI-vy
8 months, 1 week ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/23/2026
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...