'How to count number of bars between 2 candles that meet distinct conditions respectively in pine-script
Given 2 true false conditions A and B I would like to search for the low of all the candles between these 2 conditions. the script load, but an error say "invalid value of the 'length' argument (0.0) in the "lowest" function. it must be >0"
Could someone help please? Thanks
var int nb_bars = 0
nb_bars := B? ta.barssince(A)[2] : 0 // I have [2] because condition A could trigger just before condition B, I want to search the A which is further away
ClusterLow = B ? ta.lowest(nb_bars) : na
Solution 1:[1]
The error is clear, you cannot set the length
to zero.
And ta.barssince(A)[2]
can also be zero if condition A happened 2 bars ago from now, then it happened 0 bars back 2 bars ago. If you skew the index with [2]
, you have to skew the length parameter as well.
Try ClusterLow = B ? ta.lowest(nb_bars + 2) : na
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | karatedog |