簡體   English   中英

需要幫助將 PineScript a v2 轉換為 v4。 我的知識有限,因此不勝感激

[英]Need assistance converting PineScript a v2 to v4. My knowledge is limited coming into this so any help is appreciated

我已經有這個腳本有一段時間了,我想把它轉換成 v4,但我很難用它。 我知道有一個轉換按鈕,但這僅適用於 v3+。 腳本一點也不長,如果有人能幫助我,我真的很感激,或者指出我的方向,因為我對 pinescript 的了解非常薄。 感謝大家

//@version=2
study("ADX")
len = input(title="Length", type=integer, defval=3)
len1 = input(title="Length1", type=integer, defval=1)
th = input(title="threshold", type=integer, defval=20)

TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0

SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)

crosscall = (DIPlus > DIMinus)
crossput = (DIMinus > DIPlus)
DIPcross = sma(crosscall, len1)
DIPput = sma(crossput, len1)
DIPOVB = (DIPlus > 60)
DIMOVS = (DIMinus > 60)

bgcolor(DIMOVS ? lime : na, transp=40)
bgcolor(DIPOVB ? orange : na, transp=20)
plot(DIPlus, color=green, linewidth=3, title="DI+")
plot(DIMinus, color=red, linewidth=3, title="DI-")
plot(ADX, color=white, linewidth=1, title="ADX")
hline(th, color=white, linewidth=1, linestyle=dashed)
bgcolor(DIPcross ? green : na, transp=60)
bgcolor(DIPput ? red : na, transp=60)

讓我們 go 到 V5。

//@version=5
indicator('ADX')
len = input(title='Length', defval=3)
len1 = input(title='Length1', defval=1)
th = input(title='threshold', defval=20)

TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0

SmoothedTrueRange = 0.0
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementMinus = 0.0

SmoothedTrueRange := nz(SmoothedTrueRange[1]) - nz(SmoothedTrueRange[1]) / len + TrueRange
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - nz(SmoothedDirectionalMovementPlus[1]) / len + DirectionalMovementPlus
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - nz(SmoothedDirectionalMovementMinus[1]) / len + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
ADX = ta.sma(DX, len)

crosscall = DIPlus > DIMinus
crossput = DIMinus > DIPlus
DIPcross = ta.sma(crosscall ? 1 : 0, len1)
DIPput = ta.sma(crossput ? 1 : 0, len1)
DIPOVB = DIPlus > 60
DIMOVS = DIMinus > 60

bgcolor(DIMOVS ? color.lime : na, transp=40)
bgcolor(DIPOVB ? color.orange : na, transp=20)
plot(DIPlus, color=color.new(color.green, 0), linewidth=3, title='DI+')
plot(DIMinus, color=color.new(color.red, 0), linewidth=3, title='DI-')
plot(ADX, color=color.new(color.white, 0), linewidth=1, title='ADX')
hline(th, color=color.white, linewidth=1, linestyle=hline.style_dashed)
bgcolor(DIPcross ? color.green : na, transp=60)
bgcolor(DIPput ? color.red : na, transp=60)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM