Buytocover not working properly

Questions about MultiCharts and user contributed studies.
NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 83 times

Buytocover not working properly

Postby NW27 » 12 Jan 2012

Hi,

[Intrabarordergeneration = true];
I enter a Short trade.
SellShort ("FX1S") 200000 contract next bar at ShortLevel stop;
This is fine, I'm now short 200,000
Marketposition =-1 Marketposition_at_broker = -200000

A Limit order (profit take) is now triggered
buytocover ("PS1_SX") 100000 contracts next bar at ShortExitLevel Limit;
This order works.
Marketposition =-1 Marketposition_at_broker = -100000

Now, no further orders work.
Ie I have a StopLoss order at a price level and it has disappeared.
I have a buytocover for the rest and it no longer works
buytocover ("EB_SX") next bar at market;

Marketposition =-1 Marketposition_at_broker = -100000


The actual code looks is

Code: Select all

MP=Marketposition_at_broker;
If (MP<0) AND (CurrentTime_S>ExitTradeTime) then
  begin
    buytocover ("EB_SX") next bar at market;
    print("111111111");
  end;


Guess what, the 11111111 get printed but the position doesn't close.
Still says Marketposition =-1 Marketposition_at_broker = -100000

Why is it so?

Neil.

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

Re: Buytocover not working properly

Postby Dave Masalov » 13 Jan 2012

Hello NW27,

Please send the full code (or at least a working sample) as well as the workspace you use to support@multicharts.com so we can test it on our end.

Squib
Posts: 17
Joined: 25 Nov 2011
Has thanked: 19 times
Been thanked: 6 times

Re: Buytocover not working properly

Postby Squib » 13 Jan 2012

Could it be, that you only allow one trade per bar?

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Re: Buytocover not working properly

Postby 2haerim » 13 Jan 2012

Several months ago, I had a similar problem with the following code.
The workspace was set to "Pyramiding up to 3 orders regardless of entry signals"

The chart clearly showed 3 exit arrows, but only one order was placed.
The answer for this issue I got was that MC does not allow more than one "market" order in case of pyramiding if I remember correctly.

Your case of IOG seems to be similar to this limitation, I think.

The solution for this was to modify market exit order code to stop/limit order code.

sell 1 contract total next bar c-1 limit;
sell 1 contract total next bar c-1 limit;
sell 1 contract total next bar c-1 limit;


Personally, I wish MC let users select whether to allow multiple market orders or limited numbers from Strategy properties or whatever.


Code: Select all

{**************************************************************}
{ Bar calculation                     }
var   :   barNum(0);
if currentbar = 1 then barNum = 0;
if date <> date[1] then value99 = currentbar-1;
BarNum = currentbar - value99;
condition11 = mod (BarNum, 5) = 1;
condition12 = mod (BarNum, 5) = 2;
condition13 = mod (BarNum, 5) = 3;
condition14 = mod (BarNum, 5) = 4;
 
if condition11 or condition12 or condition13 then begin
   buy this bar on close;  // will display 3 entry arrows
end;

if condition14 then begin
   sell 1 contract total this bar on close;  // executed ok
   sell 1 contract total this bar on close;  // discarded
   sell 1 contract total this bar on close;  // discarded
end;

setexitonclose;
These users thanked the author 2haerim for the post:
NW27

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 83 times

Re: Buytocover not working properly

Postby NW27 » 14 Jan 2012

Hi Dave,
I'm on a road trip for two weeks. When I get back I will send the info.

Hi Squib,
Thanks for responding. I do have it set to allow multiple trades per bar and I know this is working correctly from that perspective. Ie 100,000 in and 100,000 out, multiple times per bar works fine.
It only appears to be multiple exits that are causing the issue.

Hi 2haerim,
Thanks for responding. This could well be the problem. A good bit of info you posted there.
When I get back, I will look further into this and let every one know the result.


It would be nice if MC clarified/confirmed your statement of "The answer for this issue I got was that MC does not allow more than one "market" order in case of pyramiding if I remember correctly."
Dave ? Thoughts ???


Neil.

rainworm
Posts: 11
Joined: 19 Apr 2011
Has thanked: 3 times
Been thanked: 5 times

Re: Buytocover not working properly

Postby rainworm » 15 Jan 2012

NW27 wrote:It only appears to be multiple exits that are causing the issue.

I experience the same problem caused by multiple exits. The program code is processed properly (indicated by print-messages) but after the first partial exit no order is being shown in OPT-window. Market and broker positions are all right.

In live-chat Andrew took all of the signal sourcecode, workspace, logs etc. But till now no reply.

Last week I've seen another strange thing in OPT-window: when this issue stated above appears, the strategy open P/L isn't calculated any more. Symbol properties are set up right in quote manager. See screenshot attached (MC version 7.4)
Attachments
MC-partialexit.png
stragey open P/L not calculated any more
MC-partialexit.png (37.54 KiB) Viewed 414 times
These users thanked the author rainworm for the post:
NW27

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 83 times

Re: Buytocover not working properly

Postby NW27 » 16 Jan 2012

Rainworm,
Thanks for responding, let me know if you here anything.
Neil.

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 83 times

Re: Buytocover not working properly

Postby NW27 » 16 Jan 2012

Rainworm,
Thanks for responding, let me know if you here anything.
Neil.

ericvp
Posts: 30
Joined: 11 Jan 2012
Has thanked: 14 times
Been thanked: 6 times

Re: Buytocover not working properly

Postby ericvp » 17 Jan 2012

Hi Neil,

I think I had a related problem with pyramiding in and out of positions. 2haerim seems spot on with his suggestion, including the use of "total" (so your exit order is applied to only your oldest entry, instead of all of your entries), and having separate sell commands for your individual exits -- exercising the same code, even in a different bar, produced for me the same confusing lack of orders that you appear to be confronted with.

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 83 times

Re: Buytocover not working properly

Postby NW27 » 29 Jan 2012

Hi All,

Why can't we get some clear instruction from Multicharts on how the order system should be used?

Speak up Multicharts and let us know how to use your software WE have PAID for!

Neil.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Re: Buytocover not working properly

Postby 2haerim » 02 Feb 2012

Format Signal's Property provides a way to limit the max entry positions.
With this limit set, there seems no outstanding risks for unlimited exit orders.
So, I don't see why MC internal trading engine blocks multiple pyramidding market entry/exit orders.

Current MC's behaviour for this issue poses a few problems or more.
[1] Charts positions not matching with broker positions
[2] Charts positions not matching with strategy positions
[3] Extremely hard to find what went wrong when this happens.

I think all users want MC to work in the following simple way:
All signals you see in MC charts are sent to the brokers.

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

Re: Buytocover not working properly

Postby Dave Masalov » 06 Feb 2012

MC internal trading engine blocks multiple pyramidding market entry/exit orders


You cannot send more than one market order on one bar / one tick in IOG mode. It is implemented this way due to a number of factors. As a workaround you can monitor such situations in your script and create a united market order (sum of all market orders generated at each script calculation).
These users thanked the author Dave Masalov for the post:
JoshM

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Re: Buytocover not working properly

Postby 2haerim » 06 Feb 2012

You cannot send more than one market order on one bar / one tick in IOG mode. It is implemented this way due to a number of factors.

1) Well, would you kindly explain such factors in detail so that users can understand and accept this limitation is inevitable?
2) We already have a way to limit the # of entries in the Strategy Properties dialog. Why do we need additional hidden/unknown/undocumented limitation which confuses users a lot?

As a workaround you can monitor such situations in your script and create a united market order (sum of all market orders generated at each script calculation).

Numerically, 10,000 contracts are the same as 10*1,000 contracts. But for some special reasons(pyramidding or whatever depending on each user), one would like to place multiple split/partial orders as exactly shown in the chart. Would it be me only?

Would it be impossible to remove this limitation or at least give us a way to decide it ourselves at all?
Adding one more check box in the strategy properties will resolve this issue cleanly for all users.
By default, it will be disabled as it is now, and anyone who wants to enable can do that too.


thx

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

Re: Buytocover not working properly

Postby Dave Masalov » 08 Feb 2012

2haerim,

It is technically possible, but it is not a trivial feature from the development point of view. We will consider it for future implementation, however we do not see this feature as the one with the highest priority.

I'm on a road trip for two weeks. When I get back I will send the info.

Neil,

As far as I am concerned the fix provided to you by Henry solved the issue, is my understanding correct? This fix would be implemented in MC 8 Beta 1 which should be released soon.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Re: Buytocover not working properly

Postby 2haerim » 08 Feb 2012

As far as I am concerned the fix provided to you by Henry solved the issue, is my understanding correct? This fix would be implemented in MC 8 Beta 1 which should be released soon.


Can the fix be shared here?

User avatar
Henry MultiСharts
Posts: 8443
Joined: 25 Aug 2011
Has thanked: 1207 times
Been thanked: 2703 times

Re: Buytocover not working properly

Postby Henry MultiСharts » 08 Feb 2012

2haerim wrote:Can the fix be shared here?

The fix will be available in MC 8 Beta 1.
Please contact us directly at support@multicharts.com if you are interested in the hot fix.


Return to “MultiCharts”