TWS/Gateway restart & order desyncs

Discuss, post questions here about MTIBBridge the MetaTrader-Interactive Brokers trade-copier

Users who just registered, please write an email to
forum@trade-commander.de
with your username mentioned.
So we can distinguish you from bots.
Thank you
Post Reply
Melle
Posts: 2
Joined: Mon Feb 28, 2022 12:33 pm

TWS/Gateway restart & order desyncs

Post by Melle »

TWS and IB Gateway need to restart on a daily basis. This restart can take around 10-20 seconds.
If a trade has been opened during this restart moment, the trade will not be copied to IB, causing a desync.

1. How do you fix/prevent this?

I watched your tutorial about auto restart feature of TWS: https://www.youtube.com/watch?v=uZZL0fmp7FU
The option presented in the video is not available in my version of the Order Copier?


Regarding desyncs in general; what should a person do when a desync occurs?
2. Is the trade copier able to fix desyncs automatically?
Re-initializing the ib_order_copy EA in MT4 seems to work, but this is a manual thing.


An interesting situation happened last week. Trade copier had closed it's positions, but did not fully close 1 position, still 1 quantity was left:
Image
3. Seems something went wrong with the Order Copier's calculation of position scaling?
I "fixed" this by manually re-initializing the ib_order_copy EA in MT4. Not favorable of course.

Hopefully there is an option to keep in sync and properly scale positions.

board_admin
Site Admin
Posts: 241
Joined: Mon Apr 24, 2017 3:24 pm

Re: TWS/Gateway restart & order desyncs

Post by board_admin »

The copier feature in the video related to autostart has been removed. No longer needed.

1.
I made a test and could not reproduce this. My test was as following:
1.1 Place an order in MT (open position)
1.2 Order get's copied. Position opened in TWS.
1.3 Close TWS
1.4 Close position in MT
1.5 Restart TWS
1.6 Position closed in TWS

Perhaps raise MKT order timeout in copier menu / Setup / Misc. Settings
to 120 seconds or something like that.

Also make sure that connection to TWS does not require your confirmation.

2. If desync happens
- close all position on MT side
- detach ib_order_copy
- adjust position at TWS manually (to close at market you can use copier account window for this)

Melle
Posts: 2
Joined: Mon Feb 28, 2022 12:33 pm

Re: TWS/Gateway restart & order desyncs

Post by Melle »

1. I see. MKT Order Timeout was at 10 seconds (default). Possibly TWS was taking longer than this to restart.

2. I understand. But on a live account you wouldn't want to force close trades just because of this.
Might be worth to take a look into position sizing?

Lets say we have an MT account with $100k balance, and a TWS account with $200k balance.
We copy from MT to TWS with balance ratio 1.0.

2.1 MT account opens 1.00 position
2.2 TWS account copies the MT4 position at 2.00 size
2.3 MT account receives a $100k deposit, making its balance $200k
2.4 MT account closes the 1.00 position
2.5 TWS account closes only 1.00
2.5 TWS account is left with an unmanaged 1.00 position

Would this scenario describe it well?
I think this was the cause of a remaining position with 1 quantity in TWS. Account balances between MT and TWS can change during trades, due to swap, difference in commissions, slippage, different price feeds making slightly different profits.

Please correct me if I'm wrong.

board_admin
Site Admin
Posts: 241
Joined: Mon Apr 24, 2017 3:24 pm

Re: TWS/Gateway restart & order desyncs

Post by board_admin »

The copier ist working on order basis, not balance.
The multiplier is applied when you place the order.
The closing size depends on open size what makes sense.

I see the problem below, but it is related
to the deposit.

In this case, closing remaining size in TWS manually
should work.

Post Reply