LastVisibleValue take value from the next future bar instead of the last visible bar

Hi all,
I'm plotting the LastVisibleValue on Close:

Plot( LastVisibleValue( Close ), "lvv", colorBlue );

However the horizontal line is based on the Close of the next future bar (hidden), instead of the immediate close of the last visible bar as what I'm expected. Or am I mistaken of how it works?

lastvisiblevalue%20-%20Copy

1 Like

Hi @bursaware,

The single line code on it's own works fine at my end.

As a preliminary check, if you are using that line of code with other lines of code then try using the single line code on it's own to see if it works as expected at your end.

1 Like

Thanks @TrendSurfer for the suggestion.

I stripped my code until the last 3 lines and the problem still occur:

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

lbar = LastValue( BarIndex() );
Plot( LastVisibleValue( Close ), "lvv", colorBlue, styleThick );

LastVisibleValue works as expected after I removed this line :

lbar = LastValue( BarIndex() );

Not sure how this can have effect on the LastVisibleValue.

regards.

1 Like

If those lines are last lines of your entire code then lbar has no use anywhere. Simply remove that line instead of keeping "zombie" code lines having no purpose.


As for LastValue... for it to work is loads entire array if user wants to get very last value.


As for QuickAFL and how to control it read here.

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

lbar = LastValue( BarIndex() );
Plot( LastVisibleValue( Close ), "lvv", colorBlue, styleThick );

SetBarsRequired(100, 0);

By setting 2nd argument to zero and placing SetBarsRequired at end of formula you disable loading future bars.


If for example you want to output last visible price and last value price you might do like this using Status function.

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

lbar = LastValue(BarIndex());

lvb = Min(Barcount-1, Status("lastvisiblebar"));

Plot( C[lvb], "lvv", colorBlue, styleThick );
Plot( LastValue(C), "last value C", colorOrange, styleThick );

As you can see lvv line keeps value the same as default AB price label despite of two times LastValue in code.
9

6 Likes

Thanks @fxshrat for the explanation. Actually the lbar is used in another calculation in the bottom. Your trick is saving the day, as always. :slight_smile: