如何检测过去 'n' 根蜡烛是否满足特定要求?

How to detect if in ANY candle in the past 'n' candles meet a certain requirement?

我想检查过去是否有任何蜡烛 'n' 蜡烛满足特定条件。

例如让我们检查一下最近 20 根蜡烛的收盘价是否高于 'x':

x = 2
n = 20
condition = [ANY of n] > x

参见barssince() and an example showing how to use it here

您还可以使用以下方法计算最后 n 根柱中条件出现的次数:

sum(cond ? 1 : 0, len)

Disclosure: the link in this answer points to a PineCoders FAQ entry.
I am a member of the PineCoders community and I most probably wrote that FAQ entry. PineCoders is a TradingView-supported group of volunteer Pine coders and PineCoders' website is strictly educational. Neither TradingView nor PineCoders benefits financially from sending traffic to pinecoders.com, and the site contains no affiliate/referral links.