Hi All,

In the effort to capture all trades (e.g. all buys and sells no matter how many 
are on the same bar), I convoluted some code and got it to work by manually 
assigning buy/sells to bars.  While it works to capture all trades, it's 
messing with other parts of AB (drawdown calcs and probably others).

So, after verifying all trades can be captured, and captured appropriately, I'm 
trying to re-write it to AB native language.  My first attempt is to use 
sigScaleIn / sigScaleOut, but after some extensive reading I'm not 
understanding how to scale with set price points.  The verified profit is 
$5315.42, while the ScaleIN/OUT is ~$22,000.

Since about everything else that's stumped me with AB has been simple, anyone 
know what I'm missing?

Thanks tons,
Michael

I'm trying to use (obviously not working):

...
      if ( Low[i] < myStopLosss[j] AND timeValid[i] ) // Check for Stops First
      {
        Buy[ i ] =  sigScaleOut;                                
        BuyPrice[i] = myStopLosss[j]; // To override AA Trades tab, You must 
set Prices after Flagging
        openPos[j] = False; // No longer have open position

...

        if ( High[i] > sellPrices[j] ) // Check for Profits
        {
          Buy[ i ] =  sigScaleOut;                                
          BuyPrice[i] = sellPrices[j];
          openPos[j] = False; // No longer have open position

...

      if (     ( lastLow[j] < tradeActivationPrices[j] )
           AND ( High[i] > buyPrices[j] )
           AND ( buyPrices[j] > Low[i-1] ) //capture gaps
           AND ( timeValid[i] )
         )
      {
        Buy[i] = sigScaleIn;
        BuyPrice[i] = buyPrices[j];
        openPos[j] = True; // Now have an open position
...


within the original code:



for ( i = 0; i < BarCount; i++ ) // Loop over all bars in the chart
{
    for ( j = 0; j < numBuyPoints; j++ ) // Loop over all Buy points
    {
        if ( openPos[j] ) // Have an open position, check to sell it
        {
            if ( Low[i] < myStopLosss[j] AND timeValid[i] ) // Check for Stops 
First
            {
                Buy[stickBuySellAt] = True;
                BuyPrice[stickBuySellAt] = buyPrices[j];  // To override AA 
Trades tab, You must set Prices after Flagging
                stickBuySellAt = stickBuySellAt + 1;
                Sell[stickBuySellAt] = True;
                SellPrice[stickBuySellAt] = myStopLosss[j];
                stickBuySellAt = stickBuySellAt + 1;
                openPos[j] = False; // No longer have open position
                lastLow[j] = IIf( Close[i] < SellPrice[i], Close[i], 
SellPrice[i] ); // ReSet lastLow[j] for Buy Check
            }
            else
            {
                if ( High[i] > sellPrices[j] ) // Check for Profits
                {
                    Buy[stickBuySellAt] = True;
                    BuyPrice[stickBuySellAt] = buyPrices[j];
                    stickBuySellAt = stickBuySellAt + 1;
                    Sell[stickBuySellAt] = True;
                    SellPrice[stickBuySellAt] = sellPrices[j];
                    stickBuySellAt = stickBuySellAt + 1;
                    openPos[j] = False; // No longer have open position
                    lastLow[j] = IIf( Close[i] < SellPrice[i], Close[i], 
SellPrice[i] ); // ReSet lastLow[j] for Buy Check
                }
            }
        }
        else // Nothing open on this BuyPoint, see if we can buy something
        {
            if (     ( lastLow[j] < tradeActivationPrices[j] )
                     AND ( High[i] > buyPrices[j] )
                     AND ( buyPrices[j] > Low[i-1] ) //capture gaps
                     AND ( timeValid[i] )
               )
            {
                // Do NOT assign BUY or BUYPRICE, the sell has to do that to 
keep continuity
                // BuyPrice[i] = buyPrices[j];
                // Buy[i] = True;
                openPos[j] = True; // Now have an open position
            }

            if (    ( lastLow[j] > Close[i] )
                    OR ( lastLow[j] > BuyPrice[i] )
               )
            {
                lastLow[j] = IIf( BuyPrice[i] > Close[i] , Close[i] , 
BuyPrice[i] );
            }
        }
    }
}


Logging and excessive commenting removed.  Here's an example log output:

Setup Vars:
symbolsLow-23.7500, symbolsHigh-34.6500, buyPriceMin-21.3700, 
buyPriceMax-34.6600
Optimization Vars:
buyPriceStart-23.6000, profitPctChange-0.0600, stopLossPctChange-0.0200, 
tradeActPctChange-0.0400

BuyPrices: [0] Buy-23.60, Activate-22.66, Stop-23.13, Profit-25.02
BuyPrices: [1] Buy-25.01, Activate-24.00, Stop-24.50, Profit-26.51
BuyPrices: [2] Buy-26.51, Activate-25.44, Stop-25.97, Profit-28.10
BuyPrices: [3] Buy-28.10, Activate-26.97, Stop-27.53, Profit-29.78
BuyPrices: [4] Buy-29.78, Activate-28.58, Stop-29.18, Profit-31.56
BuyPrices: [5] Buy-31.56, Activate-30.29, Stop-30.92, Profit-33.45
BuyPrices: [6] Buy-33.45, Activate-32.11, Stop-32.78, Profit-35.45
BuyPrices: [7] Buy-35.45, Activate-34.03, Stop-34.74, Profit-37.57
DGP,Bought,2009-11-02,14:02,1,25.0100
DGP,Profit,2009-11-03,12:58,0,1,25.01,26.51
DGP,Bought,2009-11-03,12:58,2,26.5100
DGP,Profit,2009-11-13,15:56,0,2,26.51,28.10
DGP,Bought,2009-11-13,15:56,3,28.1000
DGP,Profit,2009-11-23,09:00,0,3,28.10,29.78
DGP,Bought,2009-11-27,09:32,4,29.7800
DGP,Profit,2009-12-01,09:01,0,4,29.78,31.56
DGP,Bought,2009-12-01,09:53,5,31.5600
DGP,StopLoss,2009-12-04,10:40,0,5,31.56,30.92
DGP,Bought,2009-12-31,10:29,2,26.5100
DGP,Profit,2010-01-06,09:00,0,2,26.51,28.10
DGP,Bought,2010-01-06,09:30,3,28.1000
DGP,StopLoss,2010-01-13,10:31,0,3,28.10,27.53
DGP,Bought,2010-02-01,12:48,2,26.5100
DGP,StopLoss,2010-02-04,09:31,0,2,26.51,25.97
DGP,Bought,2010-02-05,15:35,1,25.0100
DGP,Profit,2010-02-16,09:04,0,1,25.01,26.51
DGP,Bought,2010-02-24,09:47,2,26.5100
DGP,Profit,2010-03-02,10:46,0,2,26.51,28.10
DGP,Bought,2010-03-02,10:46,3,28.1000
DGP,StopLoss,2010-03-08,11:23,0,3,28.10,27.53
DGP,Bought,2010-04-05,13:19,3,28.1000
DGP,Profit,2010-04-27,15:00,0,3,28.10,29.78
DGP,Bought,2010-04-27,15:00,4,29.7800
DGP,Profit,2010-05-06,14:57,0,4,29.78,31.56
DGP,Bought,2010-05-06,14:57,5,31.5600
DGP,Profit,2010-05-12,09:35,0,5,31.56,33.45
DGP,Bought,2010-05-12,09:35,6,33.4500
DGP,StopLoss,2010-05-14,10:46,0,6,33.45,32.78
DGP,Bought,2010-05-28,11:13,5,31.5600
DGP,Profit,2010-06-07,12:13,0,5,31.56,33.45
DGP,Bought,2010-06-07,12:13,6,33.4500
DGP,StopLoss,2010-06-09,11:14,0,6,33.45,32.78
=End=



Reply via email to