autotrading details  [SOLVED]

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

autotrading details

Postby orion » 31 Oct 2014

Can you please help me with following questions related to autotrading assuming IB as broker.

1) I understand there are two modes, SA and AA, and there are 3 positions:
a) position at broker (marketPosition_at_broker)
b) position in strategy engine (marketPosition_at_broker_for_the_strategy)
c) chart position (marketPosition)
For each of two modes, can you please clarify what things are in sync using equals and not equals. For example, if nothing is in sync, then a != b != c. If there is a mode where position at broker is not in sync with position in strategy engine but position in strategy engine is in sync with chart, then please indicate a != b = c.

2) 'Replace to market partially filled orders' under Auto Trading tab: since limit and stop orders are IB native orders, I want to clarify what is happening under the covers to make sure there are no overfills due to 'ships passing in the night' with IB completing the fill while MC is sending a replacement market order. For this to work correctly, MC has to cancel the outstanding order that is partially filled, wait for the order cancel acknowledgement, and then issue the new replacement order for the remainder. Is that the sequence of messages exchanged?

3) 'Unfilled strategy order replacement' in Auto Trading tab: as with above, if IB is the broker, this can again be a dangerous thing to do since you could have 'ships passing in the night' problem again unless similar precaution as above is taken?

4) 'Unfilled strategy order replacement': will this work as expected if the time value is set to 0 seconds? My expectation would be that as soon as price is touched based on datafeed (which can be from separate provider and not the broker), the limit/stop order to the broker is cancelled and a new order is reissued after the cancel acknowledgement is received?

5) Can #2 and #3 work without IOG?

6) 'Recalculate on broker events' has two options: 'Market position change' and 'Order filled'. How are these two different? Market position change at broker implies an order is filled and conversely.

7) 'Get real time data from' has two options. Help page has example of this with setDollarTrailing and says that in this case, if 'Get real time data' from 'Chart' option is selected then the order will be calculated based on entry order fill price at broker and the real time price from chart. I assume that 'Chart' means 'datafeed provider'?

8) Am I correct in assuming that in either the SA or AA mode we can select 'Do not show the Assign the Initial Market Position at Broker dialogue' with 'Use the actual position at the broker'? Some of the help pages say that this is only available in AA mode and that does not appear to be the case with the way the radio buttons are in the Auto Trading tab in MC?

9) I presume the Format -> Strategy Properties under MC are for chart trading only and to configure autotrading in PT (Portfolio Trader), I have to do the config in PT by right click on Strategy in Portfolio Tree and 'Show Properties ...' -> Auto Trading [Part of reason for my confusion is that there is no mention of autotrading in the PT manual and some things such as Symbol Mapping are shared between PT and MC while autotrading seemingly isn't.]

10) Some buttons like 'Assign the Initial Market Position at the Boker Settings' -> 'Show the assign the initial market position at broker dialogue' seem t be unavailable in PT? So we can only use 'Do not show the assign ...'?

11) One of the help pages says: "Sync of market position in autotrading mode may not work correctly if pyramiding was used. It may also not work if more than one active entry was generated on a chart." What does this mean? Does autotrading not work with pyramiding and scale-out?

12) I read about the placeMarketOrder and changeMarketPosition keywords and I am a bit confused as to where I would need to use these? If I use SA mode with 'Do not show the Assign the Initial Market position ..' -> 'Use the actual position at the broker', is there any use for these two keywords?

I apologize in advance for the long list of questions.

Thanks,
orion

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: autotrading details

Postby TJ » 01 Nov 2014

Before tech support gets to you on Monday,
you can try here:
(Wiki would have all the answers you needed, it is worth the time investment to study it in detail)
https://www.multicharts.com/trading-sof ... ge#Content


[FAQ]
viewtopic.php?f=16&t=10811

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

Re: autotrading details

Postby orion » 01 Nov 2014

Thanks TJ. I have read quite a few of your posts on the forum and your FAQ and I have learned from them.

I read all of the wiki before posting. Unfortunately, there are inconsistencies in some of the wiki documentation. These have perhaps escaped the attention of experts who understand MC intimately but the inconsistencies sow confusion in a newcomer. Once my confusion gets cleared, I will volunteer some of my time to help edit the wiki for more clarity.

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

Re: autotrading details

Postby Andrew MultiCharts » 03 Nov 2014

Hello orion,
  1. In SA mode B always = C. Everything else both in SA and in AA mode can be out of sync. If you start auto-trading in SA mode, using "Assign Market Position At Broker" feature, no manual orders are placed at the same market in the same broker account and there is only 1 chart auto-trding this market, A should be = B and should be = C. In AA mode chances that A = B = C are low.
  2. Yes, everything is done like you described except for order cancellation that is done by IB, since their native OCO group is used.
  3. Native OCO. Should be ok.
  4. Yes, it will work this way, however i am not sure i understand what is the goal of this. You can simply use market orders upon a certain level of price is reached.
  5. Yes.
  6. Those are 2 separate events coming from broker.
  7. Yes. "Chart" = last price from current chart.
  8. Yes.
  9. Yes, that is correct.
  10. Yes, not all features of auto-trading are available in PT.
  11. Sorry, not sure where you saw this. Could you give me the link, please?
  12. Those keywords were introduced for combining manual trading and auto-trading. More info here.

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

Re: autotrading details

Postby orion » 03 Nov 2014

Thanks Andrew! That cleared up 99% of my confusion. Response to item #11 from above and some suggestions followed by a question at the end.

#11 above: "Sync of market position in auto trading mode may not work correctly if pyramiding was used. It may also not work if more than one active entry was generated on a chart." These words appear highlighted midway on this webpage:

http://www.multicharts.com/trading-soft ... utoTrading


Some suggested modifications to the help pages for greater consistency:

1) 'Get Real Time Data From' in http://www.multicharts.com/trading-soft ... to_Trading

Following clarification may be useful: The term "special orders" means global exits such as setStopLoss and setProfitTarget orders. If your broker provides native stop and limit order for these instructions, then you need the 'Get Real Time Data From' option only in the case you want to act on partially filled or unfilled orders. In such case, you must use this feature in conjunction with 'Replace to Market Partially Filled Orders' and/or 'Unfilled Strategy Order Replacement' as described above.

2) On help page for Understanding Automated Trade Execution, at http://www.multicharts.com/trading-soft ... _Execution

2.1) In last paragraph in the introduction, it says: "Synchronous mode makes it possible to show a position on the chart that matches the actual filled position. However there is no guarantee that the order will get filled. When using the Asynchronous mode, every order generated on the chart is filled, ...".

This is misleading since every order generated on chart is not necessarily filled in AA mode unless order converting is used. Furthermore, such order converting may be also be used in SA mode. These two lines should just be deleted since the description that follows is good enough.

2.2) In the numbered list under conditions for SA mode sync, item #2 should be deleted since it is possible to start with non zero position and still be synchronized if you use 'Assign Market Position at Broker' feature.

2.3) The comparison table at the bottom has following:

a) Disadvantage for SA mode: "Possibility of non-execution of entry orders at broker ...". This should be replaced by something different since non-execution is a distinct possibility in AA mode as well. Furthermore, order converting may be used in SA mode to overcome this limitation just as it can be used for AA mode.

b) For AA mode, it states following advantage: "Ability to convert entry orders such as limit or stop orders if defined price mark was not met ...". This is available in SA mode too and so it is not an advantage of the AA mode in comparison to the SA mode.

Finally, my question: given that order converting may be used in SA mode just as well as it can be used in AA mode, it is not clear as to what is the relative merit of AA mode over SA mode? SA mode allows you stay synchronized if you start synchronized using 'Do not show Assign the Initial Market Position at Broker' with 'Use Actual Position at broker'. What is the relative merit of AA and why would anyone prefer using it?

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

Re: autotrading details

Postby Andrew MultiCharts » 04 Nov 2014

#11 above: "Sync of market position in auto trading mode may not work correctly if pyramiding was used. It may also not work if more than one active entry was generated on a chart." These words appear highlighted midway on this webpage: http://www.multicharts.com/trading-soft ... utoTrading
Removed. Not actual information anymore.
1) 'Get Real Time Data From' in http://www.multicharts.com/trading-soft ... to_Trading
Following clarification may be useful: The term "special orders" means global exits such as setStopLoss and setProfitTarget orders. If your broker provides native stop and limit order for these instructions, then you need the 'Get Real Time Data From' option only in the case you want to act on partially filled or unfilled orders. In such case, you must use this feature in conjunction with 'Replace to Market Partially Filled Orders' and/or 'Unfilled Strategy Order Replacement' as described above.
It doesn't affect setStopLoss and setProfitTarget orders. Only SetDollarTraling.
2) On help page for Understanding Automated Trade Execution, at http://www.multicharts.com/trading-soft ... _Execution

2.1) In last paragraph in the introduction, it says: "Synchronous mode makes it possible to show a position on the chart that matches the actual filled position. However there is no guarantee that the order will get filled. When using the Asynchronous mode, every order generated on the chart is filled, ...".
This is misleading since every order generated on chart is not necessarily filled in AA mode unless order converting is used. Furthermore, such order converting may be also be used in SA mode. These two lines should just be deleted since the description that follows is good enough.
Thanks, i changed them.
2.2) In the numbered list under conditions for SA mode sync, item #2 should be deleted since it is possible to start with non zero position and still be synchronized if you use 'Assign Market Position at Broker' feature.
Thanks, added 1 sentence.
2.3) The comparison table at the bottom has following:

a) Disadvantage for SA mode: "Possibility of non-execution of entry orders at broker ...". This should be replaced by something different since non-execution is a distinct possibility in AA mode as well. Furthermore, order converting may be used in SA mode to overcome this limitation just as it can be used for AA mode.

b) For AA mode, it states following advantage: "Ability to convert entry orders such as limit or stop orders if defined price mark was not met ...". This is available in SA mode too and so it is not an advantage of the AA mode in comparison to the SA mode.
Thanks, we will change the whole table in future.
Finally, my question: given that order converting may be used in SA mode just as well as it can be used in AA mode, it is not clear as to what is the relative merit of AA mode over SA mode? SA mode allows you stay synchronized if you start synchronized using 'Do not show Assign the Initial Market Position at Broker' with 'Use Actual Position at broker'. What is the relative merit of AA and why would anyone prefer using it?
To tell the truth i never recommend to use AA mode. In fact the only true advantage of the AA mode is that it has access to the backtesting results.

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

Re: autotrading details  [SOLVED]

Postby orion » 04 Nov 2014

Thanks Andrew. No more questions on auto trading. MC is a great product with great customer service.

The documentation can be improved. Here are some notes I made for myself. These could serve as the write up for the help page on Understanding Automated Trade Execution. Feel free to comment and use as appropriate.

When looking at synchronization, we need to focus on both synchronization of orders and synchronization of positions. Synchronization of orders is a necessary but not sufficient condition for synchronization of positions.

SA mode means that you always see the same orders on the chart as at broker without any need for order conversions as long as following conditions, called the runtime sync conditions, hold:

1) there is only one chart trading the instrument and
2) there is no manual trading in the instrument.

The term order conversions refers to the feature available in auto trading whereby unfilled or partially filled price orders may be converted to market orders.

In of itself, SA mode only guarantees order synchronization since position synchronization requires an additional condition to be met. In SA mode, you will see the same positions on the chart as at the broker as long as positions were synchronized at the start of auto trading. Note that there are three separate position values that you need to be aware of:

a) chart position accessed by keyword marketPosition
b) strategy engine position accessed by keyword marketPosition_at_broker_for_the_strategy
c) broker position accessed by keyword marketPosition_at_broker

In SA mode, the first and second position values, namely the chart and strategy engine positions, are always in sync. Also, as discussed above, the chart position and the broker position will be in sync as long as the runtime sync conditions are met and the positions started out in sync at the start of auto trading.

Position sync at start time can be achieved either manually or automatically using the 'Assign the initial market position at broker' feature settings as follows:

a) Manual sync: select 'Show the assign the initial market position at broker' to display a dialog box at start up where you can manually input the broker position for the chart.

b) Automatic sync: select 'Do not show the assign the initial position at broker' and further select the option 'Use the actual position at the broker'. This automatically synchronizes the chart position using the broker position. However, unlike the manual sync discussed above, this can only be used for synchronizing the position for one strategy and it cannot be used if you have multiple strategies on a chart that need startup synchronization. Startup synchronization for multiple strategies can only be achieved by using manual synchronization via the dialog box.

Note that 'Use the actual position at the broker' option is a new feature that was released in MC9.0. Prior to this feature release, position sync at startup could only be done manually.

AA mode means that the chart is running without any synchronization of chart orders with broker orders. Hence, the chart position and the strategy engine position may also be out of sync. By extension, positions at the broker need not be the same as positions on the chart. The only benefit of AA mode over SA mode is that it allows you to start with the position from a historical backtest and carry it forward in auto trading but without any guarantees that the three positions are in sync. Unlike SA mode where order conversions are not required, AA mode requires order conversions for chart orders to be in sync with orders at the broker. Furthermore, even the use of order conversions does not guarantee that the prices of the order fills on the chart are the same as the prices of the order fills at the broker.

We now mention some advanced concepts in synchronization. First note that in SA mode, the chart position and broker position will stay in sync if they start out in sync and if the runtime sync conditions are met. Runtime sync conditions are not met when we have either of following:

1) combining auto and manual trading
2) auto trading using multiple charts

For the special handling of these scenarios, two strategy synchronizers were developed. These strategy synchronizers are

!From Broker to Strategy MP Synchronizer!
!From Strategy to Broker MP Synchronizer!

The first synchronizer uses the special keyword changeMarketPosition to change the market position of the strategy to bring it in line with the position at the broker. The second synchronizer uses the special keyword placeMarketOrder to place a market order at the broker without the position changing on the chart.

Usage of these keywords directly by the user in their PL code is an advanced feature. It is recommended that the user desiring synchronization of orders and positions use the SA mode while complying with the conditions for runtime sync and ensuring that positions were synchronized at startup as discussed above.

FutureTrader
Posts: 79
Joined: 28 Mar 2013
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: autotrading details

Postby FutureTrader » 13 Nov 2014

so I'd like to start trading with Portfolio Trader. Let's say I've got about 20 strategies, where some are on the same symbols.
My Broker account is 100% flat. So how can I sync them at start, as there is not the manual sync dialog available.
If I start Forward Testing, there is the possibility to "close" positions. Can I use this option to sync the strategies before going on automated trading mode?

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

Re: autotrading details

Postby Andrew MultiCharts » 13 Nov 2014

So how can I sync them at start, as there is not the manual sync dialog available.
Hello FutureTrader,

If you are talking about Assign Market Position At Start Dialogue, it is availble in Portfolio Trader: make a right-click on "Strategy1" in Portfolio Tree window -> Show properties... -> Auto-Trading.

FutureTrader
Posts: 79
Joined: 28 Mar 2013
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: autotrading details

Postby FutureTrader » 13 Nov 2014

So how can I sync them at start, as there is not the manual sync dialog available.
Hello FutureTrader,

If you are talking about Assign Market Position At Start Dialogue, it is availble in Portfolio Trader: make a right-click on "Strategy1" in Portfolio Tree window -> Show properties... -> Auto-Trading.

Andrew, as you can see on my attachment, I can't enable the option "Assign the Initial Market Position at the Broker Settings"
Attachments
Untitled.png
(27.69 KiB) Downloaded 1383 times

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

Re: autotrading details

Postby Andrew MultiCharts » 13 Nov 2014

Andrew, as you can see on my attachment, I can't enable the option "Assign the Initial Market Position at the Broker Settings"
At the moment only the options "always same as broker", "always same as on chart" and "always flat" are available. If you need exactly the dialogue to modify it manually, it will be available in MC 9.1.


Return to “MultiCharts”