Very interesting problem.
First, it appears that your code is not quite right. It would appear that
Status("lastvisiblebar") will actually give you the index of the last bar
*including* blank bar padding to the right of the chart.
So, check your charting preference settings for "Blank bars in right margin"
(via Tools | Preferences... | Charting). Following your logic, you would need
to subtract that many bars from the result of Status("lastvisiblebar").
e.g.
lbr = Status("lastvisiblebar") - 10;
However, I believe that a recent beta has added the ability to stretch the
right padding even more, so this approach is probably not going to work in more
recent versions than mine (5.20). A more reliable way would be to take the
lesser of the Status result and BarCount - 1.
e.g.
lbr = min(Status("lastvisiblebar"), BarCount - 1);
Second, it appears that when running the syntax verify,
Status("lastvisiblebar") returns -1. Presumably this is because the code is not
being run in the context of the chart. However, if you simply save the changes,
your chart will correctly update to reflect your code.
Mike
--- In [email protected], "brianw468" <wil...@...> wrote:
>
> Can someone please advise where the error is in the following simple code:-
>
> fbr = Status("firstvisiblebar");
> Lbr = Status("lastvisiblebar")-1;
>
> x0 = fbr;
> x1 = Lbr;
> y0 = H[fbr];
> y1 = L[Lbr];
> Line = LineArray(x0,y0,x1,y1);
> Plot(Line,"Line",colorGreen);
>
> The compiler produces an "out of range" error for the subscript in y1.
> Hard to see how, since the status calls should return array index values,
> which obviously should be within the range used.
> Thanks.
>