PureBytes Links
Trading Reference Links
|
Greetings,
I believe that I've found a couple of problems with scaling out via
SetPositionSize and sigScaleOut.
(1) When using sigScaleOut to trigger a scale out, the BuyPrice is
used not the SellPrice. Although, I'm not sure if this is working as
intended and this isn't the main problem.
(2) When scaling out, the back test stats correctly indicate the
profit from scaling out on "Net Profit. However, the detailed stats
under Winners/Losers do NOT correctly indicate the profit from scaling
out. They seem to only indicate the profit from the final exit (or
rather the 2nd of the two).
I've _contrived_ a test case for YHOO daily quotes with a single entry
and two exits. Running the code below on YHOO daily, you'll find that
Net Profit is 151.83 (using 100k starting capital) and Total Profit is
101.83 with 1 winner and 0 losers. The Total profit should included
the profit from both exits.
If anyone sees a problem with they way this is coded, please feel free
to point it out. Thanks.
- Mike
=======================================================
Buy = Ref(C,-1) > 37 AND Open < 35;
BuyPrice = Open;
priceatbuy = 0;
Sell = 0;
firstProfitTarget = 0;
secondProfitTarget = 0;
stopLoss = 0;
sharesTemp = 0;
exit = 0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 AND Buy[ i ] )
{
priceatbuy = BuyPrice[ i ];
stopLoss = priceAtBuy - 3;
perShareRisk = priceatbuy - stopLoss;
sharesTemp = 100 / perShareRisk;
firstProfitTarget = priceAtBuy + PerShareRisk;
secondProfitTarget = priceAtBuy + 2*PerShareRisk;
printf( "firstProfitTarget = %2.2f\n", firstProfitTarget );
printf( "secondProfitTarget = %2.2f\n", SecondProfitTarget );
}
shares[i] = sharesTemp;
if( priceatbuy > 0 )
{
if( exit == 0 AND
High[ i ] >= firstProfitTarget )
{
// first profit target hit - scale-out
exit = 1;
Buy[ i ] = sigScaleOut;
BuyPrice[ i ] = firstProfitTarget;
}
if( exit == 1 AND
High[ i ] >= secondProfitTarget )
{
// second profit target hit - exit
exit = 2;
SellPrice[ i ] = Max( Open[ i ], secondProfitTarget );
BuyPrice[ i ] = Max( Open[i], SecondProfitTarget );
}
if( Low[ i ] <= stopLoss )
{
// trailing stop hit - exit
exit = 3;
SellPrice[ i ] = Min( Open[ i ], stopLoss );
}
if( exit >= 2 )
{
Buy[ i ] = 0;
Sell[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatbuy = 0; // reset price
}
}
}
printf( "Buy = %2.0f\n", Buy );
printf( "Sell = %2.0f\n", Sell );
printf( "SellPrice = %2.2f\n", SellPrice );
SetPositionSize( shares, spsShares );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );
// scale out 50% of position
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|