Accessing array outside the loop

Hi,
Please could I get some help, on accessing the arrays bot_line1 and top_line1 from this loop?
I have tried StaticVarSet and StaticVarGet, as I understand it, this will allow or make available the arrays inside the loop from the outside. I just have no idea where to put these formula.
I'm just trying to colour in some line arrays with
PlotOHLC(top_Line,bot_Line,top_Line,bot_Line,"",colorAqua,styleCloud);
but obviously getting error 29.
Thanks very much for any help!

for ( i = lvb;i > fvb;i-- )
{
    if ( top_line[i]  )
    {
    //StaticVarSet("top_line", top_line); 
        x2_tl = MT_px2[i];
        x1_tl = MT_px1[i];
        x0_tl = MT_px0[i];
        y2_tl = MT_ph2[i];
        y1_tl = MT_ph1[i];
 
        if ( x0_tl == x1_tl )
            x0_tl = BarCount - 1;
        top_Line1 = LineArray( x2_tl, y2_tl, x1_tl, y1_tl, 1 );
        top_idx2 = xx == x2_tl;
        top_idx1 = xx == x0_tl;
        top_idx = Flip( top_idx2, top_idx1 );
        top_Line1 = IIf( top_idx, top_Line1, Null );
        Plot( top_Line1, "", colorWhite, 1, Null, Null, 0, 1, 2 );
     
     //StaticVarSet ("top_line" , top_Line1);
     //top_Line1 = StaticVarGet ("top_line1");   
        
    }
     
    if ( bot_line[i]  )
    {
    //StaticVarSet("bot_line", bot_line);
        x2_bl = MT_tx2[i];
        x1_bl = MT_tx1[i];
        x0_bl = MT_tx0[i];
        y2_bl = MT_tl2[i];
        y1_bl = MT_tl1[i];
 
        if ( x0_bl == x1_bl )
            x0_bl = BarCount - 1;
         bot_Line1 = LineArray( x2_bl, y2_bl, x1_bl, y1_bl, 1 );
         bot_idx2 = xx == x2_bl;
         bot_idx1 = xx == x0_bl;
         bot_idx = Flip( bot_idx2, bot_idx1 );
         bot_Line1 = IIf( bot_idx, bot_Line1, Null );
         Plot( bot_Line1, "", colorBlue, 1, Null, Null, 0, 1, 2 );
     
     //StaticVarSet("bot_line", bot_line1);
     //bot_Line1 = StaticVarGet ("bot_line1");
    }

}
top_Line = StaticVarGet ("top_line1");
bot_line = StaticVarGet ("bot_line1");

PlotOHLC(top_Line1,bot_Line1,top_Line1,bot_Line1,"",colorAqua,styleCloud);

Your code is incomplete

But take a look at 2nd code version here
http://www.amibroker.org/userkb/2007/04/20/plotting-trade-zigzag-lines/

Hi @fxshrat , sorry for the incomplete code. I was just showing the issue at hand, and I should have given the complete code, for a better solution from the forum, apologies!
Your solution, of the 2nd code version, worked perfectly! Thanks you very much for the help.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.