[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Scale Out bug



PureBytes Links

Trading Reference Links

Hello,
 
Firstly do not send thing in three places at once. I have received THREE copies
of this letter (bugs, support and list).
It is frustrating *and* time consuming to have to answer THREE times to one person.
 
Also there is a FEEDBACK CENTER at http://www.amibroker.com/feedback/ where
it is recommended to send this.
 
As to 1 - it is not a bug, it is by design - as scaling in/out sigScalein/SigScaleOut signals must be provided
in BUY/SHORT arrays it is perfectly consistent and logical that corresponding prices must be stored
in buyprice/shortprice arrays.
 
As to 2 - in order to confirm that or not I would need to check this in detail and will get back to you later
using correct channels (i.e NOT this list). 

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: Mike
Sent: Sunday, April 09, 2006 3:26 PM
Subject: [amibroker] Scale Out bug

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