简体   繁体   中英

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

I have had this script for some time now, and I wanted to convert it to v4 but having a really hard time with it. I know there is a convert button but that's only for v3+. the script isn't long at all, and if anyone can assist me with this, I truly would appreciate it, or point me in the direction as my knowledge is really thin when it comes to pinescript. Thanks everyone

//@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)

Let's go to 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM