如何定义一个特定范围为"sum(x, len)"的长度?
How to define a specific range as the length of "sum(x, len)"?
我想检查在回溯期的前半段是否至少满足一次特定条件,然后在回溯期的后半段至少再次满足一次。
我正在尝试使用下面的代码来做到这一点,如 。但是我没有弄清楚如何使 len
成为一个范围。
所以我的问题是:如何使 len
成为一个范围? (低于 len
为 lenFirstHalf
和 lenSecondHalf
)。
非常感谢任何帮助!
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
condition = close > open
lenFirstHalf = (<GREATER THAN> (lookBack/2)) and (<LESS THAN OR EQUAL TO> lookback)
lenSecondHalf = (<GREATER THAN OR EQUAL TO> 1) and (<LESS THAN OR EQUAL TO (lookback/2))
// Check if the condition is met in the FIRST half of the lookback period
triggerA = (sum(condition ? 1 : 0, lenFirstHalf)) >= 1 ? true : false
// Check if the condition is met in the SECOND half of the lookback period
triggerB = (sum(condition ? 1 : 0, lenSecondHalf)) >= 1 ? true : false
显然,那些<GREATER THAN>
和<LESS THAN OR EQUAL TO>
不存在,但我不知道如何将这样的范围归因于一个变量。
我认为这样的事情应该可行。
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
condition = close > open
sumLookBack = sum(condition ? 1 : 0, lookBack)
sumSecondHalf = sum(condition ? 1 : 0, lookBack/2)
sumFirstHalf = sumLookBack - sumSecondHalf
// Check if the condition is met in the FIRST half of the lookback period
triggerA = sumFirstHalf >= 1 ? true : false
// Check if the condition is met in the SECOND half of the lookback period
triggerB = sumSecondHalf >= 1 ? true : false
您在 sum()
中使用的 length
用于计算从 length
柱回溯到最新柱的总和。
因此,首先计算整个长度,然后减去“后”一半,就得到“前”一半。
我想检查在回溯期的前半段是否至少满足一次特定条件,然后在回溯期的后半段至少再次满足一次。
我正在尝试使用下面的代码来做到这一点,如 len
成为一个范围。
所以我的问题是:如何使 len
成为一个范围? (低于 len
为 lenFirstHalf
和 lenSecondHalf
)。
非常感谢任何帮助!
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
condition = close > open
lenFirstHalf = (<GREATER THAN> (lookBack/2)) and (<LESS THAN OR EQUAL TO> lookback)
lenSecondHalf = (<GREATER THAN OR EQUAL TO> 1) and (<LESS THAN OR EQUAL TO (lookback/2))
// Check if the condition is met in the FIRST half of the lookback period
triggerA = (sum(condition ? 1 : 0, lenFirstHalf)) >= 1 ? true : false
// Check if the condition is met in the SECOND half of the lookback period
triggerB = (sum(condition ? 1 : 0, lenSecondHalf)) >= 1 ? true : false
显然,那些<GREATER THAN>
和<LESS THAN OR EQUAL TO>
不存在,但我不知道如何将这样的范围归因于一个变量。
我认为这样的事情应该可行。
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
condition = close > open
sumLookBack = sum(condition ? 1 : 0, lookBack)
sumSecondHalf = sum(condition ? 1 : 0, lookBack/2)
sumFirstHalf = sumLookBack - sumSecondHalf
// Check if the condition is met in the FIRST half of the lookback period
triggerA = sumFirstHalf >= 1 ? true : false
// Check if the condition is met in the SECOND half of the lookback period
triggerB = sumSecondHalf >= 1 ? true : false
您在 sum()
中使用的 length
用于计算从 length
柱回溯到最新柱的总和。
因此,首先计算整个长度,然后减去“后”一半,就得到“前”一半。