我想在策略放置/检测到一个条目时添加 ATR 止损。到目前为止,我想出了这个脚本:
@version=4
// Stop Loss inputs atr
longLossPerc = input(title="Long Stop Loss (%)",type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
atrLength = input(title="ATR Length", type=input.integer, defval=6, minval=1)
userStructure = input(title="Use Structure", type=input.bool, defval=true)
lookback = input(title="How far to look back for High/Low",type=input.integer, defval=7, minval=1)
atrStopMultiplier = input(title="ATR x ? ", type=input.float, defval=1.0, minval=0.1)
longStopPrice = strategy.position_avg_price * (1 - longLossPerc)
// calculate data atr
atr=atr(atrLength)
longStop = (userStructure ? lowest(low, lookback) : close) - atr * atrStopMultiplier
shortStop = (userStructure ? highest(high,lookback) : close) + atr * atrStopMultiplier
// plot atr Long/Short
plot(longStop, color=color.green, style=plot.style_linebr, title="Long Trailing Stop-ATR")
plot(shortStop, color=color.red, style=plot.style_linebr, title="Short Trailing Stop-ATR")
我的问题是,我不知道如何将此脚本关联/连接到我的脚本参数。我是否必须创建一个新变量,然后将其插入到我的 strategy.close 中?
strategy.entry("LongA", strategy.long,1, when= x and y)
strategy.close("LongA", when= z or t )
注意:x,y,z,t 是预定义变量。