Execute code only on last bar on chart

Again I am hanging on a seemingly easy portion of code for which I didn't find any comments.
I want to execute some code only on/after lastbar on chart.
In easylanguage this is done with

if islastbar then 

but whatever I tried to do with similar afl code it just won't happen, either the code was
nevertheless executed on every bar or never !
For exemple

LB = 0;   //or LB = False;
FinishBar = EndValue( BarIndex() );
if (LB == FinishBar) 
{
...
}

it's never...
All I want to do in fact is to add a candle with calculated values at the end after the last candle

PlotOHLC( HH, HH, LL, LL, "HiLos", colorWhite, styleCandle,Null,Null, 1);

So how can I achieve this ?

bi = BarIndex();
is_last_bar = bi == LastValue(bi);
HH = IIf(is_last_bar, H, Null);
LL = IIf(is_last_bar, L, Null);

//Plot( C, "Price", colorDefault, styleNoDraw );
PlotOHLC( HH, HH, LL, LL, "HiLos", colorWhite, styleCandle, Null, Null, 1);

10

bi = BarIndex();
is_last_bar = bi == LastValue(bi);
HH = IIf(is_last_bar, H, Null);
LL = IIf(is_last_bar, L, Null);

Plot( C, "Price", colorDefault, styleBar );
PlotOHLC( HH, HH, LL, LL, "HiLos", colorWhite, styleCandle, Null, Null, 1);

10

2 Likes

Thanks a lot, that works indeed perfectly.

HH = IIf(is_last_bar, H, Null);
LL = IIf(is_last_bar, L, Null);

especially made the trick, I was so focused on the bar
instead to find the way to exclude the array...