【问题标题】:PineScript = Adding input to atr stoplossPineScript = 向 atr 止损添加输入
【发布时间】:2021-12-13 01:17:42
【问题描述】:

我想创建一个新的输入来仅绘制多头止损。

atr SL 脚本:

// Stop Loss inputs atr     
var atr_sl = "ATR Stoploss"    
longLossPerc = input(title="Long Stop Loss (%)",type=input.float, group = atr_sl,minval=0.0, step=0.1, defval=1) * 0.01    
atrLength = input(title="ATR Length", type=input.integer, group = atr_sl,defval=6, minval=1)    
userStructure = input(title="Use Structure", type=input.bool, group = atr_sl, defval=true)    
lookback = input(title="How far to look back for High/Low",type=input.integer,group = atr_sl,defval=7, minval=1)    
atrStopMultiplier = input(title="ATR x ? ", type=input.float, group = atr_sl,defval=1.0, minval=0.1)    
plotLong = input(title="Long ATR", type=input.bool, group= atr_sl, defval=false)

// calculate data atr    
longStopPrice = strategy.position_avg_price * (1 - longLossPerc)    
atr=atr(atrLength)    
longStop = (userStructure ? lowest(low, lookback) : close) - atr * atrStopMultiplier    
shortStop = (userStructure ? highest(high,lookback) : close) + atr * atrStopMultiplier

我应该使用if (plotLong == true) 参数来绘制这个脚本吗?如果是怎么办?

// plot
plot(longStop, color=color.green, style=plot.style_linebr, title="Long Trailing Stop-ATR")

【问题讨论】:

    标签: pine-script algorithmic-trading trading pine-script-v4


    【解决方案1】:

    你不能在 if 块中绘图。您可以做的是,创建一个输入以启用/禁用绘图。

    plotAtrSL = input(title="On/Off", type=input.bool, defval=true)
    

    然后使用plot()中的这个变量作为条件。

    plot(plotAtrSL ? longStop : na)
    

    如果是false,由于`na,它不会绘制任何东西。

    【讨论】:

    • 成功了!谢谢。
    猜你喜欢
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2022-12-09
    相关资源
    最近更新 更多