0

I'd like to set the index of bar_index[] based on ta.pivothigh in a dynamic way.

// PivotHigh Check
leftBars= input(4)
rightBars = input(4)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_circles, linewidth=3, color=#ffffff, offset=-rightBars)

// Draw the line
upperLine = line.new(bar_index[10], high[10], bar_index[20], high[20], color=#ffffff, width = 2)

As you can see the numbers 10 and 20 aren't written in a dyinamic way, because I wrote the index of bar_index and high. Is it possible to return the value of each circles made by ta.pivothigh in order to fill the index automatically?

Mlabuit
  • 65
  • 7

1 Answers1

1

When your pivot is drawn, you are 'rigthBars' away from it. So the index of your pivot is bar_index-rigthBars.

//@version=5
indicator("test", overlay = true)
var IndexNewPivot = 0
var IndexOldPivot = 0
// PivotHigh Check
leftBars= input(4)
rightBars = input(4)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_circles, linewidth=3, color=color.purple, offset=-rightBars)

if ph > 0
    // Draw the line
    IndexNewPivot := bar_index - rightBars
    upperLine = line.new(IndexOldPivot, high[bar_index - IndexOldPivot], IndexNewPivot, high[bar_index - IndexNewPivot], color=color.blue, width = 2)
    IndexOldPivot := IndexNewPivot

The result : enter image description here

G.Lebret
  • 2,826
  • 2
  • 16
  • 27