Restrict trades to top position score signals

I have a follow up question to an issue that was addressed in this thread: Exploration Results differ from PositionScore choices using rankings from Static Variables - #13 by paulbruns

I have mean reverting systems that try and generate a signal on the first day, and then enter via a limit order the second day. In the prior post I had fixed an issue where it was using the position score from the wrong day. Now it's using the same position score both days, however I've found I have a different error.

The system is generating say 50 signals, and every day I take the top 10 and enter in those trades for potential execution. During the actual course of trading anywhere from 0-10 positions can be filled, usually just 1 or 2. I want to only look at the top 10 signals to see if they've executed. However I notice that the backtest is looking at all 50 trade signals that were generated and then, of trades that would have executed, assigning entry to the top 10 based on position score.

To put it differently the issue is that in real life the trade that ranks #11 isn't entered in to execute. But in the backtest it is assuming all trades are entered and just keeping the top ranked 10, so if trade #11 executes it puts it in the backtest. I'm noticing that many trades that I was unable to enter live are then being counted as executed even though they failed the position score.

My question is how do I restrict entry to the top 10 signals based on position score, instead of the top 10 trades?

I feel it's a little similar to the issue in this thread: Executed trades do not correspond with their position score however their issue was more for changing position score. I've gotten it so that the position score is the same for the signal and executed trade, but I can't find how to restrict trading to the top 10 position scores.

Some more information if it helps. This is a system that looks at stocks and attempts to generate multiple trades. They are ranked for entry the next day via a limit order. I'm only using 10 positions so I use the top 10 trades ranked via position score (or less if I have open positions). I'm finding that the trades that I actually take are showing correctly in the backtests, but that a lot of trades that failed to place in the top position scores are being added in that shouldn't be. Happy to try and include code if it helps but I think this is more of a setting issue perhaps? Please let me know if there is any other information that I can provide if it's helpful. I'm not sure if this is a setting issue, if this is an issue based on my code, or if it's based on using limit orders. Any help with identifying the correct root issue or a solution would be much appreciated!

To simulate only placing limit orders for the top (10 - open positions) setups each day requires the use of a custom backtest (CBT). There is no AmiBroker setting to model this behavior.

1 Like

Hi Mradtke,

Thank you very much for the quick reply! I guess you've quickly helped me determine that it's not a coding or process issue but a backtest issue. This is caused by using the limit orders I assume?

I have not used the custom backtester yet. I've been reading a bit about it: Porfolio Backtester Interface Reference

Is this a high level use case that shouldn't be too hard, or is this a complex thing to try and learn and code? I'm just trying to determine if it would be easier for me to learn how to write a custom backtest or try and modify my trading system to not use limit orders.

That really depends on your background and coding skills. It's definitely not trivial, but conceptually it's not that difficult once you understand the basic structure of the CBT.