【问题标题】:Pinescript variable doesn't change its valuePinescript 变量不会改变它的值
【发布时间】:2022-11-27 07:00:10
【问题描述】:

所以我有一个问题,想了很多但无法解决,所以我很感激你的帮助。

为了简单起见,我再给出一段代码。

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,但变量仍然在蜡烛结束时回滚。

【问题讨论】:

    标签: pinescript-v5


    【解决方案1】:

    我刚遇到那个问题,我解决了它:使用 barstate.isconfirmed 在你的条件下,这是在 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 
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加更多详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写出好的答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 2023-03-21
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多