Plot line without the loop

#1
I am trying to plot the stop line. The following code works but because of the loop it slows down the afl. Can anyone suggest a LOOPLESS solution?

startBarBuy = IIf( Buy == 1 OR Short==1, BarIndex() - BarsSince( BuyStopInitial != Ref( BuyStopInitial, -1 ) )-10, Null );
startBarShort = IIf( Buy == 1 OR Short==1, BarIndex() - BarsSince( ShortStopInitial != Ref( ShortStopInitial, -1 ) -10), Null );

endBar = IIf( Buy == 1 OR Short==1, BarIndex()+10, Null );
stopline = 0;

for ( s = 0;s < BarCount - 1;s++ )
{
if ( Buy == 1 ){
stopline = LineArray( startBarBuy , BuyStopInitialConfirmed , endBar, BuyStopInitialConfirmed, 0 );
Plot(stopline, "trailing stop level", colorBlue, styleDots + styleThick + styleNoTitle + styleNoLabel );
}
else if (Short==1)
{
stopline = LineArray( startBarShort , shortStopInitialConfirmed , endBar, shortStopInitialConfirmed, 0 );
Plot(stopline, "trailing stop level", colorBlue, styleDots + styleThick + styleNoTitle + styleNoLabel );
}

}
 

Attachments

#3
help me out please :) I want to draw the blue line (see above) without the loop. Is it possible?

Since you know coding, i will put it in short.

Stop1=ValueWhen(Buy,your calculation,1);
Stop = IIf( BarsSince( Buy ) <= 5, stop1, Null );

Then plot it as usual. Hope it works.
 
#4
Since you know coding, i will put it in short.

Stop1=ValueWhen(Buy,your calculation,1);
Stop = IIf( BarsSince( Buy ) <= 5, stop1, Null );

Then plot it as usual. Hope it works.
What will be the code to plot the line. I am asking because if Linearray is to be used then a loop will be required.
 

Similar threads