total keyword in exit orders

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

total keyword in exit orders

Postby janus » 21 Mar 2011

I thought I understood the use of the total keyword in exit orders. I'll use an example.

Let's say I sellshort ("SS#1") 3 contracts next bar at market and the study eventually reports back it's net short 3 (using MarketPosition_at_Broker).

I then use a separate command to sellshort ("SS#2") 2 contracts next bar at market to be net short 5. The study eventually reports back it's net short 5. So far OK.

Then I issue a command to buytocover ("CS#1") 3 contracts total next bar at market.

Because I used the total keyword I expected to end up net short 2. Instead the system issues 2 orders, one to buy back 3 and the other to buy back 2 so ending up flat. I see on the plot two exit orders with the same label (#CS1).

According to the documentation the total keyword is used in strategy exit statements to indicate that only the number of contracts or shares specified by the numerical expression is to be sold or covered in total, regardless of the number of open entries. The contracts or shares will be sold or covered in the same order they were bought or shorted: First In, First Out.

What am I missing?

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

Re: total keyword in exit orders

Postby janus » 23 Mar 2011

Problem solved. The reason I was experiencing the results I described was because I kept on re-sending the buytocover order for too long. I have to stop re-sending it once the position according to the strategy matches what I expect. One could also use wait for the position according to the broker to match that of the strategy but I suspect that may lead to the same problem in very active markets. I prefer to stop the re-sending as soon as possible. I also tried to send it once off but that failed sometimes. I suspect it depends on what type of update tick the order is sent (eg, end of bar, start of a new bar, or repeated tick). Using my new approach appears to be the safest and best way.

After a long and exhaustive analysis using various approaches and stress testing techniques, I'm convinced users of MC that have IOG turned on should use extra caution. Steps should be taken to overcome certain peculiarities in the design of MC for studies that are updated on each tick. I find this to be the case with very inactive as well as very active markets, but for different reasons. When IOG is turned off things appear to be as stable as one could hope for. This is probably why I've noticed at least one person who made the comment they refuse to turn IOG on. I think if one takes the necessary precautionary steps, turning IOG on is safe although a pain in the proverbial backside. So, if MC ever wants to get serious with tick-based trading for the typical user who has little experience in these matters, there has to be a significant change in the way it works to make it simpler and safer to use. When I say tick-based trading, I'm not necessarily referring to high frequency forex traders, scalpers and the like. I'm referring to traders who simply turn on IOG for their strategies.

UPDATE

Turns out I only reduced not completely fixed the issue. More testing has revealed I must execute the exit order only once to avoid multiple exits completely. Repeating entry orders on the other hand appear to be safe, at least until the position at the strategy matches the expected value. Clearly MC managers entry and entry orders differently. Oh well, at least I figured out how orders are really managed (I hope). It only took me nearly a year :-)

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: total keyword in exit orders

Postby Stan Bokov » 12 Apr 2011

Thanks for your thorough investigation, Janus. I'm sure other traders can benefit from you sharing your experiences.

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

Re: total keyword in exit orders

Postby janus » 12 Apr 2011

Thanks for your thorough investigation, Janus. I'm sure other traders can benefit from you sharing your experiences.
Thank you Stan, I hope so too. Although in general writing code for MC is an easy process, and there are lots of documentation that provide good guides, this part of the implementation of signals is not discussed in any detail as far as I know, yet is critical in implementing reliable and successful trading rules. The way the orders work do make sense once one understands the way IOG and "next bar" orders operate together, but novice traders can easily go off course without this apparent assumed knowledge.

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: total keyword in exit orders

Postby Stan Bokov » 14 Apr 2011

The way the orders work do make sense once one understands the way IOG and "next bar" orders operate together, but novice traders can easily go off course without this apparent assumed knowledge.
Indeed. We are working on making MC a lot easier to use with new videos and docs - all we have to do is gather knowledge like this and organize it.


Return to “MultiCharts”