Identifying why not all trades taken in simulated backtest

I'm looking to generate an equity curve by using some closed trades coded into amibroker. However not all of the trades are taken. I'm trying to identify why not all of the trades are taken. Code is shown below. The one security that it does enter is entered and exited on the correct dates at the correct price, just i'm at a loss to identify why others are not being taken.

Any ideas of where to look are greatly appreciated.

SetOption( "initialequity", 1000000); //set big to ensure we have enough funds for backtest
SetPositionSize( 10000, spsValue );

SetBacktestMode(backtestRegularRawMulti); // to allow multiple open positions on the same symbol
SetOption( "MaxOpenPositions", 100 ); //  loosened the value for better chance of isolating failure 


	
if(name() == "PDI.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	0.21	;  sell = year() ==	2021	    and month() == 	12	  and day() ==	1	;	sellprice = 	0.240	;}
if(name() == "BOE.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	1.8	;  sell = year() ==	2021	    and month() == 	11	  and day() ==	30	;	sellprice = 	2.720	;}
if(name() == "360.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	11.13	;  sell = year() ==	2021	    and month() == 	12	  and day() ==	14	;	sellprice = 	11.750	;}
if(name() == "TLX.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	6.47	;  sell = year() ==	2021	    and month() == 	12	  and day() ==	7	;	sellprice = 	6.620	;}
if(name() == "LOV.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	18.72	;  sell = year() ==	2021	    and month() == 	12	  and day() ==	3	;	sellprice = 	20.610	;}
if(name() == "AEF.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	12.97	;  sell = year() ==	2021	    and month() == 	12	  and day() ==	14	;	sellprice = 	12.490	;}
if(name() == "360.au"){buy = year() ==	2021	and month() == 	11	 and day() == 	29	; buyprice =  	10.18	;  sell = year() ==	2021	    and month() == 	12	  and day() ==	14	;	sellprice = 	11.750	;}

@flash007 one potential cause is the wrong settings of the filter dialog.

Check your filter dialog and ensure that in the tab "Exclude" there are no active selections:

and that the tickers that you are referencing in your code are actually included" (for example 360.au that alphaebetically should be at the beginning of the filter watchlist).

1 Like

I assume you are running against a watchlist that contains all the symbols of interest, correct? If so, try running a Scan to see if you’re actually generating the entry and exit signals that you are expecting.

Beppe & mradtke, thanks for your input. I’ve made sure the database I used to generate the trades is the same one used in the backtest, and all symbols are available (by running an exploration). So no symbols excluded. Also, I ensured the dates were valid by selecting “All quotes”.

I also tried re-installing Amibroker, and got exactly the same results. So it’s not to do with the settings. I’ll keep playing. It’s got to be something simple

Did you check PAD & ALIGN ? The symbol used has all bars ?

2 Likes

What did the Scan show?

Hi, Did you resolve your issue?

Late to the party as usual but I just ran a backtest using your code and got 6 trades, 1 in each of the 6 stocks.

On examining the code this is what I would expect. The second Buy on stock '360.au' on the same date overwrites the first.

John.

Generally:

Run your code in "DETAILED LOG" mode.

There are ALL signals generated in first phase that are accepted (note that only upto 2 * MaxOpenPositions items are shown in the entry signal list, sorted by position score. PositionScore is crucial for prioritizing trades).

:arrow_right: If there is no signal on entry list, then obviously it won't open a trade.

:arrow_right: If there is a signal but other constraints disallow opening position - you will see that in the detailed log.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

1 Like