LineArray without loop (x position problem)

I draw kind of signal lines on charts using loop with Plot and Line Array. It looks like this:

for ( i = 5; i < BarCount; i++ )
	showBuy=IIf(H[i-1]<H[i-2] AND L[i-1]>L[i-2],1,0 ) 

I know that Plot inside for-loop is not optimal, that is why I would like to work on arrays. I'm trying to use code like this below, however I've got problems with defining X co-ordinates:

x0Buy=???; //(previous bar);
x1Buy=???; //(current bar);
y0Buy=H[i-1]; //(y value for previous bar)
y1Buy=y0Buy; //(y value for current bar)
showBuy=IIf( Ref(H,-1)<Ref(H,-2) AND Ref(L-1)>Ref(L,-2),1,0 ) 
Plot(IIf(showBuy==1,LineArray(???x0Buy???, y0Buy, ???x1Buy???, y1Buy), Null),"",colorYellow,styleThick);

I would like to draw LinaArray not only on the last bar, but on the whole chart. I think I should define somehow X position of the bar for LineArray purposes. I did (almost) the same with PlotShapes on arrays (because it doesn't need to define X coordinates, it is enough when showBuy==1), but LineArray is visually much better that is why I would like to solve this issue.

Any suggerstions, please?

There is proper code on how to use LineArray with Plot by T.J. at User KB.
See @Tomasz's version (2nd code) there.

/// modified from T.J. code of User KB at:
/// @link 
/// Plot the Trade Lines
bi = Barindex();
Sig = Ref(ROC(H,1)<0 AND ROC(L,1)>0,-1);// every n-bar

y0 = 0;
y1 = L[0];
FirstVisibleBar = FirstVisibleValue(bi);
Lastvisiblebar = LastVisibleValue(bi);
CombinedLine = Null;
for ( b = Firstvisiblebar; b <= Lastvisiblebar; b++ )
    if ( Sig[b] )
        TPrice[b] = L[b];

        x0 = y0;
        x1 = y1;
        y0 = b;
        y1 = TPrice[b];
        La = LineArray( x0, x1, y0, y1 );

        CombinedLine = IIf( IsNull( la ), CombinedLine, la );

Plot( C, "Price", colorDefault, styleBar );
Plot( CombinedLine, "", colorYellow);
PlotShapes(sig*shapeSmallCircle, colorYellow, 0, L, -12);



Yes, I know this solution (however, I had some problems with using it), but there is still for-loop and works for visible part of the chart (firstvisible-lastvisible) and it's pretty... complicated :wink:
Is there any possibility to do it like in my first post (2nd code)? The problem is to define/set X co-ordinates.

Where is that mentioned in first post??

There is no problem with 2nd post's code (I didn't face problems).
What is problem (you had)? No one can read your mind and no one can look at your screen!

If there would be loop-less way then I would have posted it! I am not posting for sake of posting.

You want to plot on chart. Chart is visible area.
Quoting movie character "Biff Tannen":

"Hello? Hello? Anybody home, McFly?"

If you want to output Linearray in analysis window (which you did not say in first post at all) then simply replace

FirstVisibleBar = FirstVisibleValue(bi);
Lastvisiblebar = LastVisibleValue(bi);


FirstVisibleBar = 0;
Lastvisiblebar = BarCount-1;

And Sig may be modified to

Sig = Sig AND Status("BarInRange");

But as far as plot is concerned... there is other way using Gfx (but it wlll not output values between each signal point). It will just draw line (connecting signal points).

Sig = Ref(ROC(H,1)<0 AND ROC(L,1)>0,-1);

bi = Barindex();
fvb= FirstVisibleValue(bi);
lvb = LastVisibleValue(bi);

GfxSelectPen(colorYellow, 1, 0);
GfxMoveTo(fvb, L[fvb]);
for ( i = fvb; i <= lvb; i++ ) {
    if ( Sig[i] ) GfxLineTo(i, L[i]);

Plot( C, "Price", colorDefault, styleBar );
PlotShapes(sig*shapeSmallCircle, colorYellow, 0, L, -12);



OK, now it's clear for me, thanks!!