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

人盡茶涼 提交于 2021-01-29 20:01:36

问题


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

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

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

回答1:


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.



来源:https://stackoverflow.com/questions/65621050/how-to-detect-if-in-any-candle-in-the-past-n-candles-meet-a-certain-requiremen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!