Backtesting an imported trade list into AmiBroker

I am using the code from AmiBroker Knowledge Base » 2014 » September to import a list of trades into AmiBroker, so I can generate statistics on these trades. The trades seem to get imported correctly, a Scan shows the trade signals are there. However, when I run a backtest, while it picks the trades, it doesn't implement them, as it says possize is zero:

Date Information
16/06/2020
Entry signals(score):SLR.au=Buy(1),
Exit signals:
SLR.au not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 1.91, reqEntryPosSize: 0 shares (value = 0), reqLotSize: 1)
0 Open Positions: , Market Value: 0.00, Equity: 100000.00, Cash: 100000.00, Margin: 0.00, Net Cash Balance: 100000.00,

The imported trade list had the number of shares, but it doesn't seem to have gone through to the backtester, and I haven't been able to figure out why yet.

SLR.au,Buy,15/06/2020,1.91,7350.00
ELD.au,Buy,16/06/2020,9.34,1540.00

Any ideas/suggestions?

That would imply your SetPositionSize call didn't work as you intended. I suggest using an Exploration to see what's going on.

1 Like

The message is pretty clear. In the PositionSize you specified ZERO shares. It can't open position with ZERO shares.

It might be because the code that you copied assumes that date/time stamps in the file correspond to EXISTING data bars in the database you have.
If there is no exact match between date/time in the external file and in your database you are going to have problems because of the lines:

 if ( trade == "Buy" )
             {
                 newbuy = dt == trade_datetime; // ONLY WORKS IF there is a match!
                 Buy = Buy OR newbuy; // combine previous buy signals with new
                 BuyPrice = IIf( newbuy, price, BuyPrice );
                 possize = IIf( newbuy, shares, possize ); // ONLY WORKS IF there is a match!
             }

Check your data. Pay attention to the fact that your external file has date/times without TIME part, so it expects EOD ONLY records in DB.