I am researching discretionary buy signals (breakout of wedge, Cup and handle, ...) and testing different trailing stops. I am manually going through each stock and trying to simply select the breakout bar (SelectedValue) and have it plot a trail stop. I am most likely using SelectedValue wrong, but my impression was once I select the bar it will create the Buy signal and use the close price. Buy = SelectedValue(c); What happens is this creates multiple buy signals.
StopLevel = 1 - Param("trailing stop %", 20, 0.1, 30, 0.1)/100;
Buy = SelectedValue(c);
Sell = 0;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel;
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * stoplevel, trailstop );
trailARRAY[ i ] = trailstop;
}
}
PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot( Close,"Price",colorBlack,styleBar);
Plot( trailARRAY,"trailing stop level", colorCustom12);
Thanks