Pinescript – 如何让条件仅在首次满足时执行?

huangapple go评论57阅读模式
英文:

Pinescript - How would I go about having a condition execute the first time it's met only?

问题

如果可能的话,我想只更新directionPoints变量一次(在条件首次为真时)。任何帮助都将不胜感激。

我尝试过使用另一个变量,根据它是否已执行来设置为true/false,但它仍然会多次更新该变量。

英文:

How would I go about having a condition execute the first time it's met only? An example of what I want to achieve is as follows (this is just a snippit of my code):

if (RSILong)
	directionPoints := directionPoints + 1
if (RSIShort)
	directionPoints := directionPoints - 1

If it's possible, I'd like to be able to only update the directionPoints variable once (the first time the condition is true). Any help is appretiated.

I tried to have another variable what would be set to true/false depending on if it had already executed but it still was updating the variable more than once.

答案1

得分: 1

不确定您是希望仅在前一根柱上的条件不为真时才进行计数,还是希望仅在出现RSI短信号之前对RSI多信号进行一次计数。

您可以通过以下方式使其仅在前一根柱上的条件不为真时才进行计数。

if rsilong and not rsilong[1]
    directionPoints := directionPoints + 1
if rsishort and not rsishort[1]
    directionPoints := directionPoints - 1
英文:

Not sure if you are looking for it to only count if the condition wasn't true on the bar before or if you want it to only count RSI long once until there is an RSI short signal.

You can make it so it only counts if the condition wasn't true on the bar before by doing something like this.

if rsilong and not rsilong[1]
    directionPoints := directionPoints + 1
if rsishort and not rsishort[1]
    directionPoints := directionPoints - 1

huangapple
  • 本文由 发表于 2023年2月27日 11:59:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定