How do I combine many LineArrays?

Hello,

I've created many LineArrays with VarSet()
and want to combine these LineArrays to one,
but it's failed with ValueWhen(), is there a way to do this?

x0 = y0 = x1 = y1 = 0;
for( i = 100; i < BarCount; i+=300 )
{
  x0 = i - 100; y0 = L[i - 100];
  x1 = i;       y1 = L[i];
  VarSet("T" + i, LineArray(x0, y0, x1, y1, 1));
}

TrendLine = ValueWhen(VarGet("T" + BarIndex()), VarGet("T" + BarIndex()));
Plot (TrendLine, "TrendLine", colorTan, styleline);

Thank you very much :smiley: !

You code is incorrect. There is proper code by T.J. at User KB.
http://www.amibroker.org/userkb/2007/04/20/plotting-trade-zigzag-lines/
See Tomasz's version (2nd code) from there.

/// modified from T.J. code of User KB at:
/// @link http://www.amibroker.org/userkb/2007/04/20/plotting-trade-zigzag-lines/ 
/// Plot the Trade Lines
bi = Barindex();
Sig = bi % 100 == 0;// 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, "", colorRed);
5 Likes