I am using this scaling out loop code found on the AB site. I noticed that the first Profit target sellprice gets the close price of targeted bar assigned to it while the second profit target gets assigned the exact percent change (intrabar) from the buyprice. I tried assigning a sellprice to the first profit target as is in the second target but that did not change the results, The BT is still posting the close as the sellprice for first target. I feel I may need to augment this last line...SetPositionSize( 50, spsPercentOfPosition * (Buy == sigScaleOut ) ); but I don't know where to look. If anyone can see the fix or direct me to it so I can get the first target to post into the BT as the exact intrabar value, that would be appreciated.
Thank you for your helpstrong text.
// the system will exit
// 50% of position if FIRST PROFIT TARGET stop is hit
// 50% of position is SECOND PROFIT TARGET stop is hit
// 100% of position if TRAILING STOP is hit
FirstProfitTarget = .5; // profit
SecondProfitTarget = 1; // in percent
TrailingStop = 2; // also in percent
priceatbuy=0;
highsincebuy = 0;
exit = 0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 AND Buy[ i ] )
{
priceatbuy = BuyPrice[ i ];
}
if( priceatbuy > 0 )
{
highsincebuy = Max( High[ i ], highsincebuy );
if( exit == 0 AND
High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy )
{
// first profit target hit - scale-out
exit = 1;
// **Tried adding this... SellPrice[ i ] = Max( Open[ i ], ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy );**
Buy[ i ] = sigScaleOut;
}
if( exit == 1 AND
High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy )
{
// second profit target hit - exit
exit = 2;
SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy );
}
if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy )
{
// trailing stop hit - exit
exit = 3;
SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy );
}
if( exit >= 2 )
{
Buy[ i ] = 0;
Sell[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatbuy = 0; // reset price
highsincebuy = 0;
}
}
}
SetPositionSize( 2, spsShares );
SetPositionSize( 50, spsPercentOfPosition * (Buy == sigScaleOut ) ); // scale out 50% of position