pinescript变量不更改其值
为了简单起见,我将提供另一个代码。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是遇到了这个问题,我解决了:使用
barstate.isconfirded
在您的条件下,这是更改Pinescript中VAR的唯一方法。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.