slow to close open positions
Posted: Mar 06 2011
I have a signal study that uses the following commands to cover all contracts regardless of the current position.
sell ("CoverL") all contracts next bar at market;
buytocover ("CoverS") all contracts next bar at market;
I've noticed when the strategy is live (ie, automatic order execution turned on) it sometimes takes several seconds for the positions to be closed despite the fact the chart has updated a number of times with new tick data. The worst example I saw was it took about 20 seconds in a very active market. The strategy is using IOG. I put this down to a delay in IB confirming the close order has taken place. Now I'm not so sure. When I use "close all positions" in TWS directly the orders are closed almost immediately each time. I'm testing all this with the simulation account. I've used print statements to debug my code and it sends the above two statements many times before the open positions are closed. So, I tried another test. I changed my code to execute the above two commands only once instead of executing on each and every tick update until the positions are closed. Now it's working fine. So, it appears sending the above two commands more than once can be a problem. The odd thing though it was all working fine before the changes when automatic order execution is turned off. Anyway, the problem appears to be fixed now. Not sure if others are doing the same as what I did, but if so be warned.
UPDATE: Not sure if I have fixed it - doing some more testing. Meanwhile, if anyone has any suggestions please post. I will update once I've completed my tests.
UPDATE2: Looks like I have a more fundamental issue with all types of orders. I'm going over to PM.
sell ("CoverL") all contracts next bar at market;
buytocover ("CoverS") all contracts next bar at market;
I've noticed when the strategy is live (ie, automatic order execution turned on) it sometimes takes several seconds for the positions to be closed despite the fact the chart has updated a number of times with new tick data. The worst example I saw was it took about 20 seconds in a very active market. The strategy is using IOG. I put this down to a delay in IB confirming the close order has taken place. Now I'm not so sure. When I use "close all positions" in TWS directly the orders are closed almost immediately each time. I'm testing all this with the simulation account. I've used print statements to debug my code and it sends the above two statements many times before the open positions are closed. So, I tried another test. I changed my code to execute the above two commands only once instead of executing on each and every tick update until the positions are closed. Now it's working fine. So, it appears sending the above two commands more than once can be a problem. The odd thing though it was all working fine before the changes when automatic order execution is turned off. Anyway, the problem appears to be fixed now. Not sure if others are doing the same as what I did, but if so be warned.
UPDATE: Not sure if I have fixed it - doing some more testing. Meanwhile, if anyone has any suggestions please post. I will update once I've completed my tests.
UPDATE2: Looks like I have a more fundamental issue with all types of orders. I'm going over to PM.