英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论