order engine

Read before posting.
orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

order engine

Postby orion » 24 Jan 2015

Hello Andrew or Henry,
Could you please help with these questions. I have edited to add two more questions. This is the full list. Clear understanding of the operation of the MC order engine is essential to making sure we don't have mishaps due to poor fills, double orders, exposed orders, and other such issues.

1. For a market order sent on a prior bar, if the script stops generating the market order condition before the market order timer ('Cancel Market Orders as Obsolete if not Filled Within X seconds') expires, does MC cancel the market order immediately (similar to the way price orders are cancelled on order condition not being met in PL) or does it wait for the timeout and only cancel on timer expiration? So say, timer setting is default 40 seconds and we are using 15 second bars. If market order condition is valid on close of bar 1 and market order placed on open of bar 2 but market order condition is no longer valid in script on close of bar 2, will the market order still be maintained since the 40 second timer has not expired or will the market order be cancelled?

2. Context for this question and #3 is IB as broker to understand how the MC + IB combo works given IB is only broker that allows order modification. Yes/no answers are fine. Assume order conditions are calculated as valid by script on two bars 1 and 2 for each of following cases and that at time of bar 2 calculation the bar 1 order had not been filled.

2.a
bar1: buy 5 contracts next bar at market
bar2: buy 10 contracts next bar at market
Size changed in script. So MC sends a modify (and not a cancel/replace)?

2.b
bar1: buy 5 contracts next bar at 1800 limit
bar2: buy 5 contracts next bar at 1805 limit
Price changed in script. So MC sends a modify (and not a cancel/replace)?

2.c
bar1: buy 5 contracts next bar at 1800 limit
bar2: buy 10 contracts next bar at 1800 limit
Size changed in script. So MC sends a modify (and not a cancel/replace)?

2.d
bar1: buy 5 contracts next bar at 1800 limit
bar2: buy 10 contracts next bar at 1805 limit
Both price and size changed. MC still sends a modify (and not a cancel/replace)?

3. Finally, we have following case, where we want to keep original order in order book queue while adding a new price order.
bar1: buy 5 contracts next bar at 1800 limit
bar2: // following entry pair
buy 5 contracts next bar at 1800 limit // keep prior order in bar 2
buy 5 contracts next bar at 1805 limit // add additional order in bar 2

3.a. What happens? Assume it does not violate position limits and 'Optimize Order Flow' is unchecked (OOF=off). Does MC simply send the additional limit order to be added to the order book or does it do a cancel the original order and send an OCO?
3.b. If the answer is OCO, based on discussion in this OCO thread, this is an OCO_cancel? So that means it would be a mistake to do this in script?

4. Say a price order is sent by MC to broker on close of bar 5. It will persist at the broker as long as the order condition is met on calculation on bar close event (barStatus = 2) for subsequent bars 6, 7, 8... For order persistence at broker, does the order condition also need to hold on any recalc due to other events such as those resulting from market position change or order fill reports?

5. I understand that stop loss and profit target orders that bracket a market or price order are sent by the MC order engine to broker only when the market or price order is filled. I presume the MC order engine relies on the order fill report and not the market position report from the broker for sending the bracket orders?

Thanks.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: order engine

Postby Andrew MultiCharts » 29 Jan 2015

1. For a market order sent on a prior bar, if the script stops generating the market order condition before the market order timer ('Cancel Market Orders as Obsolete if not Filled Within X seconds') expires, does MC cancel the market order immediately (similar to the way price orders are cancelled on order condition not being met in PL) or does it wait for the timeout and only cancel on timer expiration? So say, timer setting is default 40 seconds and we are using 15 second bars. If market order condition is valid on close of bar 1 and market order placed on open of bar 2 but market order condition is no longer valid in script on close of bar 2, will the market order still be maintained since the 40 second timer has not expired or will the market order be cancelled?
A market order is canceled as soon as the timer is out, or the close of the bar happens (no matter if the conditions are true or not).
2. Context for this question and #3 is IB as broker to understand how the MC + IB combo works given IB is only broker that allows order modification. Yes/no answers are fine. Assume order conditions are calculated as valid by script on two bars 1 and 2 for each of following cases and that at time of bar 2 calculation the bar 1 order had not been filled.

2.a
bar1: buy 5 contracts next bar at market
bar2: buy 10 contracts next bar at market
Size changed in script. So MC sends a modify (and not a cancel/replace)?
The first market order is canceled. A new market order is sent.
2.b
bar1: buy 5 contracts next bar at 1800 limit
bar2: buy 5 contracts next bar at 1805 limit
Price changed in script. So MC sends a modify (and not a cancel/replace)?
The limit order is modified.
2.c
bar1: buy 5 contracts next bar at 1800 limit
bar2: buy 10 contracts next bar at 1800 limit
Size changed in script. So MC sends a modify (and not a cancel/replace)?
The limit order is modified.
2.d
bar1: buy 5 contracts next bar at 1800 limit
bar2: buy 10 contracts next bar at 1805 limit
Both price and size changed. MC still sends a modify (and not a cancel/replace)?
The limit order is modified.
3. Finally, we have following case, where we want to keep original order in order book queue while adding a new price order.
bar1: buy 5 contracts next bar at 1800 limit
bar2: // following entry pair
buy 5 contracts next bar at 1800 limit // keep prior order in bar 2
buy 5 contracts next bar at 1805 limit // add additional order in bar 2
The old limit order is cancelled, the new 2 orders are fired.
3.a. What happens? Assume it does not violate position limits and 'Optimize Order Flow' is unchecked (OOF=off). Does MC simply send the additional limit order to be added to the order book or does it do a cancel the original order and send an OCO?
See my prev. comment above.
3.b. If the answer is OCO, based on discussion in this OCO thread, this is an OCO_cancel? So that means it would be a mistake to do this in script?
If you don't want to cancel the first one, that would be a mistake.
4. Say a price order is sent by MC to broker on close of bar 5. It will persist at the broker as long as the order condition is met on calculation on bar close event (barStatus = 2) for subsequent bars 6, 7, 8... For order persistence at broker, does the order condition also need to hold on any recalc due to other events such as those resulting from market position change or order fill reports?
If IOG=OFF, nothing will be cancelled intrabar.
5. I understand that stop loss and profit target orders that bracket a market or price order are sent by the MC order engine to broker only when the market or price order is filled. I presume the MC order engine relies on the order fill report and not the market position report from the broker for sending the bracket orders?
Please give me an example scenario.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: order engine

Postby orion » 29 Jan 2015

Thank you Andrew for the response.
1. For a market order sent on a prior bar, if the script stops generating the market order condition before the market order timer ('Cancel Market Orders as Obsolete if not Filled Within X seconds') expires, does MC cancel the market order immediately (similar to the way price orders are cancelled on order condition not being met in PL) or does it wait for the timeout and only cancel on timer expiration? So say, timer setting is default 40 seconds and we are using 15 second bars. If market order condition is valid on close of bar 1 and market order placed on open of bar 2 but market order condition is no longer valid in script on close of bar 2, will the market order still be maintained since the 40 second timer has not expired or will the market order be cancelled?
A market order is canceled as soon as the timer is out, or the close of the bar happens (no matter if the conditions are true or not).
This is different from what I expected!! So please allow me to paraphrase what you are saying above to ensure there is no misunderstanding and also lets clarify this through two examples. To paraphrase your description, market orders obey the following 3 rules:

1. Market order that was sent on the open of a bar, that is yet to be acknowledged as filled, is always cancelled at the earliest of any one of the following two events: (a) the close of the bar on whose open the market order was sent, or (b) expiration of the market order timer.
2. New market order may be sent on open of new bar without waiting for response to the cancellation of old unfilled market order that had to be cancelled due to either of the two events as described in #1.
3. The timer for the market order is started at the open of the bar on which the market order is sent.

Examples:

1. Scenario of trading with 10 second bars with default timer setting of 40 sec:
@10:05:10: bar 1 closes, script calculates: market order condition = true
@10:05:10: bar 2 opens, market order sent by MC to broker, timer started
assume market order is not filled by 10:05:20
@10:05:20: bar 2 closes, script calculates: market order condition = true
@10:05:20: bar 3 opens
a) Even though script calculates market order condition to be true at close of bar 2 and timer has not expired, MC cancels the original market order and sends a new one on bar 3 open. Correct?
b) MC fires the new market order without waiting for old cancel response to come back. Correct?
c) The timer is started at open of bar when market order is sent (in this case, bar 2 open). Correct?

2. Scenario of trading with 10 second bars with timer setting of 5 sec:
@10:05:10: bar 1 closes, script calculates: market order condition = true
@10:05:10: bar 2 opens: market order placed by MC order engine and timer started
@10:05:15: timer expires and order is cancelled since it is not filled
@10:05:20: bar 2 closes, script calculates: market order condition = true
@10:05:20: bar 3 opens
MC places new market order on bar 3 open at 10:05:20 without waiting for response to cancel that was sent on timer expiration at 10:05:15. Correct?
5. I understand that stop loss and profit target orders that bracket a market or price order are sent by the MC order engine to broker only when the market or price order is filled. I presume the MC order engine relies on the order fill report and not the market position report from the broker for sending the bracket orders?
Please give me an example scenario.
Take the following sequence:
bar 1 close: script calculates price order condition = true
bar 2 open: price order sent
price order is filled and order fill report comes back intrabar
MC engine sends special orders (PT/SL) intrabar on receipt of order fill report. This is normal and no clarification required here unless this is wrong.

Now consider a slight variation:
bar 1 close: script calculates price order condition = true
bar 2 open: price order sent
price order is filled but order fill report is lost and instead position change report received intrabar
In this case, MC engine does not send the special orders (PT/SL) intrabar on receiving the position change report since it is expecting the order fill report. Correct?

Thanks again!

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: order engine

Postby Andrew MultiCharts » 30 Jan 2015

1. Market order that was sent on the open of a bar, that is yet to be acknowledged as filled, is always cancelled at the earliest of any one of the following two events: (a) the close of the bar on whose open the market order was sent, or (b) expiration of the market order timer.
...
3. The timer for the market order is started at the open of the bar on which the market order is sent.
Yes.
2. New market order may be sent on open of new bar without waiting for response to the cancellation of old unfilled market order that had to be cancelled due to either of the two events as described in #1.
No. No order will be sent during the time interval specified in the setting "Cancel market order as obsolete" since the moment the cancellation command was sent or before the final status of the order is received from broker.
Examples:

1. Scenario of trading with 10 second bars with default timer setting of 40 sec:
@10:05:10: bar 1 closes, script calculates: market order condition = true
@10:05:10: bar 2 opens, market order sent by MC to broker, timer started
assume market order is not filled by 10:05:20
@10:05:20: bar 2 closes, script calculates: market order condition = true
@10:05:20: bar 3 opens
a) Even though script calculates market order condition to be true at close of bar 2 and timer has not expired, MC cancels the original market order and sends a new one on bar 3 open. Correct?
No.
b) MC fires the new market order without waiting for old cancel response to come back. Correct?
No.
c) The timer is started at open of bar when market order is sent (in this case, bar 2 open). Correct?
Yes.
2. Scenario of trading with 10 second bars with timer setting of 5 sec:
@10:05:10: bar 1 closes, script calculates: market order condition = true
@10:05:10: bar 2 opens: market order placed by MC order engine and timer started
@10:05:15: timer expires and order is cancelled since it is not filled
@10:05:20: bar 2 closes, script calculates: market order condition = true
@10:05:20: bar 3 opens
MC places new market order on bar 3 open at 10:05:20 without waiting for response to cancel that was sent on timer expiration at 10:05:15. Correct?
No.
Take the following sequence:
bar 1 close: script calculates price order condition = true
bar 2 open: price order sent
price order is filled and order fill report comes back intrabar
MC engine sends special orders (PT/SL) intrabar on receipt of order fill report. This is normal and no clarification required here unless this is wrong.
Yes.
Now consider a slight variation:
bar 1 close: script calculates price order condition = true
bar 2 open: price order sent
price order is filled but order fill report is lost and instead position change report received intrabar
In this case, MC engine does not send the special orders (PT/SL) intrabar on receiving the position change report since it is expecting the order fill report. Correct?
Yes.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: order engine

Postby orion » 30 Jan 2015

1. Market order that was sent on the open of a bar, that is yet to be acknowledged as filled, is always cancelled at the earliest of any one of the following two events: (a) the close of the bar on whose open the market order was sent, or (b) expiration of the market order timer.
...
3. The timer for the market order is started at the open of the bar on which the market order is sent.
Yes.
2. New market order may be sent on open of new bar without waiting for response to the cancellation of old unfilled market order that had to be cancelled due to either of the two events as described in #1.
No. No order will be sent during the time interval specified in the setting "Cancel market order as obsolete" since the moment the cancellation command was sent or before the final status of the order is received from broker.
Thank you Andrew. So my previous example sequences regarding the cancellation were wrong because I misunderstood rule #2. Let me try to paraphrase what you are saying about rule #2 and then, after you let me know whether my paraphrasing is correct, I can follow up with example sequences.

Rule #2: The market order cancellation is done by sending a cancel request to the broker and starting a new timer at the time of sending the cancel request. We refer to this timer as the "cancel timer" to distinguish it from the "market order timer" in rule #1 even though both the timers are initialized from the same configuration setting and both have default value of 40 seconds. This cancel timer begins a blackout period for market orders in which no new market orders can be sent. The blackout period ends at the earliest of two events: (a) the final status report for the original market order is received, or (b) expiration of the cancel timer.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: order engine

Postby Andrew MultiCharts » 30 Jan 2015

Rule #2: The market order cancellation is done by sending a cancel request to the broker and starting a new timer at the time of sending the cancel request. We refer to this timer as the "cancel timer" to distinguish it from the "market order timer" in rule #1 even though both the timers are initialized from the same configuration setting and both have default value of 40 seconds. This cancel timer begins a blackout period for market orders in which no new market orders can be sent. The blackout period ends at the earliest of two events: (a) the final status report for the original market order is received, or (b) expiration of the cancel timer.
Yes.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: order engine

Postby orion » 30 Jan 2015

Thank you Andrew. I greatly appreciate your time and effort in answering all the questions!


Return to “MultiCharts FAQ”