@portfoliobuilder,
ApplyStop is more suited for “simpler” exits.
You can’t construct this via ApplyStop (-> considering %stop only within first x bars and afterwards doing something else). Why do you think I have posted link to similar code?
And there isn’t anything complicated about that.
The info about “after first 5 days…” got lost in his post. But here is some “Check this one within first five bars and trigger if true and afterwards consider doing something else (if first one didn’t trigger)…”-code.
/// @link http://forum.amibroker.com/t/exit-when-today-close-is-low-than-5-of-entry-price-with-in-5-first-days/2048/4
SetPositionSize( 100, spsShares );
Buy = Sell = 0;
Short = Cover = 0;
// buy signal
BuySignal = MACD() > 0;
SellSignal2 = MACD() < 0;
buyentryprice = buyentrybar = 0;
for( i = 0; i < BarCount; i++ ) {
if( BuySignal[ i ] && buyentryprice == 0 ) {
Buy[ i ] = 1;
buyentryprice = BuyPrice[ i ];
buyentrybar = i;
}
// exit if close is lower than 0.95*buyprice within 5th first bars after entry
SellSignal1 = Close[ i ] < 0.95 * buyentryprice && i <= buyentrybar + 5;
if( SellSignal1 && buyentryprice > 0 ) {
Sell[ i ] = 1;
buyentryprice = buyentrybar = 0;
}
// default sellsignal 5 bars after entry (or construct something else)
if( SellSignal2[i] && i > buyentrybar + 5 && buyentryprice > 0 ) {
Sell[ i ] = 1;
buyentryprice = buyentrybar = 0;
}
}
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( C, "Close", ParamColor( "Color Price", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle(), 0, 1, 0, 0);
PlotShapes( Buy*shapeUpArrow, colorGreen, 0, L, -15 );
PlotShapes( Buy*shapeHollowUpArrow, colorWhite, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallCircle, colorGreen, 0, BuyPrice, 0 );
PlotShapes( Sell*shapeDownArrow, colorRed, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, colorWhite, 0, H, -15 );
PlotShapes( Sell*shapeHollowSmallCircle, colorRed, 0, SellPrice, 0 );