英文:
Create a boolean expression for current 9 bars PINESCRIPT
问题
我想为当前的9个柱子创建一个布尔表达式。
示例:
最近的9个柱子(close,close[1]...close[9])= 真
最近的10个柱子及以后的柱子(close[10]..close[n>10])= 假
我该如何操作?
Ta.barssince?
英文:
I want to create a boolean expression for the current 9 bars
Example
Last 9 bars ie (close, close[1]...close[9]) = true
Last 10 bars and on (close[10]..close[n>10]) = false
how do i go about doing this?
Ta.barssince??
答案1
得分: 0
你可以使用 math.sum()
来计算在给定的回溯期内条件出现的次数。
例如:
cond = close > close[1]
cond_sum = math.sum(cond ? 1 : 0, 9)
cond_sum
将告诉您在最近的 9 个周期内有多少个周期的收盘价高于前一个周期。
英文:
You can use math.sum()
to count the number of occurences of a condition in the given lookback period.
For instance:
cond = close > close[1]
cond_sum = math.sum(cond ? 1 : 0, 9)
cond_sum
will tell you how many bars closed higher than the previous bar within the last 9 bars.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论