PineScript - 向 ON/OFF 图表添加输入

PineScript - Adding Input to ON/OFF chart plots

PineScript 新手。

我将这个指标脚本(https://www.tradingview.com/script/a0vTLaS6-Double-Top-Bottom-Ultimate-OS/)添加到我原来的策略中,所以我可以为策略添加新的条件。close/entry,但问题是我以前的图表绘图和一些按钮现在不再工作了。我认为我插入的新脚本 (copy/past) 覆盖了之前的策略,因此之前的图表不工作。在这种情况下,我认为最好的选择是为下面显示的框创建一个 Input.bool。

我想到了这个:

xyz = input(title="XYZ", type=input.bool, defval=false)

但我不知道如何将此输入与其相关行相关联。我认为第 172 行是此框的相关代码:

labelText = (doubleTop? "Double Top" : "Double Bottom") + (DisplayRiskPerReward ? " RR - "+tostring(riskPerReward) : "")

此外,如果我想向我的策略添加(copy/past)新脚本。有没有办法 在我的指标中为整个指标创建一个按钮?例如,我的指标名称是“XYZ”,我想在“XYZ”中添加“ABC”。有没有办法为“ABC”设置一个按钮,这样当我使用通用指标(“XYZ”)时,我可以将其关闭和打开?是正常输入吗?或者我应该缩进代码中的所有内容?

因此,如果您想输入 enable/disable 那个“Double Bottom RR”标签,您可以为此输入一个变量,并使用 if 条件来决定是否应该绘制。

创建输入: 布尔 plotLabel = 输入(真)

然后修改172行,作图处理如下(注意缩进):

var  label baseLabel = na

if (plotLabel == true)
    labelText = (doubleTop? "Double Top" : "Double Bottom") + (DisplayRiskPerReward ? " RR - "+tostring(riskPerReward) : "")

    baseLabel := label.new(x=index, y=value, text=labelText, yloc=doubleTop?yloc.abovebar:yloc.belowbar,
      color=doubleTop?bearishColor:bullishColor, 
      style=doubleTop?label.style_label_down:label.style_label_up,
      textcolor=textColor, size=size.normal)

因此,为了绘制该标签,plotLabel 输入必须是 true

Also, In case I want to add(copy/past) new scripts to my strategy. Is there a way to create a button for the whole indicator, within my indicator? For instance, my indicator's name is "XYZ" and I want to add "ABC" inside "XYZ". Is there a way to set a button for "ABC", so when I use the general indicator ("XYZ"), I can just turn it off and on? Is it normal input? or I should indent everything in the code?

不,您需要修改代码并为您复制的整个脚本添加 enable/disable 输入。