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 );
}
}
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
-
29.7 KB Views: 99