我正在浏览 ATR 追踪止损指标的 pinescript 代码,并试图用 Python 对其进行编码。我在理解以下几行时遇到困难。
Prev = H,barssince(close>H and close>close[1])
TS = iff(cum(1)<16,close,iff( close > H and close>close[1],H,Prev))
值 H 为您提供最高值 (highest(high-Mult*atr(Atr),Hhv))。在下一行,barsince 函数在满足条件时给出柱/蜡烛的计数。
完整的陈述 H,barssince 意味着什么?我的意思是什么值将存储在 Prev 中。
还有什么 cum(1) 函数呢?
//@version=4
study("ATR Trailing Stoploss",overlay=true)
Atr = 3 // input(defval=5,title="Atr Period",minval=1,maxval=500)
Hhv= 10 // input(defval=10,title="HHV Period",minval=1,maxval=500)
Mult= 2.5 // input(defval=2.5,title="Multiplier",minval=0.1)
Barcolor=input(true,title="Barcolor")
H = highest(high-Mult*atr(Atr),Hhv)
Prev = H,barssince(close>H and close>close[1])
TS = iff(cum(1)<16,close,iff( close > H and close>close[1],H,Prev))
Color=iff(close>TS,color.green,iff(close<TS,color.red,color.black))
barcolor(Barcolor? Color:na)
plot(TS,color=Color,linewidth=3,title="ATR Trailing Stoploss")
Buy=crossover(close,TS)
Sell=crossunder(close,TS)
plotshape(Buy,"BUY", shape.labelup, location.belowbar, color.green,
text="BUY",textcolor=color.black)
plotshape(Sell,"SELL", shape.labeldown, location.abovebar, color.red,
text="SELL",textcolor=color.black)
alertcondition(Buy, "Buy Signal", "Buy ATR Trailing Stoploss")
alertcondition(Sell, "Sell Signal", "Sell ATR Trailing Stoploss")