Buy when cash available

When a buy signal is generated in chart the account may not have enough funds available but on the very next bar funds may become available ( due to some other position getting closed, blocked margin getting released etc). Let me give an example. Assume we are portfolio backtesting.

  1. At 10:05 am signal is generated for stock AAA.

  2. In CBT when this signal is processed it is found that account does not have enough cash available to buy the required quantity. So signal is rejected by cbt.

  3. At 10:10 am an open position in stock BBB is closed which releases funds back to the account. As a result now the account has enough cash to execute order in Stock AAA that it rejected earlier. But since there is no signal for Stock AAA at bar 10:10 am it does not buy.

How do we handle such scenarios? How can I build logic to buy when cash becomes available?