During development I have used two different methods to close a position but I get different results.
Method 1. close a position using the system takeProfit defined when the position is opened
engine.submitOrder(label, instrument, orderCmd, amount, price, slippage, stop, takeProfit);
Method 2. close a position manually within the onTick() method (when certain price level is reached) using
this.order.close();
However even when I use the same takeprofit price level the positions are closed at different locations - see attached file showing the two methods and the close positions.