This indicator provides a way to track 3 different types of Gaps along with actively tracking how far away the price is from closing them. Open gaps to the upside are represented as positive bars and gaps to the downside as negative bars.
The Gap types are as follow:
The gap type can be manually switched using the GapType parameter.
The code looks as follow:
//Gap Type as Variable
If GapType = 1 Then //Daily
SGap = 0
LGap = 0
If hour = 17 and minute = 0 Then
GapClose = close
ElsIf hour = 9 and minute = 0 then
If low > GapClose Then
Gap = (low-GapClose)* -1
ElsIf high < GapClose Then
Gap = (GapClose-high) * +1
EndIf
ElsIf hour >= 9 and hour < 17 Then
If Gap > 0 Then
Gap = (GapClose-high) * +1
ElsIf Gap < 0 Then
Gap = (low-GapClose) * -1
EndIf
Else
Gap = 0
EndIf
ElsIf GapType = 2 Then //Intraday
Gap = 0
Once SGap = 0
Once LGap = 0
If hour < 9 or hour >= 22 Then
SGap = 0
LGap = 0
Else
If SGap = 0 and low - high[1] > 0.0001 THEN
SGapClose = high[1]
SGap = (low-SGapClose) * -1
EndIf
If LGap = 0 and low[1] - high > 0.0001 THEN
LGapClose = low[1]
LGap = (LGapClose-High) * +1
ENDIF
If SGap < 0 Then
If (low-SGapClose) * -1 > 0 Then
SGap = 0
Else
SGap = (low-SGapClose) * -1
EndIf
EndIf
If LGap > 0 Then
If (LGapClose-High) < 0 Then
LGap = 0
Else
LGap = (LGapClose-High) * +1
EndIf
EndIf
EndIf
ElsIf GapType = 3 Then //Brooks Gap
Gap = 0
Once SGap = 0
Once LGap = 0
If hour < 9 or hour >= 22 Then
SGap = 0
LGap = 0
Else
If SGap = 0 and low - high[2] > 0.0001 THEN
SGapClose = high[2]
SGap = (low-SGapClose) * -1
EndIf
If LGap = 0 and low[2] - high > 0.0001 THEN
LGapClose = low[2]
LGap = (LGapClose-High) * +1
ENDIF
If SGap < 0 Then
If (low-SGapClose) * -1 > 0 Then
SGap = 0
Else
SGap = (low-SGapClose) * -1
EndIf
EndIf
If LGap > 0 Then
If (LGapClose-High) < 0 Then
LGap = 0
Else
LGap = (LGapClose-High) * +1
EndIf
EndIf
EndIf
EndIf
return Gap style(HISTOGRAM) as "GAP", SGap style(HISTOGRAM) as "Short GAP", LGap style(HISTOGRAM) as "Long GAP", 0 as "zero"