I am currently attempting to write a Pair Trading Algorithm based on the Johansen Test. Using order_target_percent each of the pairs in the algorithm below worked without any problems. But when I calculate the orders directly there seems to be some error. I would highly appreciate it if someone would take a look.