Reputation: 1
Why is this code showing me wrong pivothighs it there are any? It is counting every second bar to the left and to the right not only one... If I change if to:
bar_index % 1 == 0
, it is working right .
Here my code :
//@version=4
study("fckn test", overlay=true)
if bar_index % 2 == 0
ph = pivothigh(1,1)
label.new(bar_index-1, low, tostring(ph))
Upvotes: 0
Views: 993
Reputation: 8789
Not too sure what you are trying to do. Perhaps this?
//@version=4
study("fckn test", overlay=true)
pivotLegs = 1
// Find pivot outside `if` block because needs to run on every bar.
ph = pivothigh(pivotLegs, pivotLegs)
// Detect a new pivot.
newPh = not na(ph)
// If a new pivot is found, save the bar index where it was found.
bh = newPh ? bar_index - pivotLegs : na
if bar_index % 2 == 0 and not na(ph)
label.new(bh, high[pivotLegs], tostring(ph))
Upvotes: 1