I have been struggling with BARINDEX and its interpretation, as far as I am aware it will tell me how many bars are loaded since the beginning of an automated strategy so the very first bar in a strategy should be 0.
I have a piece of code below where I would like to enter the position under certain circumstances and when BARINDEX = 0. But it never enters the initial position so the automated strategy wont get going.
Am I misunderstanding BARINDEX or is the code below wrong?
The online prorealtime documentation of the site :
BARINDEX : Return the number of bars since the beginning of data loaded (in a chart in the case of a ProBuilder indicator of for a trading system in the case of ProBacktest or ProOrder)
In your code, if barindex=0, there are no way to calculate 7 previous bar of the very first one 🙂
In your first condition you are trying to find the highest and lowest values from the 7 previous periods, but it’s not possible since you are trying to do this at the first bar (barindex=0). So you need to wait until you are at least at the 7th bar of loaded history to find these values.