Pinescript情节问题

发布于 2025-01-31 14:44:09 字数 496 浏览 1 评论 0原文

当我的职位“ pos”为= -1(卖出)或位置为= 1(买)时,我需要编辑代码以绘制买入/出售信号位置从红色更改为绿色,反之亦然,请注意:我的pinescript版本是v1,

color = pos == -1 ? red: pos == 1 ? green : blue 

plotshape(color , title="Buy", style=shape.labelup, location=location.belowbar, size=size.normal, text="Buy", transp=0, textcolor = white, color=green, transp=0)
plotshape(color , title="Sell", style=shape.labeldown, location=location.abovebar, size=size.normal, text="Sell", transp=0, textcolor = white, color=red, transp=0)

I need to edit my code to plot a buy/sell signal when my position "pos" is =-1 (sell) or the position is = 1 (buy) but the problem is plotting several times I need to plot only every time the position is changed from red to green or vise versa, Note: My Pinescript version is v1,

color = pos == -1 ? red: pos == 1 ? green : blue 

plotshape(color , title="Buy", style=shape.labelup, location=location.belowbar, size=size.normal, text="Buy", transp=0, textcolor = white, color=green, transp=0)
plotshape(color , title="Sell", style=shape.labeldown, location=location.abovebar, size=size.normal, text="Sell", transp=0, textcolor = white, color=red, transp=0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情定在深秋 2025-02-07 14:44:09

首先,找出位置是否在当前栏上更改。

is_new_sell = (pos[1] == 1) and (pos == -1) // pos was buy one bar ago and it is sell now
is_new_buy = (pos[1] == -1) and (pos == 1) // pos was sell one bar ago and it is buy now

然后使用这些变量来绘制形状。

plotshape(is_new_buy, title="Buy", style=shape.labelup, location=location.belowbar, size=size.normal, text="Buy", transp=0, textcolor = white, color=green, transp=0)
plotshape(is_new_sell, title="Sell", style=shape.labeldown, location=location.abovebar, size=size.normal, text="Sell", transp=0, textcolor = white, color=red, transp=0)

First, find out if the position changed on the current bar.

is_new_sell = (pos[1] == 1) and (pos == -1) // pos was buy one bar ago and it is sell now
is_new_buy = (pos[1] == -1) and (pos == 1) // pos was sell one bar ago and it is buy now

Then use these variables to plot your shape.

plotshape(is_new_buy, title="Buy", style=shape.labelup, location=location.belowbar, size=size.normal, text="Buy", transp=0, textcolor = white, color=green, transp=0)
plotshape(is_new_sell, title="Sell", style=shape.labeldown, location=location.abovebar, size=size.normal, text="Sell", transp=0, textcolor = white, color=red, transp=0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文