我正在尝试在tradingview上自动绘制目标,就像这张图片
但是我失败了,TP会重复出现几次。
有人可以帮助我吗?
plotshape( (close>TP1_value) , title="TP1_Reached", style=shape.arrowup, location=location.belowbar, color=green, transp=0, text="TP1_Reached", textcolor=green, size=size.large)
答案 0 :(得分:1)
您的问题是,close>TP1_value
对多个小节都是正确的。如果只想绘制一次,则可以使用一个变量。
//@version=4
study("My Script", overlay=true)
TP1_value = input(title="Take Profit Price", defval=10000)
var isTP1reached = false // Use this variable to see if TP1 hass already been reached
takeProfit1 = not isTP1reached and (close > TP1_value) // If not already reached TP1 and TP condition is true
if (takeProfit1)
isTP1reached := true
plotshape(series=takeProfit1, title="Take Profit 1", text="Take Profit 1", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
从上图可以看到,它仅绘制一次。当然,您需要根据需要重置变量,以便再次使用它。