简体   繁体   中英

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

I'd like to check if ANY candle in the past 'n' candles meet a certain condition.

Eg let's check if any close in the latest 20 candles was higher than 'x':

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

See barssince() and an example showing how to use it here .

You can also count the number of occurrences of a condition in the last n bars using:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM