position sync

Questions about MultiCharts and user contributed studies.
orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

position sync

Postby orion » 22 Jan 2015

Some questions on position sync:

Shorthand:
bp = marketPosition_at_broker
sp = marketPosition_at_broker_for_the_strategy

1. When the unexpected mismatch case discussed here occurs and we are in SA mode with single chart trading the symbol, is it always the case that bp is right and sp is wrong? In other words, bp is always more trustworthy?

2. If sp = +5 and bp = +2, and we invoke ChangeMarketPosition(-3) as in !From Broker To Strategy MP Synchronizer! script, it makes sp = 5 - 3 = +2 = bp. What is expected behavior if instead we invoke ChangeMarketPosition(-1). Will this make sp = 5 - 1 = +4 while keeping bp = +2?

Thanks.

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

Re: position sync

Postby Andrew MultiCharts » 22 Jan 2015

1. When the unexpected mismatch case discussed here occurs and we are in SA mode with single chart trading the symbol, is it always the case that bp is right and sp is wrong? In other words, bp is always more trustworthy?
In general yes, but you should understand that position status is just a piece of information sent from broker, like order execution status. What i am trying to say is that if one is lost, the other one also can be lost. Though from my experience the broker market position is always correct.
2. If sp = +5 and bp = +2, and we invoke ChangeMarketPosition(-3) as in !From Broker To Strategy MP Synchronizer! script, it makes sp = 5 - 3 = +2 = bp. What is expected behavior if instead we invoke ChangeMarketPosition(-1). Will this make sp = 5 - 1 = +4 while keeping bp = +2?
Yes.

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

Re: position sync

Postby orion » 22 Jan 2015

1. If a strategy makes frequent trades, then position updates will be sent frequently by the broker thus making bp more resilient to message loss while order execution report is sent only once for each trade which makes sp more fragile from an error standpoint. So if bp error occurs due to message loss, the position updates on the next trade will get through and correct it. OTOH, once an sp error occurs due to message loss, sp will remain in error forever. So bp error is transient since it is auto-correcting while sp error is sticky? Agree?

Yes
2. I went through both the IB and CQG API documents since these will be the two gateways I will be trading with. The APIs have a lot of similarities. They both allow MC to query account positions asynchronously which means MC can make regular queries to ensure that the bp value is robust. Does MC send regular "hello" queries for account positions to the broker API to ensure robustness?

MC requests that info once and then MC receives what is sent from broker.
3. If an instrument is traded by a single strategy in SA mode, and the signal relies on marketPosition or marketPosition_at_broker_for_the_strategy for its logic as most strategies do, when such unexpected mismatch due to message loss shows up in OPT strategy tab, the recommended solution is to stop auto trading, resynchronize using 'Assign the Initial Market Position at the Broker Settings', and then resume auto trading. Does this resync force the MC engine to do a message exchange with the broker for a fresh position update or is the broker position from the local value reflected in OPT used?

Depending on selected option for "Assign the Initial Market Position at the Broker Settings", it is either set manually or taken from OPT.
4. In the case of single strategy in SA mode, we are lucky to be able to detect the 'unexpected mismatch' by simply looking at the OPT since bp and sp should always match. In the case of trading a symbol using multiple strategies in SA mode, we have no such luck because the mismatch is to be expected. So if the order fill report for a strategy was lost and the marketPosition_at_broker_for_the_strategy developed an error, then per our prior discussion (#1 above), such error is sticky and such error is undetectable from just looking at the OPT. Do you agree that this makes the multi-strategy case quite different from the single strategy case since special code needs to exist in the strategy to detect the error? This special code is fairly easy and my question is not as to what this code should be. Instead, I am just looking for your affirmation that such special code does need to exist - your affirmation would help validate my understanding and thinking.

In MC 9.1 it will be possible to monitor statuses of orders from OPT, perhaps it will be helpful in this case..
5. Is marketPosition_at_broker_for_the_strategy only updated on the final order status message or is it also updated as order status updates due to partial fills come in? I would expect it to be updated on partial fills too?

It is updates based on any order execution update received from broker.
6. GetPositionQuantity keyword: when this is used in the PL code, does it force a message exchange with the broker to get the freshest value or is it simply giving you the state reflected in OPT?

From OPT.
7. Does ChangeMarketPosition force any message exchanges between MC and the broker to get a fresh update for bp or does it leave bp completely alone?

It doesn't affect message exchange between MC and broker.
8. If answer to 7 is no, then the only reason for the LatencyMS parameter in the example synchronizer script is to cover the latencies in the internals of MC AT engine?

Yes


Return to “MultiCharts”