I am trying to calculate weekly data on a daily chart. And I found that the returned value from BarIndex() is not always 0 based, after calling TimeFrameSet(). How could I get the correct weeklyBarsAvailable? It should increment from 0 to 60 during the first 60 weeks of the stock.
_SECTION_BEGIN("Close Ranking");
TimeFrameSet(inWeekly);
weeklyBarIndex = BarIndex();
weeklyBarsAvailable = Min(weeklyBarIndex, 60);
weeklyCloseRank = PercentRank(Close, weeklyBarsAvailable);
TimeFrameRestore();
weeklyBarsIndexExpanded = TimeFrameExpand(weeklyBarIndex, inWeekly, expandLast);
weeklyBarsAvailableExpanded = TimeFrameExpand(weeklyBarsAvailable, inWeekly, expandLast);
weeklyCloseRankExpanded = TimeFrameExpand(weeklyCloseRank, inWeekly, expandLast);
Plot(weeklyBarsIndexExpanded, "weeklyBarsIndexExpanded", colorRed, styleDashed);
Plot(weeklyBarsAvailableExpanded, "weeklyBarsAvailableExpanded", colorPink, styleDashed);
Plot(weeklyCloseRankExpanded, "weeklyCloseRankExpanded", colorYellow, styleDashed);
_SECTION_END();
BarIndex() for AAPG started with 39, then incremented by 1 every week.
BarIndex() for AAPW started from 0, jumped to 26, then incremented by 1 every week.
I would like to see something start from 0 and increment by 1 every week.