PlaceMarketOrder Behavior, Market Order Obsolete Question

Questions about MultiCharts and user contributed studies.
Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

PlaceMarketOrder Behavior, Market Order Obsolete Question

Postby Triage » 17 Aug 2012

There is a feature in MC auto trading that can cancel a market order as obsolete if not filled in x seconds.

1) Do these obsolete market orders include PlaceMarketOrder command "low level" orders?

2) And does cancel obsolete market orders work the same way for SA and AA auto trading modes? Or does MC order engine only track the order for SA mode trading?

Thanks for the info.

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

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Andrew MultiCharts » 20 Aug 2012

The PlaceMarketOrder is not affected by "Cancel market orders as obsolete if not filled after X seconds". This option works both in SA and AA mode.

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Triage » 20 Aug 2012

The PlaceMarketOrder is not affected by "Cancel market orders as obsolete if not filled after X seconds". This option works both in SA and AA mode.
Is it correct to assume that the only market orders that will be cancelled are the ones in generated by buy, sell, sell short, buy to cover keywords?

All orders that are "low level market" in the order and position tracker will not be considered obsolete. These include MC order engine resubmissions of market orders.

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

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Andrew MultiCharts » 21 Aug 2012

Is it correct to assume that the only market orders that will be cancelled are the ones in generated by buy, sell, sell short, buy to cover keywords?

All orders that are "low level market" in the order and position tracker will not be considered obsolete.
Absolutely!

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Triage » 21 Aug 2012

Is it correct to assume that the only market orders that will be cancelled are the ones in generated by buy, sell, sell short, buy to cover keywords?

All orders that are "low level market" in the order and position tracker will not be considered obsolete.
Absolutely!
Thanks Andrew for the confirmation.

Follow-up questions are:

1) In SA mode, when a trade is placed by buy, sell, sell short or buy to cover keywords, the chart is updated only with a confirmed trade position at the broker. If there is a delayed fill, the chart will not change until the fill actually is reported back. Is this correct? Or is the broker's market position (if changed) will change the chart's position?

2) What happens when in between the time an order is placed, and something goes wrong an the brokerage position changes. Let's say for example this occurs to force a mismatch:

a. strategy is currently flat and broker is flat
b. strategy buys 100 shares for XYZ at the market
c. before the fill is returned by broker, the broker executes another extra 100 shares for XYZ
d. currently at the broker, the shares are 200 total for XYZ
e. MC engine returns back to chart in SA mode auto trading the fill

What should be shown in the chart? Long +100 shares, or Long +200 shares?

The reason I ask is to clarify if the synchronous effect is by the fill or by the true brokerage position in SA mode.

3) Do low-level market orders affect what is shown on the chart and the values of currentcontracts * marketposition in SA mode automatically, or do we have to manually use ChangeMarketPosition to reflect what would have been a change at the broker?

I assume we have to manually do this in all cases.

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

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Andrew MultiCharts » 22 Aug 2012

1) In SA mode, when a trade is placed by buy, sell, sell short or buy to cover keywords, the chart is updated only with a confirmed trade position at the broker. If there is a delayed fill, the chart will not change until the fill actually is reported back. Is this correct? Or is the broker's market position (if changed) will change the chart's position?
In SA mode strategy on chart waits for confirmation (final status) from broker that the order was filled. Only when this confirmation is received the strategy understands it has been filled, market position has changed and the order is displayed on chart.
2) What happens when in between the time an order is placed, and something goes wrong an the brokerage position changes. Let's say for example this occurs to force a mismatch:

a. strategy is currently flat and broker is flat
b. strategy buys 100 shares for XYZ at the market
c. before the fill is returned by broker, the broker executes another extra 100 shares for XYZ
d. currently at the broker, the shares are 200 total for XYZ
e. MC engine returns back to chart in SA mode auto trading the fill

What should be shown in the chart? Long +100 shares, or Long +200 shares?

The reason I ask is to clarify if the synchronous effect is by the fill or by the true brokerage position in SA mode.
Nice question. Orders generated by the strategy and filled at broker are shown on chart in SA mode as well as any other orders filled at broker. But in this case it can lead to asynchronization. The strategy has sent an order to buy only 100 shares, so when they were filled, MC engine assumes that broker position is only 100 shares, whereas real broker position is 200 shares and the same position is displayed on chart. In Order and Position Tracker window on the Strategy Positions tab there will be mismatch, even though on chart it will look ok. the same effect can be achived when mixing strategy trading and manual trading
3) Do low-level market orders affect what is shown on the chart and the values of currentcontracts * marketposition in SA mode automatically, or do we have to manually use ChangeMarketPosition to reflect what would have been a change at the broker?

I assume we have to manually do this in all cases.
We have 2 synchronizer strategies. They are introduced to reach the goal of synchronization by means:
  • 1. Place market order to broker without affecting anything in MC engine (PlaceMarketOrder - your case). It is "invisible" for the strategy, so when it is used, strategy has no idea of the executed order. But you can trace it in your strategy only using Market_Position_At_Broker.
    2. Emulate an executed order in MC engine without sending anything to broker.
I believe it should answer your question.

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Triage » 27 Aug 2012

In SA mode strategy on chart waits for confirmation (final status) from broker that the order was filled. Only when this confirmation is received the strategy understands it has been filled, market position has changed and the order is displayed on chart.
Sorry to ask the question in a slightly different way again. I just want to understand a little bit of the inner workings so I understand what's going on in the trade workflow.

Follow-up questions:

1) If my strategy on 1 minute chart"
a. sends a new market order in SA mode at the close of every 1 minute bar
b. but does not "get filled" for 10 minutes because of delayed order reporting of a fill

then marketposition and currencontracts (including the chart arrows) do not change.

However, during the 10 minutes before the first fill is reported, 9 other market order trades should be sent by the strategy's code logic. How are these other 9 trades handled? Are they skipped, or do they queue up until the first trade is reported as filled and then sent?


2) MarketPosition_at_Broker_for_The_Strategy is the assumed brokerage position at the brokerage in the MC order engine for a single strategy. This keeps track of what the brokerage position should be just for a single strategy AFTER IT IS FILLED.

This is different than MarketPosition_at_Broker, which reports the position at the broker whether or not MC gets a fill report FOR ALL STRATEGIES trading a single symbol. Is that correct?


EXAMPLE OF MARKETPOSITION_AT_BROKER_FOR_THE_STRATEGY:

In SA Mode: strategy buy/sell position changes by market order--> MC Order Engine sends new market order to brokerage--> once order fill is reported, it then changes MarketPosition_at_Broker_for_The_Strategy --> then changes chart arrows (positions)--> then changes strategy (MarketPosition and CurrentContracts).

MarketPosition_at_Broker_for_The_Strategy reports back what is filled for ONLY one strategy that calls this keyword.


EXAMPLE OF MARKETPOSITION_AT_BROKER:

In SA Mode: no matter if MC order engine gets a fill report from the broker, the MarketPosition_at_Broker will report whatever is the total market position for a symbol.

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

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Andrew MultiCharts » 29 Aug 2012

1) If my strategy on 1 minute chart"
a. sends a new market order in SA mode at the close of every 1 minute bar
b. but does not "get filled" for 10 minutes because of delayed order reporting of a fill

then marketposition and currencontracts (including the chart arrows) do not change.

However, during the 10 minutes before the first fill is reported, 9 other market order trades should be sent by the strategy's code logic. How are these other 9 trades handled? Are they skipped, or do they queue up until the first trade is reported as filled and then sent?
if conditions of your order generation is met on 10 bars, the order is maintaned at broker, not cancelled. But not for market orders. Let me explain on an example:
  • Bar 0 (close, script is calculated), condition for placing market order = true.
    Bar 1 (open), condition for placing market order = true, market order 1 is placed at broker.
    Bar 1 (close, script is calculated), condition for placing market order = true, market order 1 is not yet filled, script tries to cancel it, it starts waiting for 40 seconds (by default, but manageable)
    Bar 2 (open), condition for placing market order = true, market order 1 is not yet filled, still waits for 40 seconds.
    Bar 2 (close, script is calculated), condition for placing market order = true, market order 1 is coinsidered "lost".
    Bar 3 (open), condition for placing market order = true, market order 2 is placed at broker.
    ...
2) MarketPosition_at_Broker_for_The_Strategy is the assumed brokerage position at the brokerage in the MC order engine for a single strategy. This keeps track of what the brokerage position should be just for a single strategy AFTER IT IS FILLED.
Correct. For simple understanding: it is market position for the strategy in auto trading engine (may be different from chart and from broker).
This is different than MarketPosition_at_Broker, which reports the position at the broker whether or not MC gets a fill report FOR ALL STRATEGIES trading a single symbol. Is that correct?
Correct. Net market position forthe symbol on broker end.
EXAMPLE OF MARKETPOSITION_AT_BROKER_FOR_THE_STRATEGY:

In SA Mode: strategy buy/sell position changes by market order--> ...
Not correct. This is not the first stage. First stage is order generation by script. Next stage: order is sent through plug-in.
MC Order Engine sends new market order to brokerage--> once order fill is reported, it then changes ...
MarketPosition_At_Broker first of all and if the final status that the orde ris filled is received, then changes...
MarketPosition_at_Broker_for_The_Strategy --> then changes chart arrows (positions)--> then changes strategy (MarketPosition and CurrentContracts).
Chart arrows are the consequences of chart market position change.
MarketPosition_at_Broker_for_The_Strategy reports back what is filled for ONLY one strategy that calls this keyword.
Yes.
EXAMPLE OF MARKETPOSITION_AT_BROKER:

In SA Mode: no matter if MC order engine gets a fill report from the broker, the MarketPosition_at_Broker will report whatever is the total market position for a symbol.
Absolutely correct.

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Triage » 29 Aug 2012

Thanks Andrew for the detailed answers. You're the best. Helps us, and hopefully others, to see what is going on in the trade workflow.

Your description below confirms a lot of what we see in executions.
if conditions of your order generation is met on 10 bars, the order is maintaned at broker, not cancelled. But not for market orders. Let me explain on an example:
  • Bar 0 (close, script is calculated), condition for placing market order = true.
    Bar 1 (open), condition for placing market order = true, market order 1 is placed at broker.
    Bar 1 (close, script is calculated), condition for placing market order = true, market order 1 is not yet filled, script tries to cancel it, it starts waiting for 40 seconds (by default, but manageable)
    Bar 2 (open), condition for placing market order = true, market order 1 is not yet filled, still waits for 40 seconds.
    Bar 2 (close, script is calculated), condition for placing market order = true, market order 1 is coinsidered "lost".
    Bar 3 (open), condition for placing market order = true, market order 2 is placed at broker.
    ...
What we also noticed is that if there is an order execution delay (which so far we have tracked to a half dozen common brokerage problem trade events), we can get repeating orders queued up from just the strategy conditional still being true on the following bars when the position at broker has not confirmed as filled on successive bars.

This is especially true on lower timeframes such as tick bars or 1 minute bars.

Repetitive trades are also an issue with the generic MC synchronizer included in the MC list of indicators that comes with each install of MC when certain brokerage trade events occur.

Along with market order re-submissions and attempted cancels, we can get confusion in what the true market position should be and what the true brokerage position is. Whether in SA or AA mode, we are adding a fair amount of code to handle these events.

I understand that this is not a bug, but expected behavior. And I agree it is the way it should be.

But is there any way for us to get the order status or the brokerage order ID from MC PowerLanguage? Is that available in MC .NET? That would allow us to better solve these problem trade events from the broker.

We are getting a lot of clients who are asking us about order ticket control. We encourage them to port over to MC because MC supports a large number of brokerages, but this is ultimately an important consideration for them.

Although our custom solutions fix about 99% of the sync and brokerage error problems/confusions, there is that 1% if we can just get some order ID into PowerLanguage to distinguish trade status. You don't even need to give us direct ticket control. Just the order ID for order placed, and for order filled would be "golden" :-)

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Triage » 29 Aug 2012

Recalculate on Broker Events

The option can be used to force the strategy to be recalculated after a certain event during live trading. One can check the following events:

When Market Position Changes.
When an Order is Filled.
Other related questions:

1) When the strategy is recalculated after an event such as Market Position changes or order is filled, what is the barstatus? Is it -1?

2) Market Position changes is the script's marketposition or the position at the broker?

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

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Andrew MultiCharts » 30 Aug 2012

Thanks Andrew for the detailed answers. You're the best. Helps us, and hopefully others, to see what is going on in the trade workflow.

Your description below confirms a lot of what we see in executions.
You are welcome :-)
But is there any way for us to get the order status or the brokerage order ID from MC PowerLanguage? Is that available in MC .NET? That would allow us to better solve these problem trade events from the broker.
Yes, search for "TradeManager" in MC. NET help.
1) When the strategy is recalculated after an event such as Market Position changes or order is filled, what is the barstatus? Is it -1?
Barstatus will be most likely 1. Barstatus -1 will be when there is no bar, but there is a calculation of script.
2) Market Position changes is the script's marketposition or the position at the broker?
Broker market position. So even execution of a manual order will cause the strategy to be recalculated.

Triage
Posts: 28
Joined: 12 Mar 2012
Has thanked: 2 times
Been thanked: 3 times

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Triage » 30 Aug 2012

Barstatus will be most likely 1. Barstatus -1 will be when there is no bar, but there is a calculation of script.
But Recalculate and RecalcLastBarAfter keywords that calculate the script will produce a barstatus = -1. Which won't run any strategy buy or sell keywords.

But when the strategy is recalculated after an event such as Market Position changes or order is filled with the strategy properties options checked, the barstatus = 1 (in between open and closing ticks of the bar).

What happens when the marketposition changes during the open and closing ticks? Is this also barstatus = 1 or they are barstatus = 0 and 2 respectively for the bar's end points?

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

Re: PlaceMarketOrder Behavior, Market Order Obsolete Questio

Postby Andrew MultiCharts » 11 Oct 2012

What happens when the marketposition changes during the open and closing ticks? Is this also barstatus = 1 or they are barstatus = 0 and 2 respectively for the bar's end points?
According to our design, a bar is closed when the first tick of the next bar is received. In other words: even if this is for sure the last tick of the bar, the bar is considered to be "in-progress" until the first tick of the next bar is received.


Return to “MultiCharts”