Pine脚本绘图到浮点类型转换

huangapple go评论72阅读模式
英文:

Pine script Plot to float type casting

问题

Here's the translated code without the comments and with the necessary changes for 'vwma_topline' and 'vwma_bottomline' to be of float type:

vwma_ohlc = ta.vwma(ohlc4, 7)
plot(vwma_ohlc, title="VWMA Mid Line", color=color.silver, linewidth=2)
vwma_topline = vwma_ohlc + ta.sma(close, 5)
vwma_bottomline = vwma_ohlc - ta.sma(close, 5)

vwma_topline_val = ta.valuewhen(bar_index, vwma_topline, 0)
vwma_bottomline_val = ta.valuewhen(bar_index, vwma_bottomline, 0)

if (vwma_topline_val > vwma_ohlc and vwma_bottomline_val < vwma_ohlc)
    [0]

I have removed the 'plot' function for 'vwma_topline' and 'vwma_bottomline' and replaced them with calculations to obtain float values.

英文:
//Volume Weighted Moving Avarage
vwma_ohlc= ta.vwma(ohlc4,7)
vwma_midline =  plot(vwma_ohlc, title = &quot;VWMA Mid Line&quot;, color = color.silver, linewidth = 2)
vwma_topline = plot(vwma_ohlc, title = &quot;VWMA Top Line&quot;,color= color.green,offset=-5,linewidth = 1)
vwma_bottomline = plot(vwma_ohlc, title = &quot;VWMA Bottom Line&quot;, color = color.red, offset=5,linewidth = 1)

if (ta.crossover(vwma_topline, vwma_midline) and ta.crossover(vwma_midline, vwma_bottomline))

I have this code and need a float type for 'vwma_topline' and 'vwma_bottomline' instead of plot type and still need to be able to plot these lines.

basically 'vwma_topline' and 'vwma_bottomline' are the same as 'vwma_midline' but has an offset of -5 and 5 bars respectively. I need a way to calculate a float value for these. can somebody help

vwma_ohlc= ta.vwma(ohlc4,7)
plot(vwma_ohlc, title = &quot;VWMA Mid Line&quot;, color = color.silver, linewidth = 2)
vwma_topline = plot(vwma_ohlc, title = &quot;VWMA Top Line&quot;,color= color.green,offset=-5,linewidth = 1)
vwma_bottomline = plot(vwma_ohlc, title = &quot;VWMA Bottom Line&quot;, color = color.red, offset=5,linewidth = 1)

vwma_topline_val = ta.valuewhen(bar_index, vwma_topline, 0)
vwma_bottomline_val = ta.valuewhen(bar_index, vwma_bottomline, 0)

if(vwma_topline_val &gt; vwma_ohlc and vwma_bottomline_val &lt; vwma_ohlc)
    [0]

I have already tried this to get value but it gives me the same errors on lines 6 and 7 and basically tells me that I have entered plot type instead of series float for 'vwma_topline' and 'vwma_bottomline'.

答案1

得分: 0

"Hope this helps (please see the comments in the script).

//@version=5 indicator(&quot;My script&quot;, overlay = true) //Volume Weighted Moving Average vwma_ohlc = ta.vwma(ohlc4, 7) vwma_midline = plot(vwma_ohlc, title = &quot;VWMA Mid Line&quot;, color = color.silver, linewidth = 3) vwma_topline = plot(vwma_ohlc, title = &quot;VWMA Top Line&quot;, color = color.green, offset = -5, linewidth = 1) // vwma_bottomline = plot(vwma_ohlc, title = &quot;VWMA Bottom Line&quot;, color = color.red, offset = 5, linewidth = 1) vwma_ohlc_bot = vwma_ohlc[5] vwma_bottomline2 = plot(vwma_ohlc, title = &quot;VWMA Bottom Line&quot;, color = color.red, offset = 5, linewidth = 1) cross_bottom = ta.cross(vwma_ohlc, vwma_ohlc_bot) plotshape(cross_bottom, &quot;Cross Bottom&quot;, style = shape.xcross, color = color.red) // the value of vwma_topline for the current bar will only be available five bars ahead, so we cannot have the value now but the cross of mid and top lines is always 5 bars behind the cross of the bottom and mid lines plotshape(cross_bottom, &quot;Cross Top&quot;, style = shape.xcross, color = color.green, offset = -5 ) // if (ta.crossover(vwma_topline, vwma_midline) and ta.crossover(vwma_midline, vwma_bottomline)) //plot(close)"

英文:

Hope this helps (please see the comments in the script).

//@version=5
indicator(&quot;My script&quot;, overlay = true)



//Volume Weighted Moving Avarage
vwma_ohlc= ta.vwma(ohlc4,7)
vwma_midline =  plot(vwma_ohlc, title = &quot;VWMA Mid Line&quot;, color = color.silver, linewidth = 3)
vwma_topline = plot(vwma_ohlc, title = &quot;VWMA Top Line&quot;,color= color.green,offset=-5,linewidth = 1)
// vwma_bottomline = plot(vwma_ohlc, title = &quot;VWMA Bottom Line&quot;, color = color.red, offset=5,linewidth = 1)

vwma_ohlc_bot = vwma_ohlc[5]
vwma_bottomline2 = plot(vwma_ohlc, title = &quot;VWMA Bottom Line&quot;, color = color.red, offset=5,linewidth = 1)
cross_bottom = ta.cross(vwma_ohlc, vwma_ohlc_bot)
plotshape(cross_bottom, &quot;Cross Bottom&quot;, style = shape.xcross, color = color.red )


// the value of vwma_topline for the current bar will only be available five bars ahead, so we cannot have the value now
// but the cross of mid and top lines is always 5 bars behind the cross of the bottom and mid lines
plotshape(cross_bottom, &quot;Cross Top&quot;, style = shape.xcross, color = color.green, offset = -5 )


// if (ta.crossover(vwma_topline, vwma_midline) and ta.crossover(vwma_midline, vwma_bottomline))
//plot(close)

huangapple
  • 本文由 发表于 2023年4月11日 05:11:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定