'Pine script barssince confused
I am new to Pine script and I will appreciate it very much any kind of help. I have been using Python for my strategies but I am very interested in Pine script. Based on the code below I would like to know if on the line below "NH = valuewhen(high>k1[1],high,0)" is k1[1] a series (list) or just one value. What about
barssince(high>k1[1]) below? Basically my question is: what is the difference of the value of k1[1] between valuewhen(high>k1[1],high,0) and barssince(high>k1[1])
boxp=input(5, "BOX LENGTH")
LL = lowest(low,boxp)
k1=highest(high,boxp)
k2=highest(high,boxp-1)
k3=highest(high,boxp-2)
NH = valuewhen(high>k1[1],high,0)
box1 =k3<k2
TopBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, NH, 0)
Solution 1:[1]
highest() returs series float so, k1 is of series in all cases.
[] in pinescript is called History reference operator and is used to refer to the historical values of any variable of the series type.
So, k[1] refers to k's previous value.
valuewhen(high>k1[1],high,0) will return the high price when high > k[1] was true the last time.
barssince(high>k1[1]) will tell you how many bars ago this was.
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 | vitruvius |
