Same bar reentry at price that is not better than exit

Hello everyone !
First of all , sorry for stupid questions again . I use AB for 10 years and despite being an oracle's java certified programmer , it's still a black box for me. I know that product is clearly superior in terms of speed so thanks Tomacz for an excellent software but some things are just beyond my understanding and I gave up about that a long time ago. It seems that it's just limitation of my brain )) So the question is like that -

Let's imagine that we trade some breakout system and price is constantly rising. So we initiated a long position at 100/share. We have 10pct takeprofit. Market continues to rise so all highs and closes are higher with each bar. We constantly have Buy signals every bar but we limited AB to 1 long position so we just wait for takeprofit. Then finally we have bar with open at 104 and close at 120. Obviously we have takeprofit at 110. But the thing is that we want to reenter at the same bar and BuyPrice for that bar was 105. We shouldn't fool ourselve and allow AB to exit at 110 and also initiate new long at 105 cuz we didn't knew at 105 that we will close first position soon at 110. So we should enter in new long position with

BuyPrice=max(NewPositionEntrySignalPrice,TakeProfitOfPreviousPosition);

The problem is that catching TakeProfitOfPreviousPosition is quite a sophisticated task. I can't get it without CBT and if I declare new variables inside CBT , I can't use them outside of CBT.

Should I go through all closed positions in CBT , then compare exit dates with entry dates and use

sig.price()=max(sig.price(),StoredExitPriceofPrevTrade); 

?

I thought even about writing all trades in CSV file on memory drive then executing python script that will check prices and change them properly and then finally reading new file and executing trades, all inside one AFL script but it will be extremely slow due to constant I/O operations ...

Any ideas ? Thanks a lot again !