You are dealing with poorly written code. BarIndex() returns an array in which the first bar is 0 in contrast to Barcount which is the number of bars (a single number) starting at 1. If this makes no sense, read the section of the Users Guide regarding arrays. So for the last bar BarIndex() = BarCount - 1.
All you need is one line: xBarIndex = LastValue(BarInddex();
You should read the Help and Users Guide for a full description of both and also look at the "Common Errors" section which discusses common errors using them.
In addition to reading Help and User Guide, put this little piece of code in a blank window and it will help you understand the difference as you click on different bars.
xLastValue= LastValue(BarIndex());//LastValue( x ); Title = "xbarindex=" + xbarindex + " x=" + x + " xlastvalue=" + LastValue(x) + " barcount = " + BarCount;
Last edited by colion; January 25th, 2012 at 09:23 AM.
The following 3 users say Thank You to colion for this post: