"GAP"叠加的打印选项



我想添加这个新的"间隙";指示器,我的组合覆盖作为一个支持和阻力工具,我需要它作为一个可选工具,这样我就可以根据需要打开和关闭它。因此,我需要在主代码的某个地方添加以下代码行

PlotGAP=input.bool(defval=false,title="Plot Gaps?"(

下面是";间隙";叠加-

//@version=5
indicator("Gaps", overlay = true, max_boxes_count = 500)
var allBoxesArray = array.new<box>()
var boxIsActiveArray = array.new<bool>()
var boxIsBullArray = array.new<bool>()
boxLimitInput = input.int(15, "Max Number of Gaps", minval = 1, maxval = 500)
minimalDeviationTooltip = "Specifies the minimal size of detected gaps, as a percentage of the average high-low range for the last 14 bars."
minimalDeviationInput = nz(input.float(30.0, "Minimal Deviation (%)", tooltip = minimalDeviationTooltip, minval=1, maxval=100) / 100 * ta.sma(high-low, 14))
limitBoxLengthBoolInput = input.bool(false, "Limit Max Gap Trail Length (bars)", inline = "Length Limit")
limitBoxLengthIntInput = input.int(300, "", inline = "Length Limit", minval = 1)
groupName = "Border and fill colors"
colorUpBorderInput = input.color(color.green, "Up Gaps", inline = "Gap Up", group = groupName)
colorUpBackgroundInput = input.color(color.new(color.green, 85), "", inline = "Gap Up", group = groupName)
colorDownBorderInput = input.color(color.red, "Down Gaps", inline = "Gap Down", group = groupName)
colorDownBackgroundInput = input.color(color.new(color.red, 85), "", inline = "Gap Down", group = groupName)
// Detect gaps.
isGapDown = high < low[1] and low[1] - high >= minimalDeviationInput
isGapUp = low > high[1] and low - high[1] >= minimalDeviationInput
isGap = isGapDown or isGapUp
isGapClosed = false
// Detect covering of gaps.
for [index, _box] in allBoxesArray
if array.get(boxIsActiveArray, index)
top = box.get_top(_box) 
bot = box.get_bottom(_box)
isBull = array.get(boxIsBullArray, index)
box.set_right(_box, bar_index)
if ((high > bot and isBull) or (low < top and not isBull)) or (limitBoxLengthBoolInput and bar_index - box.get_left(_box) >= limitBoxLengthIntInput)
box.set_extend(_box, extend.none)
array.set(boxIsActiveArray, index, false)
isGapClosed := true
// Add a box for each new gap, removing the oldest one if needed.
if isGap
box1 = box.new(
bar_index[1],
(isGapDown ? low[1] : low),
bar_index,
(isGapDown ? high : high[1]),
border_color = isGapDown ? colorDownBorderInput : colorUpBorderInput,
bgcolor = isGapDown ? colorDownBackgroundInput : colorUpBackgroundInput,
extend = extend.right)
array.push(allBoxesArray, box1)
array.push(boxIsActiveArray, true)
array.push(boxIsBullArray, isGapDown)
if array.size(allBoxesArray) > boxLimitInput
box.delete(array.shift(allBoxesArray))
array.shift(boxIsActiveArray)
array.shift(boxIsBullArray)

if barstate.islastconfirmedhistory and array.size(allBoxesArray) == 0
noGapText = "No gaps found on the current chart. n The cause could be that some exchanges align the open of new bars on the close of the previous one, resulting in charts with no gaps."
var infoTable = table.new(position.bottom_right, 1, 1)
table.cell(infoTable, 0, 0, text = noGapText, text_color = chart.bg_color, bgcolor = chart.fg_color)

alertcondition(isGap, "New Gap Appeared", "A new gap has appeared.")
alertcondition(isGapClosed, "Gap Closed", "A gap was closed.")

请帮助我确定我应该在代码内部的哪里添加函数,以便根据需要打开和关闭它。谢谢你抽出时间。当做

可能是这样的

...
isGap = PlotGAP and (isGapDown or isGapUp)
...

最新更新