pinescript变量不更改其值

发布于 2025-01-30 08:56:10 字数 403 浏览 2 评论 0原文

为了简单起见,我将提供另一个代码。

currentRSI = ta.rsi(close,14)
var tradeExists = 0
if (currentRSI > 50 and tradeExists == 0)
    tradeExists := 1
    alert("Long trade")

在我的情况下,如果Currentrsi超过50,则达到51,并且在时间范围的同一蜡烛中达到49.5,则tradeexists值将保留0,但警报已发送。我该如何解决该问题并关闭交易,是否想知道我可以做到这一点吗?

我想指定我还尝试使用varip tradeexists = 0,但是该变量仍然在蜡烛结束时回滚。

To make it simple, I'll give another piece of code.

currentRSI = ta.rsi(close,14)
var tradeExists = 0
if (currentRSI > 50 and tradeExists == 0)
    tradeExists := 1
    alert("Long trade")

In my case, if currentRSI crosses over 50, so it gets to 51, AND in the same candle of the timeframe it gets to 49.5, the tradeExists value will remain 0 but the alert has been sent. How could I fix to detect that and close the trade, any idea if I can do this?

I want to specify that I also tried using varip tradeExists = 0 but the variable still gets rollback at the close of the candle.

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

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

发布评论

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

评论(1

您的好友蓝忘机已上羡 2025-02-06 08:56:10

我只是遇到了这个问题,我解决了:使用
barstate.isconfirded在您的条件下,这是更改Pinescript中VAR的唯一方法。

if (barstate.isconfirmed and first_time_signal == false)
    if nT3Average >= ok_to_buy and nT3Average_2 <= oversold 
        last_signal := 1
        label.new(bar_index,close,'Long',color=color.rgb(49, 161, 64),style = label.style_label_up,xloc=xloc.bar_index,yloc=yloc.belowbar)
        first_time_signal := true

    if nT3Average <= ok_to_sell and nT3Average_2 >= overbought 
        last_signal := -1
        label.new(bar_index,close,'Short',color=color.rgb(175, 55, 95),style = label.style_label_down,xloc=xloc.bar_index,yloc=yloc.abovebar,textcolor=color.rgb(10,10,10))
        first_time_signal := true 

I just had that problem and I fixed it: use
the barstate.isconfirmed in your conditions, it's the only way to change a var in pinescript.

if (barstate.isconfirmed and first_time_signal == false)
    if nT3Average >= ok_to_buy and nT3Average_2 <= oversold 
        last_signal := 1
        label.new(bar_index,close,'Long',color=color.rgb(49, 161, 64),style = label.style_label_up,xloc=xloc.bar_index,yloc=yloc.belowbar)
        first_time_signal := true

    if nT3Average <= ok_to_sell and nT3Average_2 >= overbought 
        last_signal := -1
        label.new(bar_index,close,'Short',color=color.rgb(175, 55, 95),style = label.style_label_down,xloc=xloc.bar_index,yloc=yloc.abovebar,textcolor=color.rgb(10,10,10))
        first_time_signal := true 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文