3

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)

1 Answers1

1

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)
Max S.
  • 3,704
  • 2
  • 13
  • 34
bajaco
  • 830
  • 1
  • 4
  • 11