1

In Pinescript I want to show the highest price level every 50 bars, but no matter what I do I can only show the current high.

//@version=5
indicator(title='Deneme', shorttitle='Deneme', overlay=true, timeframe='')
barLength = input.int(50,minval=1,title='Uzunluk')

counter = 0
higher = 0.0

for i = 0 to bar_index
    if counter == 49
        higher := high[50]
    counter := counter+1
    if counter == 50
        counter := 0
    
counterPlot = plot(higher != 0 ? higher : na, title = 'sayac', color = color.new(color.green,0))




aakcay
  • 15
  • 4

1 Answers1

1

There is a built in function for that - ta.highest()

//@version=5
indicator(title='Deneme', shorttitle='Deneme', overlay=true, timeframe='')
barLength = input.int(50,minval=1,title='Uzunluk')

higher = ta.highest(barLength)
plot(higher)

EDIT:

If you want to see just the last value, it might be easier (visually) to use line:

//@version=5
indicator(title='Deneme', shorttitle='Deneme', overlay=true)
barLength = input.int(50,minval=1,title='Uzunluk')
higher = ta.highest(barLength)

if barstate.islast
    line.new(bar_index - 1, higher, bar_index, higher, extend = extend.both)
mr_statler
  • 1,913
  • 2
  • 3
  • 14
  • Hello, I used the ta.highest function but I got the same result again. What I want is to take the highest data in the last 50 bars and plot it on the screen in a flat and horizontal way without updating it at all. How can I do this? – aakcay Nov 23 '22 at 14:55
  • Can we organize this function so that it repeats every 50 bars? For example, every time prices advance 50 bars, we will plot the highest of the past 50 bars and this line will remain constant until the next 50 bars. Thank you for your effort. – aakcay Nov 23 '22 at 16:14
  • Just change the `if` statement to `if bar_index % 50 == 0 line.new(bar_index - 50, higher, bar_index, higher)`. If I understood you correctly, this should do the trick – mr_statler Nov 23 '22 at 17:07
  • I didn't manage to tag you because I'm a new member of the site, but I wrote a reply under this title, can you look there? – aakcay Nov 23 '22 at 18:52