many thanks for posting this.
I have tried this code in a short-term system I have which can be in and out of a trade in a single day, or can hold positions for 2-4 days, depending. The problem I am having is that I may come into a session with 10 open positions, 1 may be exited on the open, then another 2 positions will be established at the open which are exited at the close and a 3rd position is established which is held, leaving me with 10 open positions at the end of the day which accords with the max open positions allowed.
However, coming into the session with 10 OPs and exiting 1 on the open means in reality I can only take one new position, but because the 2 positions I established during the day were exited on the close of the same day, according to the code I haven't breached my max OP limit of 10 OPs, even though this would not be allowed to happen in actual trading!
I have tried to apply your sample code above in the backtesting section of my AFL, but when I run it, I get exactly the same number of trades, all identical, even though I can see many days when this piece of code should be limiting the number of positions in the backtest.
Would you have any idea what I might be doing wrong? Is there a specific place in the AFL that this block of code needs to be placed? I was thinking that perhaps the max OPs needs to be handled inside the looping section of code which controls the system's logic somehow?
Many Thanks and Regards,