Hi

I'm trying to learn how to use AmiBroker's Custom Backtester as I believe the 
system I'm coding will need to use the low level interface.

In order to understand the CBT fully I'm starting off simple, running trace's 
etc to see how it works. I have a very simple trading system which buys on the 
open and sells on the close. I'm trading index futures and for backtesting 
purposes I only want to trade a single contract.

The problem I'm experiencing is that when I run a backtest on the code below in 
Automatic Analysis no trades appear in the trade list. However, if I comment 
out the line ...

PositionSize = MarginDeposit = 1; // Trade size will be a single contract

... then I get a trade everyday although the position size is all wrong as it's 
not trading one futures contract.

I've spent a couple of days trying different ways of trading just one contract 
but I'm not getting anywhere. Does anyone have any idea what I'm doing wrong? 
Any help would be appreciated.

Thanks

Craig


// Money Management
InitialEquity = 10000;
SetOption( "InitialEquity", InitialEquity ); // Set initial equity
SetOption( "FuturesMode", True ); // Ensures trade accounting is done using 
margin deposit and point value
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 25); // Commission amount per trade (dollars)
PositionSize = MarginDeposit = 1; // Trade size will be a single contract
PointValue = 25;

// Entry/Exit Signals
BuyPrice = Open;
SellPrice = Close;
Buy = Open;
Sell = Close;
Short = 0;
Cover = 0;

SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
    bo = GetBacktesterObject(); // Get backtester object
    bo.PreProcess(); // Do pre-processing
    for( i = 0; i < BarCount; i++ ) // Loop through all bars
    {

        for( sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i) )
        { // Loop through all signals at this bar
            if( sig.IsEntry() && sig.IsLong() ) // Process long entries
            {
                bo.EnterTrade( i, sig.Symbol, True, sig.Price, sig.PosSize );
                _TRACE("Entry signal = " + i);
            }

            else
            {
                if( sig.IsExit() && sig.IsLong() ) // Process long exits
                    bo.ExitTrade( i, sig.Symbol, sig.Price );
                    _TRACE("Exit signal = " + i);
            }

        } // End of for loop over signals at this bar
        bo.HandleStops(i); // Handle programmed stops at this bar
        bo.UpdateStats(i, 1); // Update MAE/MFE stats for bar
        bo.UpdateStats(i, 2); // Update stats at bar's end
    } // End of for loop over bars
    bo.PostProcess(); // Do post-processing
}

Reply via email to