That should be easy. You need not even accumulate the PL, the total profit is WinTotal. For printing to the console, use printf() or print() in a backtest. You can also write variables to a file. Without knowing your script I can't say why your objective function does not work.