AUTOTRADING PROBLEM

Questions about MultiCharts and user contributed studies.
ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

AUTOTRADING PROBLEM

Postby ppan » 11 Jan 2011

I have a 1 min chart with the following system:
------------------------------------------------------------------------------------
IF MARKETPOSITION = 0 THEN BEGIN
BUY ("B1") 1 CONTRACTS NEXT BAR AT MARKET;
BUY ("B2") 1 CONTRACTS NEXT BAR AT MARKET;
END;

IF MARKETPOSITION = 1 THEN BEGIN
SELL ("S1") 1 CONTRACT TOTAL NEXT BAR AT MARKET;
SELL ("S2") 1 CONTRACT TOTAL NEXT BAR AT MARKET;
END;
------------------------------------------------------------------------------------
I have enable the "ALLOW UP TO "10" ENTRY ORDERS IN THE SAME DIRECTION AS THE CURRENTLY HELD POSITION" in Strategy Properties.

There is no problem with the chart. The chart has 2 buy orders and 2 sell orders each time. However, when MC auto trade with IB, it send only 1 BUY order to IB.

Is it a bug?

rondot samuel ws
Posts: 103
Joined: 05 Sep 2007
Has thanked: 8 times
Been thanked: 6 times

Re: AUTOTRADING PROBLEM

Postby rondot samuel ws » 12 Jan 2011

Hi,

have a look on :

file / new / Order and position tracker

check Strategy orders and logs



ppan wrote:I have a 1 min chart with the following system:
------------------------------------------------------------------------------------
IF MARKETPOSITION = 0 THEN BEGIN
BUY ("B1") 1 CONTRACTS NEXT BAR AT MARKET;
BUY ("B2") 1 CONTRACTS NEXT BAR AT MARKET;
END;

IF MARKETPOSITION = 1 THEN BEGIN
SELL ("S1") 1 CONTRACT TOTAL NEXT BAR AT MARKET;
SELL ("S2") 1 CONTRACT TOTAL NEXT BAR AT MARKET;
END;
------------------------------------------------------------------------------------
I have enable the "ALLOW UP TO "10" ENTRY ORDERS IN THE SAME DIRECTION AS THE CURRENTLY HELD POSITION" in Strategy Properties.

There is no problem with the chart. The chart has 2 buy orders and 2 sell orders each time. However, when MC auto trade with IB, it send only 1 BUY order to IB.

Is it a bug?

ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

Re: AUTOTRADING PROBLEM

Postby ppan » 12 Jan 2011

Hi,

I have checked the logs. Only "B1" and "S1" signal in the log.

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

Re: AUTOTRADING PROBLEM

Postby janus » 12 Jan 2011

I think it's a limitation of IB but not 100% sure as there may be ways to submit multiple orders at the same time to IB but MC isn't taking advantage of that possible feature. Someone from MC should be able to respond on this matter. The only way around it for now is to turn on intrabar order generation and send out the first buy order when barstatus = 2 (ie, at the last tick of the 1 minute bar) then send the next buy order on the next tick. It's not 100% what you are looking for but is close. If there is a way to achieve exactly what you want I would be interested too as I may want to do the same one day.

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

Re: AUTOTRADING PROBLEM

Postby Dave Masalov » 25 Jan 2011

Dear Sirs,

It is not possible to send more than 1 market order on the first bar in auto trading mode.

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

Re: AUTOTRADING PROBLEM

Postby janus » 25 Jan 2011

Thanks Dave for the confirmation.

What I don't understand though is why not? After all, we are allowed to submit multiple buy orders on separate ticks (IOG turned on) with different labels like:

if bl.index = 1 then buy ("buy long #1") qty1 contracts next bar at market;
if bl.index = 2 then buy ("buy long #2") qty2 contracts next bar at market;
if bl.index = 3 then buy ("buy long #3") qty3 contracts next bar at market;
bl.index = bl.index + 1; // intrabarpersist variable initially set to 1

and we can manage the exists for each of the 3 entries accordingly. So for completeness we should be able to do the following all in one tick:

buy ("buy long #1") qty1 contracts next bar at market;
buy ("buy long #2") qty2 contracts next bar at market;
buy ("buy long #3") qty3 contracts next bar at market;

and again we can manage the exists for each of the 3 entries accordingly.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 25 Jan 2011

MC Team - This is not an out of ordinary situation and should be addressed as soon as possible unless there are any technical reasons not to allow this.

Would you please describe - the reasons behind not allowing this kind of orders?

Thanks

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

Re: AUTOTRADING PROBLEM

Postby Dave Masalov » 26 Jan 2011

Dear Sirs,

We understand that this limitation may seem artificial. However, could you please tell us why exactly do you need this feature? What goals are you trying to achieve?

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

Re: AUTOTRADING PROBLEM

Postby janus » 26 Jan 2011

Hi Dave.

I think the point is as follows, at least from my humble opinion. MC's method of handling orders prevents a study from executing the same buy long or sell short order, presumably so it can track the order internally. In order to execute a second buy long order (as a result of a different buy rule being triggered) after initiating a fresh buy long order, one has to execute another command on a separate line in the study. Although that's not logical from a pure trader's point of view, that's fine and I've learned to live with it, hence a long list of orders in my studies, each being executed once off. Now, if for some reason the study decides both buy rules are triggered at the same time then you can't execute the two buy orders. The alternative is to combine them into one but that requires extra complication, especially for exits. So, it would make programming for the trader much easier to allow those multiple buy orders on the same tick. Then the study can keep track of the different orders based on different trading rules very easily using the labels attached to each unique order. After all, the labels do serve a useful purpose, so for completeness it would be nice to allow multiple buy (or sell) orders on the same tick.

If the restriction of using the same order command was not present, we would not have brought this up in the first place. What we would then do is re-use the same entry command in the event of multiple orders. The we would also exit by re-using the same exit command. The trader can then keep track of the orders by other simple means. Alas, this is not the case with MC.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 26 Jan 2011

MC Team - For me personally - Would like to see - the following code to work out as one would see it logically fit.

This is a complete code but doesn't work as expected. I just want to scale out all contracts - irrespective of how the position occured. Don't want to track of how the long position was created. Unfortunately this doesn't work as I would expect.

PS: On top of it - if MC somehow can some how preserve the limit order in the queue at the broker rather than re-submitting the order for every tick - I would have a better chance of closing the contracts.

-------------
condition1=<logical condition1>;
condition2=<logical condition2>;
condition3=<logical condition3>;
if CurrentContracts<12 then begin
if condition1 then buy 4 contracts next bar at market;
if condition2 then buy 4 contracts next bar at market;
if condition3 then buy 4 contracts next bar at market;
end;

condition11=<logical condition 11>;
condition12=<logical condition 12>;
condition13=<logical condition 13>;

value11=AvgPrice+1;
value12=AvgPrice+2;
value13=AvgPrice+3;

// Please note the difference of number of contracts to sell(3 contracts) vs buy(4 contracts)
if marketposition>0 and CurrentContracts>0 and CurrentContracts<=12 then begin
if condition11 then sell minlist(3,currentcontracts) contracts Total next bar at value11 limit
else if condition12 then sell minlist(3,currentcontracts) contracts Total next bar at value12 limit
else if condition13 then sell minlist(3,currentcontracts) contracts Total next bar at value13 limit;
end;




----------

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Re: AUTOTRADING PROBLEM

Postby gregorio123456 » 27 Jan 2011

I don´t use autotrading but maybe this way you have one walkround

if you have one sistem w 3 condition to enter buy in each different condition ...w possible you get true this 3 condition in the same time and autotrading only send one order....

why not ..you separate that sistem in 3 sistem separate... and run each one(sistem) in separate charts ......maybe MC send 3 order in the same time because is from 3 different charts.......

maybe work I don´t know

jo

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 27 Jan 2011

gregorio123456 - Running it on different charts is not an option. The conditions are being checked on one single chart and they are different conditions and I would be interested in trading all the conditions not necessarily one single condition. All the orders need to be sent - if for that tick - all the conditions are met. If only couple of them are valid - it needs to send those 2 orders. This is a very generic requirement and I would like to have this happen at the "same" tick - if they are valid. Don't want to wait for next tick to check for the validity of the condition. By next tick - I am not sure - whether the condition would be valid or not. If it becomes invalid for the next tick - I would have lost the opportunity to participate in the trade when the condition was actually valid. Though it might sound like a non-issue for majority of the members, for me this is critical feature to have and I would think this is potentially a design issue or some technical limitation.

Thanks
Last edited by vking on 28 Jan 2011, edited 1 time in total.

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Re: AUTOTRADING PROBLEM

Postby gregorio123456 » 27 Jan 2011

I mean this

you have one sistem run in one charts ES 5min....for example....
-----------------------------------
bl.index1=cross 2 mov_Ave
bl.index2= ovesell_RSI
bl.index3=swing_up

if bl.index1 then buy ("buy long #1") qty1 contracts next bar at market;
if bl.index2 then buy ("buy long #2") qty2 contracts next bar at market;
if bl.index3 then buy ("buy long #3") qty3 contracts next bar at market;
---------------------------

if you separate

sistemcrossAVE(((this sistem run alone ES 5min)))
bl.index1=cross 2 mov_Ave
if bl.index1 then buy ("buy long #1") qty1 contracts next bar at market;

sistemoversell_RSI(((this sistem run alone in other charts ES 5min)))
bl.index2= ovesell_RSI
if bl.index2 then buy ("buy long #2") qty2 contracts next bar at market;

sistemswing_up(((this sistem run alone in other charts ES 5min)))
bl.index3=swing_up
if bl.index3 then buy ("buy long #3") qty3 contracts next bar at market;

if each sistem get true in 10:30 am.... then MC send 3 order in same time or ...in queue inside same second (in autotrading) ....because is from diferents charts(or instruments)....is same for cover position put rules to cover in each single sistem(if you want)....

if not sends orders (2ª and 3ª)..I ask-me what is benefit of autotrading of MC when get order in same time of the diferents intruments (ES and NQ for exempla)and not send order in same time or in queue????

is only one opinion of walkaround....(I don´t use autotrading)

in my all sistem(maybe about 10).....for keep this simple. I run each sistem alone in each charts..

jo

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Re: AUTOTRADING PROBLEM

Postby gregorio123456 » 27 Jan 2011

wiking you are right about this..... but if you waite for one solution from team of MC you don´t make money (or you have problems) because now they try launch MC7 w chart_trader manual and fix some main bugs ....will be nice .....

now I would like say congratulation to team of MC.. for software and support ....thanks.....

my sugestion is try make one walkaround about your problem and waite for one solution from team of MC and post in projet managment your problems

I remenber some time ago I have problems w (avgentryprice,cover partial and total lots,reverse,etc....)(I run some 6 system in ES in the same time... maybe for some guys call one system) about add lots ...cover add lots.... scalps.... over sell... over buy... begin and end some main position trade.etc... so best solution I found was run each (simple)system on each charts.....I mean keep this simple.... :-)

I hope you and another guys find one solution w some walkaround

thanks

jo

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 27 Jan 2011

Thanks Jo.

First thing - MC is great in many aspects compared to few other platforms and don't have complaints about it.

Just that I found a limitation the way the orders are sent/managed - making it little bit difficult for "me" and is the reason for requesting MC team - whether they see it as an "issue" or a "feature". If it's considered a "feature" I would have to find an alternate way to manage the trades in simpler way ( don't know whether it's still going to be MC or someother platform). From my point of view - it would be very nice if addressed in MC itself as I have built lot of stuff based on Easy language( I also have TS 9 btw) and want to continue using easy language if at all possible unless I am "forced" to make a switch to some other platform - from order management point of view.

The solution you have suggested to use multiple charts might work - but it's not a solution that I would like to use. 3 charts would take more resources compared to one chart and also makes it difficult to manage the "combined position".


Thanks.
Last edited by vking on 28 Jan 2011, edited 1 time in total.

gregorio123456
Posts: 117
Joined: 08 Nov 2005
Been thanked: 3 times

Re: AUTOTRADING PROBLEM

Postby gregorio123456 » 28 Jan 2011

welcome


other suggetion :for exempla

you use 1 charts w 30days then use 3 charts w 5 days

for managment--- the "combined position"---

They each have their own chart with a own trade sheet attached.

jo

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

Re: AUTOTRADING PROBLEM

Postby Dave Masalov » 28 Jan 2011

Dear vking,

You can try to change

Code: Select all

if condition1 then buy 4 contracts next bar at market;
if condition2 then buy 4 contracts next bar at market;
if condition3 then buy 4 contracts next bar at market;


to

value1 = 0;
if condition1 then value1 = value1+4;
if condition2 then value1 = value1+4;
if condition3 then value1 = value1+4;
if value1 > 0 then buy value1 contracts next bar market;


Thus, one order will be sent with the amount of contracts that you need and you will avoid order queue and extra commission for multiple orders.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 28 Jan 2011

Dave - thanks a lot for the reply. The solution looks clean.

If the order is NOT market but different limit buy - any suggestion?

lp1=<calculatedPrice1>;
lp2=<calculatedPrice2>;
lp3=<calculatedPrice3>;

if condition1 then buy 4 contracts next bar at lp1 limit;
if condition2 then buy 4 contracts next bar at lp2 limit;
if condition3 then buy 4 contracts next bar at lp3 limit;

PS: Sorry - should have mentioned earlier - I was trying for a limit order fill instead of market. Any suggestion you can think of? Would like to submit all the orders at the same tick.

Thanks

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 04 Feb 2011

MC Team - Any suggestion you can provide to this question?

Thanks

User avatar
Lara
Posts: 14
Joined: 07 Feb 2011

Re: AUTOTRADING PROBLEM

Postby Lara » 07 Feb 2011

Hello,
lp1=<calculatedPrice1>;
lp2=<calculatedPrice2>;
lp3=<calculatedPrice3>;

if condition1 then buy 4 contracts next bar at lp1 limit;
if condition2 then buy 4 contracts next bar at lp2 limit;
if condition3 then buy 4 contracts next bar at lp3 limit;


This will work for limit buy, you can use this.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 07 Feb 2011

Lara - thanks for the message. Unfortunately this code doesn't produce 3 orders if all the 3 conditions are met - at the same tick. It would only generate one single limit order.

Thanks.

Please try the following full signal code (This would only generate one signal buy order - also tried multiple orders in same direction etc settings as well):

Vars: lp1(0);
Vars: lp2(0);
Vars: lp3(0);

Condition1=CurrentContracts<12;
Condition2=CurrentContracts<12;
Condition3=CurrentContracts<12;

lp1=close-0.25;
lp2=close-0.5;
lp3=close-0.75;

if condition1 then buy 4 contracts next bar at lp1 limit;
if condition2 then buy 4 contracts next bar at lp2 limit;
if condition3 then buy 4 contracts next bar at lp3 limit;

if CurrentContracts=12 then begin
Sell CurrentContracts contracts total next bar market;
end;

User avatar
Lara
Posts: 14
Joined: 07 Feb 2011

Re: AUTOTRADING PROBLEM

Postby Lara » 08 Feb 2011

This code will send limit orders as OCO -group which means that if a condition met for one oder, it execute it and will cancel the other two.There is no way to work around this issue just yet. With future manual trading in the version 7 of MultiCharts you will be able two place 3 limit orders, but they won't be able to be executed at the same time, just one after the other.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: AUTOTRADING PROBLEM

Postby vking » 08 Feb 2011

Thanks Lara. Any specific reason - these are considered as OCO orders? The logic is straight forward and I would assume this would follow exactly the program logic. Atleast there could have been a choice for the users to pick - whether to consider it as an OCO or "regular" order.

Thanks.

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

Re: AUTOTRADING PROBLEM

Postby janus » 09 Feb 2011

Lara wrote:This code will send limit orders as OCO -group which means that if a condition met for one oder, it execute it and will cancel the other two.There is no way to work around this issue just yet. With future manual trading in the version 7 of MultiCharts you will be able two place 3 limit orders, but they won't be able to be executed at the same time, just one after the other.


I think this explains why when I send a second limit order later on, the first one is cancelled and reinstated. I'm starting to understand more how MC manages orders. It appears MC on each bar (or tick when IOG is turned on) sometimes "bundles" the orders depending on the order type, and tries to treat orders issued by a study as one new trade, instead of treating them all separately irrespective of their timing. In other words, it would be better of MC singled out each order in a study and managed them separately. That way, old limit orders won't have to be re-issued. We could also issue multiple buy or sellshort orders at the same time. There must be a reason for not doing this - perhaps to do with back testing but don't see how. Perhaps it's a "feature" of EasyLanguage. Perhaps it's to provide some safe guards against runaway code. In any case, I don't want to go into the specifics of this as I'm sure MC will not be too eager to change the current way orders are managed. However, a new approach should be considered for a future release by using a new and separate set of commands to issue orders. The existing ones remain for backward compatibility but the new ones can be used by people like myself who use the more traditional (and more logical) way of managing orders. At the moment I'm working around some of the limitations using some complex logic in my code but it's not pretty. It works most of the time but it's not ideal. If I get the time I might develop a DLL to bypass the MC order management system. I will lose a lot of nice features, such as the tracking tool built-in to MC so I will have to develop my own but for me that's worth the extra work to keep my code as simple as possible so I can focus on developing new trading strategies and not waste time trying to fit my trading rules to some of the limitations presented by MC. I intend to spend a long time developing new trading strategies over the coming years, and the current order management approach used by MC does not suit me. Either I move to another package or as I mentioned develop my own DLL. I'm 50/50 at this stage which way I will go. It all depends on how complex my trading rules become. If I keep them very simple I should be able to keep using MC the way it is.
These users thanked the author janus for the post:
waveslider


Return to “MultiCharts”