Confusion with buy and sell orders

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

Confusion with buy and sell orders

Postby janus » 22 Dec 2009

I'm confused on some of the aspects of submitting buy and sell orders. When I submit a buy order as follows:

buy ("Gone long") nbuy contracts next bar at market; where nbuy = 3

It works as expected. Then my study at some time in the future may want to close 1 contract out of the 3 thus:

sell ("Covered long") nsell contracts total next bar at market; where nsell = 1

It works as expected. Then the study may do it again to close another one using the same command. It fails. I believe it's because you can't have multiple orders applied to open contracts using the same exit label. If I use use a different label it works fine. However, I can't use different labels since the number of times my study may close open contracts varies. It's a pity the labels can't be string variables so I could get around it by updating a number in the string. So, what else can I do? It does not help to leave out the exit label.

According to the documentation, if EntryLabel is not specified, all of the open long entries will be closed. Well this does not actually happen since I know that after closing one position, 2 remain according to the currentcontracts strategy position keyword. Anyway, I don't want to tie the order to a previous order as there could be more than one entry order.

Maybe I'm missing something - all I need is a simple and straightforward order to close some of the open positions, which can be used more than once. Any ideas? Also, I'm still using version 5.0. Will 5.5 help?

Dug
Posts: 31
Joined: 26 Aug 2009
Location: London

Postby Dug » 22 Dec 2009

Hi, from memory i had this problem - I just did a work around whereby I had numerous strategies for each contract.
That way Strategy 1 would buy 1 contract at Y and sell at X, Strategy 2 would buy 1 contract at Y and sell at X2, etc;
Since then I have not revisited it, but from memory I think one of the upgrades did address this problem (however I did not check as I kept with the original coding I used)

janus
Posts: 755
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 84 times

Postby janus » 22 Dec 2009

Thanks Dug. I suppose that will work for small numbers but if I buy say 100 contracts that means 100 strategies. Although I don't trade stocks with MC this workaround would not be practical at all. I'll upgrade to 5.5 to see if it helps. It better!

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 22 Dec 2009

janus,

I remember sometime back someone had asked similar question and Marina provided a solution, I suggest, go through Marina's post on this forum and you may find what you are looking for.

you can code something in this fashion:

if CurrentContracts=3 then sell nsell contracts next bar at market // nsell=1, you are left with 2
if CurrentContracts=2 then sell nsell contracts next bar at market // you are left with 1...

and so on

janus
Posts: 755
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 84 times

Postby janus » 22 Dec 2009

Thanks SUPER. I tried your suggestion and it appears to work. I will use this approach for now with around 200 statements as I don't expect to trade more than that many for now. By having separate although identical statements, the signals are treated as if they were with different exit labels.

I like to make a comment. To be honest I don't like the way all this works. If this is all built-in to EasyLanguage and nothing can be done then I'm afraid MC will never become very popular. Traders must have flexible AND simple order types that work the same way as if they manually placed the orders directly into the broker's tool. They often just want to buy and sell various lots at various times with no restrictions tied to how many can be sold or bought to cover existing open positions. It's a basic requirement of any trading tool, automatic or manual. I don't see any manual tool have such restrictions. It just doesn't make sense. I'd be surprised if TS hasn't fixed this restriction. I suggest if MC hasn't fixed this lately that they do. If necessary, define two new keywords that override the built-in order types.

Emmanuel
Posts: 287
Joined: 21 May 2009
Has thanked: 68 times
Been thanked: 19 times

Postby Emmanuel » 23 Dec 2009

Hi,

It 's happen to me also, after trading 4 days with IB real time,

MC 5.0 sent an order to buy to cover, but instead , in the IB software,
received, a sell order !!!

I was suprise, it was unexpected, then the IB software crash, I had to restart the IB sofware.

Maybe there was problem of communication between MC5 and IB after few days ? :?:

Another time, IB stop to receive the order from MC 5.0, I didn't see it at first, because MC was working normally and was stable without error message, but as I try to click on IB software, IB Soft froze.

It is quiet rare. but it is important to make sure, the IB MC connection is still alive.

Emmanuel

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 23 Dec 2009

Emmanual,

These days I reboot my PC every day just to make sure that I don't face problems you have described.

I have to say that MC is very stable....some of the problems creep in due to internet connection and I don't think there is any way around it.

Emmanuel
Posts: 287
Joined: 21 May 2009
Has thanked: 68 times
Been thanked: 19 times

Postby Emmanuel » 23 Dec 2009

Hi Super,

I understand, but it would be even better if you had to restart only once during the week end . :)

Emmanuel

janus
Posts: 755
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 84 times

Postby janus » 25 Dec 2009

Emmanuel, the problem you described has nothing to do with what I'm describing. The issue I have is always there but does not crash or cause any other interference to how MC operates, other than what I've outlined. If you need further clarification, please let me know. In fact I've found MC very stable.

User avatar
TJ
Posts: 6585
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1907 times

Postby TJ » 25 Dec 2009

Hi,

It 's happen to me also, after trading 4 days with IB real time,

MC 5.0 sent an order to buy to cover, but instead , in the IB software,
received, a sell order !!!
...


Computers are dumb,
it will only do what you instruct it to do.

Please add this code to your signal.
It will make a log of all the triggered orders.
You can then compare it to the TWS log to see how they match.



if condition1 = true then
begin
sell ("S1") next bar market;

print(currentdate, ", ", currenttime_s, ", S1, ", c);
end;



User avatar
TJ
Posts: 6585
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1907 times

Postby TJ » 25 Dec 2009

Emmanual,

These days I reboot my PC every day just to make sure that I don't face problems you have described.

I have to say that MC is very stable....some of the problems creep in due to internet connection and I don't think there is any way around it.

Hi Super,

I understand, but it would be even better if you had to restart only once during the week end . :)

Emmanuel



Even InteractiveBrokers reboot their computers everyday,
what makes you think you can get away with once a week?

You have hundreds of other things running in your computer,
any one of the services can interfere with MC or TWS without you knowing it.

janus
Posts: 755
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 84 times

Postby janus » 25 Dec 2009

You have hundreds of other things running in your computer,
any one of the services can interfere with MC or TWS without you knowing it.


Yes, this is why I like to buy another PC to dedicate it only to using IB and MC. Even then I'll still probably reboot it once a week just in case.

Getting back to the original topic, it appears there's no way to submit a simple order to cover any quantity of contracts or shares using MC. I'm really amazed. I really like MC for a number of reasons but this simple yet extremely common requirement of any package, be it manual or automatic is really annoying. So annoying in fact I'll have to look for another package once I become a professional trader. There is no way a true professional would use MC with such a limitation. I suppose that's where I possibly made a mistake - I thought MC was meant for all types of traders, including professionals.


Return to “MultiCharts”