Limiting Re-entries per Symbol in Intraday Portfolio Backtests

Hi,

I'm new to the community and seeking some advice.

I’m working on limiting the number of re-entries per symbol per day in an intraday portfolio backtest. I currently use ApplyStop to manage stop-losses, as shown below:

ApplyStop(stopTypeLoss, stopModePoint, stopAmountShort, 1);  

I found this knowledge base article that outlines three methods to achieve this, but I’ve run into issues with each:

  1. Option 1:
    This method doesn’t suppress consecutive signals like short-short-short-cover. For example, suppose signals are generated at 8:30, 8:31, and 8:32, with an entry at 8:30 and an exit at 9:00. The counter counts all signals (3 in this case), which prevents re-entry after the exit at 9:00 if the limit is set to 3.
  2. Option 2: Using Equity(1):
    The Equity() function is described as a "single-security backtester-in-a-box." I tried using it but encountered unexpected results. Since it seems intended for single-security backtesting, I didn’t dive deeper. If my understanding is incorrect, please let me know—I’d be happy to share my code and findings.
  3. Option 3:
    This approach works but has a limitation: when stops are triggered, the cover variable is not set to 1, preventing new positions from being initiated.

Additionally, I tried using SetMaxOpenPosition, but it didn’t work for my use case. My scenario involves trading on n different stocks each day, with a limit of m entries per stock. Since I don’t know the value of n in advance, this method would allow a single stock to take more trades than intended (as long as the total trade count across all stocks stays within the limit of m * n).

Given these challenges, I’m considering a couple of alternative approaches:

  • Would it make sense to create a custom backtester to better handle this scenario?
  • Alternatively, should I look into managing stop-losses manually without relying on ApplyStop?

Any suggestions or guidance on this issue would be greatly appreciated.

Thank you!

ApplyStop has argument "ReEntryDelay" that allows to define number of bars to wait till entering the same stock is allowed.
https://www.amibroker.com/guide/afl/applystop.html

If you want to limit the number of entry signals per symbol per day, that can be achieved in Phase 1 with the Equity function. However, if you want to limit the number of entries per symbol per day, then you need a CBT because only during Phase 2 of the backtest will you know whether signals actually became entries.

1 Like

Thank you both for the insights and suggestions!

Hi Tomasz, I’m not sure how ReEntryDelay would address my issue. The only approach I can think of is to calculate the delay dynamically by dividing the total bars available in a day by n = allowed_entry. However, this would restrict re-entries to specific times of the day, which isn’t quite what I’m looking for. My goal is to allow n re-entries after an exit or stop-out, ideally after just 1 bar.

Thanks, mradtke—I’ll look into using a custom backtester (CBT) for this.

It would be really helpful if there were an option to configure this directly, similar to SetMaxOpenPosition, as it would make implementation much simpler.

Thanks again for the suggestions—I’ll explore these further!

1 Like