slow to close open positions

Questions about MultiCharts and user contributed studies.
janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

slow to close open positions

Postby janus » 06 Mar 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.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: slow to close open positions

Postby Dave Masalov » 16 Mar 2011

Dear janus,

The situation that you have described is understandable. It is normal behavior. If you send orders on every tick in IOG mode, this means that MultiCharts sends a group of order every tick - several groups of orders every second in active market. That is why MultiCharts simply cannot close the positions immediately on the next tick as it sends a new group of orders on every tick. When you use "close all positions" in TWS, you send orders once just as when you execute the your commands only once instead of executing on each and every tick update until the positions are closed.
UPDATE2: Looks like I have a more fundamental issue with all types of orders. I'm going over to PM.
Could you please be more precise? If you have submitted an issue to PM, please post the link.

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: slow to close open positions

Postby piranhaxp » 16 Mar 2011

Janus .... order management delay most of the time is a "coding" issue from your strategy in Multicharts. I experienced simple "coding" rules have to be implemented to increase performance in MC with your strategy calculations.

Regards.

Mike

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: slow to close open positions

Postby janus » 16 Mar 2011

Dear janus,

The situation that you have described is understandable. It is normal behavior. If you send orders on every tick in IOG mode, this means that MultiCharts sends a group of order every tick - several groups of orders every second in active market. That is why MultiCharts simply cannot close the positions immediately on the next tick as it sends a new group of orders on every tick.
This at first appears to contradict what you said on another recent post but:
When you submit exactly the same orders on the next bar, orders sent on the previous bars are not cancelled but stay at broker and so MC does not send the new ones (if the quiantity of orders, contracts and price is exactly the same). So, in IOG, once the condition has been met, it is better to place exactly the same order on every tick until the condition is valid.
So, are you saying sell all contracts next bar at market and buytocover all contracts next bar at market causes MC to re-send basic sell/buy orders of the appropriate amount to close existing positions on each update tick to IB until completed, but standard orders that don't change are only sent once to IB even though the study repeats the orders? If this is so it would explain why sometimes I see a double up on the order to close open positions. In other words, if I were long 1 contract and wanted to cover it, on very rare occasions I will end up being net short 1 position instead of flat due to some kind of race condition. Perhaps a better solution for me is to make the study itself issue basic sell/buy orders of the right amount to cover all open contracts, rather than relying on the "all" keyword. Would this help, assuming there is a problem?

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: slow to close open positions

Postby Dave Masalov » 17 Mar 2011

Dear janus,

What I was talking about in the other post is the conversion mechanism which applies only to price orders with the same price and quantity. Market orders are sent every bar (or every tick in IOG mode).
Perhaps a better solution for me is to make the study itself issue basic sell/buy orders of the right amount to cover all open contracts, rather than relying on the "all" keyword.
When you use "all" keyword, MC calculates the number of all open contracts anyway, so it should not change the situation.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: slow to close open positions

Postby janus » 17 Mar 2011

I think what's confusing me is when you say "market orders are sent on every bar/tick" when I thought it depended on the properties of the strategy. If the position limits is not set I think multiple entry orders in the same direction are disallowed regardless of how the code is written. If the position limits is set to allow up to 10 entry orders in the same direction as the currently held position when the order is generated by a different entry order, then multiple orders are allowed up until the total contracts filled is 10, but if the same command that successfully submitted an order is repeated by the study (even if the quantity has changed) it is ignored. If the position limits is set to allow up to 10 entry orders in the same direction as the currently held position regardless of the entry that generated the order, multiple entry orders are allowed including those generated by the same command, up until the total contracts filled is 10.

All this assumes Format -> IOG of the study is set to "Allow unlimited entries and exits per bar".

Now, for "cover all" orders at market. I issue a command to "cover all", and it's subsequently repeated on each and every update tick in my IOG study. Does MC on the first tick when the "cover all" order is placed computes how many to cover (10) and then sends a GTC market order once off for IB to sell 10 contracts?

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: slow to close open positions

Postby janus » 19 Mar 2012

It's been a year since anyone has made a comment and answered my question here. Anyone dare to comment on such a critical part as order management when pyramid type strategies are used? Those who pyramid their orders would be well advised to take note on these various settings and how they actually function. I believe the way MC managers orders and tick updates is now so complicated it has become a nightmare trying to figure out what exactly one has to do to perform pyramid trades (entry and exit) successfully without a lot of trial and error. I've noticed pyramid type questions have been posted before but the answers were often vague or incomplete. I think this deserves a separate and dedicated topic for discussion to assist others and avoid re-inventing the wheel, and if supported I will start a new thread.


Return to “MultiCharts”