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
@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