IB Auto-Trading, MarketPosition update frequency

Questions about MultiCharts and user contributed studies.
GD
Posts: 20
Joined: 03 Apr 2006

IB Auto-Trading, MarketPosition update frequency

Postby GD » 03 May 2007

Hi Folks,

I have some general comments and a specific question. First the question. Exactly when is MarketPosition updated? Suppose in one part of the code, you buy from a flat position. Then later in the same signal you sell. Does MarketPosition go from 0 to 1 to 0 within the signal code or is it only updated at bar end so it remains constant over the whole bar? In that case, it would always look like 0 for all the code within that bar. Related to this, is when does MC read the actual account status and update MarketPosition - or does it? The MarketPosition variable seems to ignore the actual state of the account and only represents the status as the Autotrader thinks it should be.

I want to encourage you to keep working hard on the IB Auto-trading features. I have been using the Autotrader extensively in IB simulation account mode and have noticed some strange behavior.

First and foremost, as you know, being able to set/send limit and stop orders is the highest priority. It amazes me how much money is lost in slippage without having these features.

Along these lines, it's not clear to me how to have an order executed intra-bar. It works fine when I use SetStopLoss to bail out of a losing trade, but I can't seem to get the following commands to execute any time other than after the bar closes, (ConQty is a variable with the number of contracts I want to buy or sell.)

Buy ("B") ConQty contracts this bar at market;
Sell short ("S") ConQty contracts this bar at market;

In addition, I hope you're testing interaction between manual trading using TWS and the Autotrader. For example, I would like to intervene at times to force a purchase or sale before the Autotrader acts. Also, I may want to open a trade manually and let the Autotrader close it - or vice versa.

I really look forward to the new Autotrader. It will be invaluable to me and others who can't sit at the terminal all day long.

I know there are bugs and hitches whenever you're writing major new features or software systems, but your willingness to improve and address bugs makes all the difference. And your support using HelpDesk is first class. Thanks for all your support. You're all great!

Regards,

GD

GD
Posts: 20
Joined: 03 Apr 2006

Postby GD » 03 May 2007

Well, I guess I've answered my own question. I sandwiched a Buy command between two print statements and discovered that MarketPosition is not updated until the bar closes. (Kind of like checking your wallet after the bartender shoos you out the door.) So you'll have to keep track of your own market position inside your code if you need it before the next bar.

Related to my other post, if there is a way to execute a buy or sell intrabar, is there a variable that holds the execution price? And for example, if you're stopped out using SetStopLoss, what variable holds the price at which you were stopped out?

User avatar
Kate
Posts: 758
Joined: 08 Dec 2006

Postby Kate » 04 May 2007

GD,

You are right, currently MarketPosition is updated only once since strategies are recalculated on close of each bar. And so far MultiCharts doesn't feature IntraBarOrderGeneration when MarketPosition can change several times inside a bar. Our developer are working on this feature now but when this option is implemented please keep in mind that when MarketPosition is referred several times intra bar it can overload TWS and it won't be able to respond timely and in its turn it will result in incorrect information inside a bar.

SetStopLoss functions in a different way than other entries and exits.

In addition, I'd like to say that in the nearest future we will release a special IB auto-trading add-on (a number of functions) that will enable you to handle your orders from the script, MarketPosition as well. You will be able to use these functions not only with strategies but also with indicators that are recalculated several times inside a bar by default and you can refer MarketPosition several times.


Return to “MultiCharts”