英文:
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 = "VWMA Mid Line", color = color.silver, linewidth = 2)
vwma_topline = plot(vwma_ohlc, title = "VWMA Top Line",color= color.green,offset=-5,linewidth = 1)
vwma_bottomline = plot(vwma_ohlc, title = "VWMA Bottom Line", 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 = "VWMA Mid Line", color = color.silver, linewidth = 2)
vwma_topline = plot(vwma_ohlc, title = "VWMA Top Line",color= color.green,offset=-5,linewidth = 1)
vwma_bottomline = plot(vwma_ohlc, title = "VWMA Bottom Line", 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 > vwma_ohlc and vwma_bottomline_val < 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("My script", overlay = true) //Volume Weighted Moving Average vwma_ohlc = ta.vwma(ohlc4, 7) vwma_midline = plot(vwma_ohlc, title = "VWMA Mid Line", color = color.silver, linewidth = 3) vwma_topline = plot(vwma_ohlc, title = "VWMA Top Line", color = color.green, offset = -5, linewidth = 1) // vwma_bottomline = plot(vwma_ohlc, title = "VWMA Bottom Line", color = color.red, offset = 5, linewidth = 1) vwma_ohlc_bot = vwma_ohlc[5] vwma_bottomline2 = plot(vwma_ohlc, title = "VWMA Bottom Line", color = color.red, offset = 5, linewidth = 1) cross_bottom = ta.cross(vwma_ohlc, vwma_ohlc_bot) plotshape(cross_bottom, "Cross Bottom", 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, "Cross Top", 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("My script", overlay = true)
//Volume Weighted Moving Avarage
vwma_ohlc= ta.vwma(ohlc4,7)
vwma_midline = plot(vwma_ohlc, title = "VWMA Mid Line", color = color.silver, linewidth = 3)
vwma_topline = plot(vwma_ohlc, title = "VWMA Top Line",color= color.green,offset=-5,linewidth = 1)
// vwma_bottomline = plot(vwma_ohlc, title = "VWMA Bottom Line", color = color.red, offset=5,linewidth = 1)
vwma_ohlc_bot = vwma_ohlc[5]
vwma_bottomline2 = plot(vwma_ohlc, title = "VWMA Bottom Line", color = color.red, offset=5,linewidth = 1)
cross_bottom = ta.cross(vwma_ohlc, vwma_ohlc_bot)
plotshape(cross_bottom, "Cross Bottom", 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, "Cross Top", style = shape.xcross, color = color.green, offset = -5 )
// if (ta.crossover(vwma_topline, vwma_midline) and ta.crossover(vwma_midline, vwma_bottomline))
//plot(close)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论