--- In amibroker@yahoogroups.com, "Mike" <sfclimb...@...> wrote:
>
> You have not indicated how you generated your log file (or at least it is not 
> showing up on the web forum). But, the backtester will reject trades due to a 
> number of settings that your log would appear not to be considering; e.g. max 
> positions, insufficient funds, position size shrinking, redundant signals, 
> etc. etc.
> 
> AmiBroker is a very mature product with thousands of users. When something is 
> not working out the way you expect, 99.9% of the time it's going to be 
> because of something we the users are doing incorrectly, rather than what 
> AmiBroker is doing incorrectly ;)
> 
> Run your backtest with detailed reporting (see AA Settings) and you will get 
> a bar by bar breakdown of signals, entries, exits and reason for rejections.
> 
> Mike

Hi Mike,

You've been a great help, and I agree with you fully, I figure it's something 
I'm either unintentionally doing wrong or I just haven't found the proper 
switch yet to accept all trades.

To that end I re-wrote the code to avoid any overlapping of Buy/Sell pairs 
(below).  Other than it messes up the trade dates anyone see a problem with 
this not collecting every trade?

One must learn to crawl before one can run,
Michael


Buy/Sell/Stops from Logfile:
********* Symbol : FAS *********
Setup Vars:
symbolsLow-17.4000, symbolsHigh-39.7933, buyPriceMin-15.6500, 
buyPriceMax-39.8000
Optimization Vars:
buyPriceStart-17.0500, profitPctChange-0.0800, stopLossPctChange-0.0600, 
tradeActPctChange-0.0700

BuyPrices: [0] Buy-17.0500, Activate-15.8565, Stop-16.0270, Profit-18.4140
BuyPrices: [1] Buy-18.4100, Activate-17.1200, Stop-17.3000, Profit-19.8800
BuyPrices: [2] Buy-19.8800, Activate-18.4800, Stop-18.6800, Profit-21.4700
BuyPrices: [3] Buy-21.4700, Activate-19.9600, Stop-20.1800, Profit-23.1800
BuyPrices: [4] Buy-23.1800, Activate-21.5500, Stop-21.7800, Profit-25.0300
BuyPrices: [5] Buy-25.0300, Activate-23.2700, Stop-23.5200, Profit-27.0300
BuyPrices: [6] Buy-27.0300, Activate-25.1300, Stop-25.4000, Profit-29.1900
BuyPrices: [7] Buy-29.1900, Activate-27.1400, Stop-27.4300, Profit-31.5200
BuyPrices: [8] Buy-31.5200, Activate-29.3100, Stop-29.6200, Profit-34.0400
BuyPrices: [9] Buy-34.0400, Activate-31.6500, Stop-31.9900, Profit-36.7600
BuyPrices: [10] Buy-36.7600, Activate-34.1800, Stop-34.5500, Profit-39.7000
BuyPrices: [11] Buy-39.7000, Activate-36.9200, Stop-37.3100, Profit-42.8700
BuyPrices: [12] Buy-42.8700, Activate-39.8600, Stop-40.2900, Profit-46.2900

// This writes the above table //
op = StrFormat("BuyPrices: [%g] Buy-%.4f, Activate-%.4f, Stop-%.4f, 
Profit-%.4f\n", 
i,buyPrices[i],tradeActivationPrices[i],myStopLosss[i],sellPrices[i] );
fputs( op, fhLog );



{skipping setup, it's at michaels-musings.com if you want to see it}

// numBuyPoints is 12.
// stickBuySellAt starts at zero.

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] ) // Check for Stops First
      {
        BuyPrice[stickBuySellAt] = buyPrices[j];
        Buy[stickBuySellAt] = True;
        stickBuySellAt = stickBuySellAt + 1;
        SellPrice[stickBuySellAt] = myStopLosss[j];
        Sell[stickBuySellAt] = True;
        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
        if ( writeLog == TRUE )
        {
          op = Name() + ",StopLoss";
          op = op + StrFormat(",%02.0f-%02.0f-%02.0f,%02.0f:%02.0f:%02.0f", y[ 
i ], m[ i ], d[ i ], r[ i ], e[ i ], n[ i ] );
          op = op + StrFormat(",%g,%.4f,%.4f,%.4f\n", j, buyPrices[j], 
myStopLosss[j], stickBuySellAt );
          fputs( op, fhLog );
        }
      }
      else
      {
        if ( High[i] > sellPrices[j] ) // Check for Profits
        {
          BuyPrice[stickBuySellAt] = buyPrices[j];
          Buy[stickBuySellAt] = True;
          stickBuySellAt = stickBuySellAt + 1;
          SellPrice[stickBuySellAt] = sellPrices[j];
          Sell[stickBuySellAt] = True;
          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
          if ( writeLog == TRUE )
          {
            op = Name() + ",Profit";
            op = op + StrFormat(",%02.0f-%02.0f-%02.0f,%02.0f:%02.0f:%02.0f", 
y[ i ], m[ i ], d[ i ], r[ i ], e[ i ], n[ i ] );
            op = op + StrFormat(",%g,%.4f,%.4f,%.4f\n", j, buyPrices[j], 
SellPrice[i], stickBuySellAt );
            fputs( op, fhLog );
          }
        }
      }
    }
    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] )
         )
      {
        // 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 ( writeLog == TRUE )
        {
          op = Name() + ",Bought";
          op = op + StrFormat(",%02.0f-%02.0f-%02.0f,%02.0f:%02.0f:%02.0f", y[ 
i ], m[ i ], d[ i ], r[ i ], e[ i ], n[ i ] );
          op = op + StrFormat(",%g,%.4f\n", j, buyPrices[j] );
          fputs( op, fhLog );
        }
      }
//      lastLow[j] = Min( Close[i], Min( lastLow[j], BuyPrice[i] ) ); // Set 
lastLow[j] for Buy Check, doesn't matter if we bought this bar, lastLow[j] 
won't be used in that case...
      if (    ( lastLow[j] > Close[i] )
           OR ( lastLow[j] > BuyPrice[i] )
         )
      {
        lastLow[j] = iif( BuyPrice[i] > Close[i] , Close[i] , BuyPrice[i] );
      }
    }
  }
}


Reply via email to