It is not entirely clear what basketProfit means, as I understand it is an indicator of total profit, what will happen if basketProfit is equal to 1, will all transactions be closed or the transactions that are positive?

a month later

This is minimum profit when you close position and get profit. After than you start again with the new buy positions. it is loop.