I am having a fundamental problem developing a screener… I don’t appear to understand the bar indexes.
Working on a screener on the monthly timescale, and I am finding that BarIndex, and indeed using many functions that should act on the current bar, simply do not work as I would expect.
For example, BarIndex is always 2 lower than the actual number of bars displayed in the chart (easy to see on stocks that haven’t been around long) and ‘low’ is returning the low of the previous bar, not the current bar… doing low[0], returns the same value.
What I am assuming is that BarIndex actually returns the index of the first bar in the data, not the count of bars as described in the documentation, but what I don’t understand is why the current bar is not bar 0.
This disparity is making things like this script to detect when a stock set an ATL last month to break completely.
I am able to get around the BarIndex issue by using BarIndex+1… for example to find the All time low price I have to use
TIMEFRAME(monthly)
ATL = lowest[BarIndex + 1](low)
Or it ignores the price of the first month… which can be important.
But I have no idea how to get the low of the current bar as index 0 always seems to point to the previous bar, thus ‘low’ and ‘low[0]’ return last months low; ‘low[-1]’ give me an index error.
Can someone please explain to me the logic of the way the bars are indexed?
Also, is the a quick way to return the index of the bar rather than the price when using lowest or highest, or perhaps a way to look up the index using a price once I have it.
Finally, why is there no search on these forums… I tried using the search under my profile picture, but it returns stuff from all over, not just this forum.