Closing all open postiions

Questions about MultiCharts and user contributed studies.
janus
Posts: 747
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 83 times

Closing all open postiions

Postby janus » 27 Mar 2012

What does everyone now use to cover all their existing positions in a strategy? I've been using:

Code: Select all

buytocover all contracts next bar at market;
sell all contracts next bar at market;

and only execute these two statements once, not on every update tick or recalculation (using RecalcLastBarAfter). Is this still the correct approach, or is there yet another undocumented keyword to achieve the same thing in one go? As I stated I only execute them once since I've noticed some time ago during my stress tests a strange but very rare occurrence. if I executed them every time, I eventually may get a long or short opened for no apparent reason.

User avatar
JoshM
Posts: 2075
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1523 times
Been thanked: 1480 times
Contact:

Re: Closing all open postiions

Postby JoshM » 31 Mar 2012

janus wrote:What does everyone now use to cover all their existing positions in a strategy? I've been using:

Code: Select all

buytocover all contracts next bar at market;
sell all contracts next bar at market;

and only execute these two statements once, not on every update tick or recalculation (using RecalcLastBarAfter). Is this still the correct approach, or is there yet another undocumented keyword to achieve the same thing in one go? As I stated I only execute them once since I've noticed some time ago during my stress tests a strange but very rare occurrence. if I executed them every time, I eventually may get a long or short opened for no apparent reason.

I use a similar code segment, but I'm more comfortable resubmitting them every tick while there is a market position. In theory, they should also work when you only submit them once (i.e. for a one tick duration with IOG), but just in cause the order doesn't get through or there is some other quirk, I just keep resubmitting them until the market position is indeed flat.

I haven't experienced that they opened a position, so can't comment on that, though off course they shouldn't do that. :)

janus
Posts: 747
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 83 times

Re: Closing all open postiions

Postby janus » 31 Mar 2012

I've been sending them only once as you suggested and I also check MarketPosition_at_Broker to make sure it becomes 0 within a certain number of update ticks. If it fails to do so I send out alarms. I do the same with all my orders checking to make sure MarketPosition_at_Broker reaches the expected value. I do this as a constancy check for all my strategies. It has helped me uncover coding errors and a couple of bugs in MC itself, one of which I'm still trying to resolve, possibly due to a corrupted installation. I'll soon find out when the markets open again after I've done a repair then if necessary re-installed it.


Return to “MultiCharts”