You do not need to code this, just make sure each bot has a unique label added when creating the order and in cTrader Automate, just export all the historical trades for all cBots into Excel then filter the label column for the bot you wish to see the sum total. Use an excel formula to calculate the sum of all trades.