Sending only top ranked buy signals to the backtester

I have an end of day strategy where every evening I generate a list of potential trades for tomorrow. The strategy buys at limit a certain distance below today's price action. This means that out of a large list of signals (eg. 80) only a few may fill (eg. 4). I have a maximum number of open positions equal to 10.

What I would like to do is rank my signals and place the top 10 trades only in the market tomorrow. This could mean that some trades outside of the top 10 may have triggered but I will miss them and that is the intention.

Therefore in my backtesting I would like to send only the top 10 ranked signals to the backtester. Any signals that fall outside of the top 10 are never placed in the market hence I do not want to send them to the backtester. How do I achieve this?


AmiBroker does that for you automatically. You just define PositionScore variable in your formula and rest is taken care of (AmiBroker performs ranking and only sends top ranked signals to second phase of backtest)

For a strategy using limit orders, I suggest you review this entire post: PositionScore / Ranking for trades taken “next day at limit”

1 Like

But I can't know the order of which limit orders will be filled tomorrow so PositionScore won't do what I need.

I could have 50 orders and the top ranked 10 may not be the ones that fill. It could be say 5, 17, 22, 35 and 41. However I only want to place rank 1-10 in the market therefore only order rank 5 in my example will only be filled.

I know this can be done with the CBT I just don't know how.

Thanks Matt - will have a read.

Generally, it is advised not to use limit orders when you use ranking. There are dozens of reasons. Most important is that such backtesting becomes unrealistic when you have lots of orders that hit limits (exceeding buying power), because limits get hit in different time of the day in real life and you will end up entering different positions depending on timing inside bar. This plus other factors cause that limit orders add unpredictable (random) element that you don't control. Attempt to code that by checking which orders were filled is in my opinion wasted effort as you are just going into looking into the future territory. The only reliable way it to scale orders down so you have enough buying power to open all possible buying candidates regardless if limits are hit or not. This will remove intra-bar time dependency. This article shows some code: