Ini adalah kode asli untuk versi 2 tetapi setelah konversi hasilnya sama sekali berbeda dari versi 2. apakah ada kesalahan yang saya buat ketika melakukan konversi ke versi 3

Saya terjebak di sini selama berhari-hari saya ingin garisnya lurus tetapi, itu tidak lurus seperti yang ditunjukkan pada gambar di bawah garis itu terus berubah di pasar langsung

//@version=2
study("Auto Pivots with S/R",overlay = true)

// Inputs
pivotType = input(defval=false, title="Check for Fib Pivots, standard by default", type=bool) // Option for Fib or Standard
pivotExtend = input(defval = false, title = "Extend pivots through chart?", type = bool)
pivotAuto = input(defval = true, title = "Only show most recent pivot set?", type = bool)

// Calculate start point
currentTimePrimary = ismonthly ? year(timenow) : isweekly ? month(timenow) : isdaily ? weekofyear(timenow) : isintraday ? dayofweek(timenow) == saturday or dayofweek(timenow) == sunday ? friday : dayofweek(timenow) : na
currentTimeSecondary = ismonthly ? year(timenow) : isweekly ? year(timenow) : isdaily ? year(timenow) : isintraday ? weekofyear(timenow): na
currentBarTimePrimary = ismonthly ? year(time) : isweekly ? month(time) : isdaily ? weekofyear(time) : isintraday ? dayofweek(time) : na
currentBarTimeSecondary = ismonthly ? year(time) : isweekly ? year(time) : isdaily ? year(time) : isintraday ? weekofyear(time) : na
pivotTimeFrame = '1W'

// Pull traditional HLC candle values
pHigh = security(tickerid, pivotTimeFrame, high)
pLow = security(tickerid, pivotTimeFrame, low)
pClose = security(tickerid, pivotTimeFrame, close)

// Calculate pivot points
pp  = (pHigh + pLow + pClose ) / 3.0

// First level
r1 = pivotType ? pp + ((pHigh-pLow) * 0.382) : (2 * pp) - pLow
s1 = pivotType ? pp - ((pHigh-pLow) * 0.382) : (2 * pp) - pHigh

// Second level
r2 = pivotType ? pp + ((pHigh-pLow) * 0.618) : pp + (pHigh - pLow)
s2 = pivotType ? pp - ((pHigh-pLow) * 0.618) : pp - (pHigh - pLow)

// Third level
r3 = pivotType ? pp + ((pHigh-pLow) * 1.000) : pHigh + (2 * (pp - pLow))
s3 = pivotType ? pp - ((pHigh-pLow) * 1.000) : pLow - (2 * (pHigh - pp))

// Calculate pivot plots
pivot = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, pp[1]) : na : security(tickerid, pivotTimeFrame, pp[1])
pivot_r1 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, r1[1]) : na : security(tickerid, pivotTimeFrame, r1[1])
pivot_s1 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, s1[1]) : na : security(tickerid, pivotTimeFrame, s1[1])
pivot_r2 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, r2[1]) : na : security(tickerid, pivotTimeFrame, r2[1])
pivot_s2 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, s2[1]) : na : security(tickerid, pivotTimeFrame, s2[1])
pivot_r3 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, r3[1]) : na : security(tickerid, pivotTimeFrame, r3[1])
pivot_s3 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(tickerid, pivotTimeFrame, s3[1]) : na : security(tickerid, pivotTimeFrame, s3[1])

// Plot pivots
plot(pivot and pivot > 0 ? pivot : na, title="Pivot", style = linebr, color=fuchsia, linewidth=4, transp=0, trackprice = pivotExtend)
plot(pivot_r1 and pivot_r1 > 0 ? pivot_r1 : na, title="R1", style=linebr, color=white, linewidth=3, transp=15, trackprice = pivotExtend)
plot(pivot_r2 and pivot_r2 > 0 ? pivot_r2 : na, title="R2", style=linebr, color=white, linewidth=2, transp=30, trackprice = pivotExtend) 
plot(pivot_r3 and pivot_r3 > 0 ? pivot_r3 : na, title="R3", style=linebr, color=white, linewidth=1, transp=45, trackprice = pivotExtend)
plot(pivot_s1 and pivot_s1 > 0 ? pivot_s1 : na, title="S1", style=linebr, color=red, linewidth=3, transp=15, trackprice = pivotExtend)
plot(pivot_s2 and pivot_s2 > 0 ? pivot_s2 : na, title="S2", style=linebr, color=red, linewidth=2, transp=30, trackprice = pivotExtend) 
plot(pivot_s3 and pivot_s3 > 0 ? pivot_s3 : na, title="S3", style=linebr, color=red, linewidth=1, transp=45, trackprice = pivotExtend)

Setelah dikonversi

//@version=3
study("Auto Pivots with S/R v4",overlay = true)

// Inputs
pivotType = input(defval=false, title="Check for Fib Pivots, standard by default", type=input.bool) // Option for Fib or Standard
pivotExtend = input(defval = false, title = "Extend pivots through chart?", type = input.bool)
pivotAuto = input(defval = true, title = "Only show most recent pivot set?", type = input.bool)

currentTimePrimary =timeframe.ismonthly ? year(timenow) : timeframe.isweekly ? month(timenow) : timeframe.isdaily ? weekofyear(timenow) : timeframe.isintraday ? dayofweek(timenow) == dayofweek.saturday or dayofweek(timenow) == dayofweek.sunday ? dayofweek.friday : dayofweek(timenow) : na
currentTimeSecondary = timeframe.ismonthly ? year(timenow) : timeframe.isweekly ? year(timenow) : timeframe.isdaily ? year(timenow) : timeframe.isintraday ? weekofyear(timenow): na
currentBarTimePrimary = timeframe.ismonthly ? year(time) : timeframe.isweekly ? month(time) : timeframe.isdaily ? weekofyear(time) : timeframe.isintraday ? dayofweek(time) : na
currentBarTimeSecondary = timeframe.ismonthly ? year(time) : timeframe.isweekly ? year(time) : timeframe.isdaily ? year(time) : timeframe.isintraday ? weekofyear(time) : na
pivotTimeFrame = '1W'



// Pull traditional HLC candle values
pHigh = security(syminfo.tickerid, pivotTimeFrame, high)
pLow = security(syminfo.tickerid, pivotTimeFrame, low)
pClose = security(syminfo.tickerid, pivotTimeFrame, close)

// Calculate pivot points
pp  = (pHigh + pLow + pClose ) / 3.0

// First level
r1 = pivotType ? pp + ((pHigh-pLow) * 0.382) : (2 * pp) - pLow
s1 = pivotType ? pp - ((pHigh-pLow) * 0.382) : (2 * pp) - pHigh

// Second level
r2 = pivotType ? pp + ((pHigh-pLow) * 0.618) : pp + (pHigh - pLow)
s2 = pivotType ? pp - ((pHigh-pLow) * 0.618) : pp - (pHigh - pLow)

// Third level
r3 = pivotType ? pp + ((pHigh-pLow) * 1.000) : pHigh + (2 * (pp - pLow))
s3 = pivotType ? pp - ((pHigh-pLow) * 1.000) : pLow - (2 * (pHigh - pp))


// Calculate pivot plots
pivot = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, pp[1]) : na : security(syminfo.tickerid, pivotTimeFrame, pp[1])
pivot_r1 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, r1[1]) : na : security(syminfo.tickerid, pivotTimeFrame, r1[1])
pivot_r2 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, r2[1]) : na : security(syminfo.tickerid, pivotTimeFrame, r2[1])
pivot_r3 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, r3[1]) : na : security(syminfo.tickerid, pivotTimeFrame, r3[1])

pivot_s1 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, s1[1]) : na : security(syminfo.tickerid, pivotTimeFrame, s1[1])
pivot_s2 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, s2[1]) : na : security(syminfo.tickerid, pivotTimeFrame, s2[1])
pivot_s3 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and currentTimeSecondary == currentBarTimeSecondary ? security(syminfo.tickerid, pivotTimeFrame, s3[1]) : na : security(syminfo.tickerid, pivotTimeFrame, s3[1])

plot(pivot and pivot > 0 ? pivot : na, title="Pivot", style = plot.style_linebr, color=color.fuchsia, linewidth=4, transp=0, trackprice = pivotExtend)
plot(pivot_r1 and pivot_r1 > 0 ? pivot_r1 : na, title="R1", style=plot.style_linebr, color=color.white, linewidth=3, transp=15, trackprice = pivotExtend)
plot(pivot_r2 and pivot_r2 > 0 ? pivot_r2 : na, title="R2", style=plot.style_linebr, color=color.white, linewidth=2, transp=30, trackprice = pivotExtend) 
plot(pivot_r3 and pivot_r3 > 0 ? pivot_r3 : na, title="R3", style=plot.style_linebr, color=color.white, linewidth=1, transp=45, trackprice = pivotExtend)
plot(pivot_s1 and pivot_s1 > 0 ? pivot_s1 : na, title="S1", style=plot.style_linebr, color=color.red, linewidth=3, transp=15, trackprice = pivotExtend)
plot(pivot_s2 and pivot_s2 > 0 ? pivot_s2 : na, title="S2", style=plot.style_linebr, color=color.red, linewidth=2, transp=30, trackprice = pivotExtend) 
plot(pivot_s3 and pivot_s3 > 0 ? pivot_s3 : na, title="S3", style=plot.style_linebr, color=color.red, linewidth=1, transp=45, trackprice = pivotExtend) 

gambar

0
oliver meshram 15 Mei 2021, 10:30

1 menjawab

Jawaban Terbaik

Mengapa mengkonversi ke 3 bukannya 4?

Saya mencoba mengonversi ke 4, saya tidak tahu apakah perilaku berfungsi seperti yang diharapkan. btw, skrip yang menarik

//@version=4
study("Auto Pivots with S/R", overlay=true)

// Inputs
pivotType = input(defval=false, title="Check for Fib Pivots, standard by default", type=input.bool)  // Option for Fib or Standard
pivotExtend = input(defval=false, title="Extend pivots through chart?", type=input.bool)
pivotAuto = input(defval=true, title="Only show most recent pivot set?", type=input.bool)

// Calculate start point
currentTimePrimary = timeframe.ismonthly ? year(timenow) : 
   timeframe.isweekly ? month(timenow) : timeframe.isdaily ? weekofyear(timenow) : 
   timeframe.isintraday ? dayofweek(timenow) == dayofweek.saturday or 
   dayofweek(timenow) == dayofweek.sunday ? dayofweek.friday : dayofweek(timenow) : 
   na
currentTimeSecondary = timeframe.ismonthly ? year(timenow) : 
   timeframe.isweekly ? year(timenow) : timeframe.isdaily ? year(timenow) : 
   timeframe.isintraday ? weekofyear(timenow) : na
currentBarTimePrimary = timeframe.ismonthly ? year(time) : 
   timeframe.isweekly ? month(time) : timeframe.isdaily ? weekofyear(time) : 
   timeframe.isintraday ? dayofweek(time) : na
currentBarTimeSecondary = timeframe.ismonthly ? year(time) : timeframe.isweekly ? year(time) : 
   timeframe.isdaily ? year(time) : timeframe.isintraday ? weekofyear(time) : na
pivotTimeFrame = '1W'

// Pull traditional HLC candle values
pHigh = security(syminfo.tickerid, pivotTimeFrame, high)
pLow = security(syminfo.tickerid, pivotTimeFrame, low)
pClose = security(syminfo.tickerid, pivotTimeFrame, close)

// Calculate pivot points
pp = (pHigh + pLow + pClose) / 3.0

// First level
r1 = pivotType ? pp + (pHigh - pLow) * 0.382 : 2 * pp - pLow
s1 = pivotType ? pp - (pHigh - pLow) * 0.382 : 2 * pp - pHigh

// Second level
r2 = pivotType ? pp + (pHigh - pLow) * 0.618 : pp + pHigh - pLow
s2 = pivotType ? pp - (pHigh - pLow) * 0.618 : pp - (pHigh - pLow)

// Third level
r3 = pivotType ? pp + (pHigh - pLow) * 1.000 : pHigh + 2 * (pp - pLow)
s3 = pivotType ? pp - (pHigh - pLow) * 1.000 : pLow - 2 * (pHigh - pp)

// Calculate pivot plots
security_1 = security(syminfo.tickerid, pivotTimeFrame, pp[1])
security_2 = security(syminfo.tickerid, pivotTimeFrame, pp[1])
pivot = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_1 : na : security_2
security_3 = security(syminfo.tickerid, pivotTimeFrame, r1[1])
security_4 = security(syminfo.tickerid, pivotTimeFrame, r1[1])
pivot_r1 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_3 : na : security_4
security_5 = security(syminfo.tickerid, pivotTimeFrame, s1[1])
security_6 = security(syminfo.tickerid, pivotTimeFrame, s1[1])
pivot_s1 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_5 : na : security_6
security_7 = security(syminfo.tickerid, pivotTimeFrame, r2[1])
security_8 = security(syminfo.tickerid, pivotTimeFrame, r2[1])
pivot_r2 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_7 : na : security_8
security_9 = security(syminfo.tickerid, pivotTimeFrame, s2[1])
security_10 = security(syminfo.tickerid, pivotTimeFrame, s2[1])
pivot_s2 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_9 : na : security_10
security_11 = security(syminfo.tickerid, pivotTimeFrame, r3[1])
security_12 = security(syminfo.tickerid, pivotTimeFrame, r3[1])
pivot_r3 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_11 : na : security_12
security_13 = security(syminfo.tickerid, pivotTimeFrame, s3[1])
security_14 = security(syminfo.tickerid, pivotTimeFrame, s3[1])
pivot_s3 = pivotAuto == true ? currentTimePrimary == currentBarTimePrimary and 
   currentTimeSecondary == currentBarTimeSecondary ? security_13 : na : security_14

// Plot pivots
plot(pivot and pivot > 0 ? pivot : na, title="Pivot", style=plot.style_linebr, color=color.fuchsia, linewidth=4, transp=0, trackprice=pivotExtend)
plot(pivot_r1 and pivot_r1 > 0 ? pivot_r1 : na, title="R1", style=plot.style_linebr, color=color.white, linewidth=3, transp=15, trackprice=pivotExtend)
plot(pivot_r2 and pivot_r2 > 0 ? pivot_r2 : na, title="R2", style=plot.style_linebr, color=color.white, linewidth=2, transp=30, trackprice=pivotExtend)
plot(pivot_r3 and pivot_r3 > 0 ? pivot_r3 : na, title="R3", style=plot.style_linebr, color=color.white, linewidth=1, transp=45, trackprice=pivotExtend)
plot(pivot_s1 and pivot_s1 > 0 ? pivot_s1 : na, title="S1", style=plot.style_linebr, color=color.red, linewidth=3, transp=15, trackprice=pivotExtend)
plot(pivot_s2 and pivot_s2 > 0 ? pivot_s2 : na, title="S2", style=plot.style_linebr, color=color.red, linewidth=2, transp=30, trackprice=pivotExtend)
plot(pivot_s3 and pivot_s3 > 0 ? pivot_s3 : na, title="S3", style=plot.style_linebr, color=color.red, linewidth=1, transp=45, trackprice=pivotExtend)
0
Walter Tosolini 15 Mei 2021, 14:40