Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The function "max_bars_back" is not working as expected

Tags:

pine-script

my expectation in the code below is that the "max_bars_back" will limit the history used for the indicator to 500 bars, but this seems to not work as intended. Do anyone have a suggestion for how this could be fixed?

//@version=4
study("Green Bars Count", max_bars_back = 500)
var count = 0
isGreen = close >= open
if isGreen
    count := count + 1
plot(count)
like image 737
Eivind Risa Avatar asked Dec 27 '25 16:12

Eivind Risa


1 Answers

The max_bars_back is for making sure that it knows how far back to look when it is unable to determine how far. I don't completely understand it as I haven't had issues with it for a while. From what I remember you should only use it if you're running into errors regarding the referencing length of a series.

// © bajaco

//@version=4
study("Green Count")
limit = input(title='Count limit', type=input.integer, defval=500)
green = close > open
score = green ? 1 : 0
green_count = sum(score,limit)

plot(green_count)
like image 145
bajaco Avatar answered Dec 31 '25 19:12

bajaco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!