GAPS
GAPS
type AlertInfo
int countOpenGap
int countClosedGap
//@type A representation of a chart gap and all box drawings that it consists of.
//@field isActive If 'true', the gap has not yet been closed and is still being
extended on the chart.
//@field isBull The direction of the gap: 'true' for upward gaps and 'false' for
downward ones.
//@field inactiveBoxes An array of all boxes that have been drawn for this gap. The
last element of the array is the box on the chart that is currently extended
further.
type Gap
bool isActive
bool isBull
array<box> boxes
//@function Deletes all of the boxes that were drawn to represent the gap.
method delete(Gap this) =>
for _box in this.boxes
_box.delete()
//@function Closes the gap partially, stopping the previous box and creating a new,
smaller box to continue the gap instead.
method partialClose(Gap this) =>
activeBox = this.boxes.last()
activeBox.set_extend(extend.none)
top = this.isBull ? activeBox.get_top() : low
bottom = this.isBull ? high : activeBox.get_bottom()
this.boxes.push(box.new(
bar_index,
top,
bar_index,
bottom,
this.isBull ? colorDownBorderInput : colorUpBorderInput,
bgcolor = this.isBull ? colorDownBackgroundInput : colorUpBackgroundInput))
//@function Closes the gap fully, stopping the box from being extended.
method fullClose(Gap this) =>
alertInfo.countClosedGap += 1
activeBox = this.boxes.last()
activeBox.set_extend(extend.none)
this.isActive := false
if closeGapsPartially
activeBox.delete()
if (high > bot and isBull) or (low < top and not isBull)
if closeGapsPartially
this.partialClose()
else
this.fullClose()
// Detect gaps.
isGapDown = high < low[1] and low[1] - high >= minimalDeviationInput
isGapUp = low > high[1] and low - high[1] >= minimalDeviationInput
isGap = isGapDown or isGapUp
boxBorderColor = isGapDown ? colorDownBorderInput : colorUpBorderInput
boxBgcolor = isGapDown ? colorDownBackgroundInput : colorUpBackgroundInput
newBox = box.new(
bar_index - 1,
(isGapDown ? low[1] : low),
bar_index,
(isGapDown ? high : high[1]),
border_color = boxBorderColor,
bgcolor = boxBgcolor,
extend = extend.right)
// Add a box for each new gap, removing the oldest one if needed.
if isGap
registerNewGap(isGapDown)