Hi
I was given the following exit code on the forum which 'Sells at the open on the
first profitable day' and was supposedly
written by TJ.
I added it to a simple Gap system to test it and It works most of
the time but occasionally skips one or more profitable opens before exiting.
Can any of the experts spot why it’s inconsistent?
Any help would be appreciated!!
Peter
SetChartOptions( 0, chartShowArrows );
SetOption("AllowSameBarExit",True );
SetOption( "ActivateStopsImmediately", True
);
SetOption( "Futuresmode", True
);
Buy = Open > Ref(H,-1);
BuyPrice = Open;
Sell = 0;
/* Exit first profitable
open - Long */
entrybar = -1;
for( i = 0; i < BarCount; i++
)
{
if( entrybar == -1 AND Buy[ i ] )
{
entrybar = i;
}
if( entrybar != -1 AND i > entrybar AND
Open[ i
] > BuyPrice
[entrybar ] )
{
Sell[ i ] = 1;
SellPrice[ i ] = Open[ i ];
entrybar = -1;
}
else
{
Sell[ i ] = 0;
}
}
/* Exit Pints Stop- Long */
StopLossPtsPar = Param("StopLoss Pts", 30, 10,50,1);
StopLossPtsOpt = Optimize("StopLossPts", StopLossPtsPar , 10, 50, 1);
PtStop = ApplyStop(stopTypeLoss,
stopModePoint,
StopLossPtsOpt , 1, False, 0);
PositionSize = MarginDeposit = 1;