IB_Direct

V4.015 Beta

DRAFT

Friday, June 23, 2006

DISCLAIMER:

This software is provided on an “as is” basis.

Although it has been carefully tested, errors are always possible

as it is NOT possible to anticipate all eventualities

in a chaotic, uncertain world…

Prerequisites
& Recommendations. 3

Introduction. 4

Starting the IB_Direct program.. 4

The IB_Direct main dialog. 6

System menu. 6

Ticker area. 8

Entry/Exit Buttons. 8

Function Buttons. 9

Order Type and Size. 10

Financial Advisor Settings. 11

Order Status 1. 11

Order Status 2. 12

Connecting to IB. 13

Status. 13

On the TWS side. 14

On the IB_Direct side. 14

Settings. 17

Settings details. 18

Paper Trading. 19

Log File. 19

Registry. 19

Trading with IB_Direct 20

Ticker. 20

Order Management 20

Adjusting stop/limit prices (primary order). 21

Canceling an order. 22

Attached Stop/Limit Orders. 22

Canceling Stop/Limit Orders. 23

Last word. 24

Some Troubleshooting tips….. 25

Prerequisites & Recommendations

Ø
IB_Direct v4 relies heavily on the MS Windows™ Registry[1] to store many default
parameters as well as current order information in case of interruptions such
as PC failure, IB stoppage, or Internet connection problems.  Please always check for any possible registry
corruption or Windows issue with adequate utility program.

Ø
The IB TWS works within the
Java Run-Time environment.  It is highly
recommended to upgrade to the latest Java
Virtual Machine (currently v1.6 with or without SDK)

Ø
Java and the TWS can use up a
substantial amount of RAM.  To
ensure there isn’t excessive paging, RAM specs are as follows:

Minimum:
256MB   (Recommended: 512MB or more)

Ø
The latest IB API must be first installed.  However, the IB API is almost in
permanent beta stage, and is very poorly documented.  This has not made programming around it
very easy.  At this time, the
current version works with API
V8.8 (May 2006).  Please note that the API interface
sometimes changes radically with a seemingly minor update, and may cause IB_Direct to stop functioning.  In such rare events,
please downgrade to the previous API until I fix the IB_Direct calls according to the new interface.  One can only hope the API interface will
soon stabilize.

Ø
If the API Setup does not
automatically register the TWS.OCX, the program will crash upon loading the
main form.  Please register it
manually the following command: “regsvr32 C:\JTS\ActiveX\Tws.OCX” (you
may have to change the path according to actual location).

Ø
The program setup may require
the .NET framework from Microsoft.
It is usually installed along with Windows XP but can also be downloaded
separately at http://msdn.microsoft.com/netframework/downloads/updates/default.aspx
.  IB_Direct requires the
following files which are bundled in the setup file: MFC70.DLL, MSVCI70.DLL,
and MSVCR70.DLL (or later versions).
Please contact
me in case the setup program does not install them correctly.

Ø
It is essential to fully
understand how orders are processed at IB for the exchange being traded.  Users should therefore read carefully
the following page: http://www.interactivebrokers.com/html/webhelp/TWS_Reference_Information/Order_Type.htm

Ø
Lastly, although not required,
a multiple screen setup is recommended.

Introduction

The ultimate purpose of the IB_Direct program is to
handle signals coming from an automated trading system and send orders
automatically to IB through
the TWS Java console.  Its
functionalities are more straightforward than this (too) long document may
suggest.

The IB_Direct program in the
current version is not yet linked to an external signal source, hence orders
are entered manually into the IB TWS at a click of a button hence allowing fast
safe simple trading (scalping strategy).
While the TWS Java console(s) need to be running along with IB_Direct,
they can be minimized as IB_Direct represents the essential trading “dashboard”.

The user interface has been designed to be
as intuitive as possible.  I have
tried my best to keep it as simple and as uncluttered as possible…

This walk-through guide will start with
running the program and describe its program design and layout.  As we go along, it will then explain in
details how to handle different order set-ups.

Starting the IB_Direct program

When the program starts, the user is
prompted to enter the number of IB TWS
(local or remote)[2]
consoles he will wish to connect to.  3 concurrent IB accounts[3] (i.e. 3 separate TWS
instances) can be linked at this time.

Fig 1

(Layout may change in final release)

What do we see on this screenshot (Fig1 on page 3)?

Ø
On the left side is a list box
where to select the number of IB accounts the user wishes to link to.  That number of IB accounts[4] (1, 2 or 3), like most
settings in the program, is saved as default in the Windows™ Registry.  As displayed above in the dialog box, the
1st IB account must have a valid[5] data subscription[6] with IB.

Ø
An IB_Direct session id or session number has been added.  This allows to fully separate settings
in the Registry in case several instances of IB_Direct run concurrently for different instruments.  Each instance can then connect
independently to the same IB TWS Java consoles.

Ø
Registration will enable IB_Direct to run permanently after
the trial period has expired.  A
serial code or license will be issued per user on a single PC.  This license will also be linked to
hardware (HD serial number).  This
feature is not activated yet in this BETA version.

Ø
This initial form also offers
an Internet Time Synchronization (“Time Sync” button) based on the
RFC868 protocol.  IB_Direct must be firewall-enabled to connect to the Internet Time Server
(time.ien.it by default).  The time
sync may take some time depending on connection speed and server availability.  It is run in a different thread which can
be interrupted if necessary.  When
time is returned from the Internet Server, system time is also updated on your
PC (admin privileges are required with Win2K, Win XP).

Ø
The program also checks for the
API version.  It will display an
alert if an upgrade is required, and then close.  The current IB_Direct build works with
the last API v8.71 which seems to be quite stable.

Ø
In the final release, this
dialog will also display a “Check for Update” button.

On rare occasions, it may be necessary to
clear all registry settings.  Such
option has been added to the system menu (program icon at top left corner of
the window).  A major program
release may also force automatic reset of those settings to predefined default
values.

When ready, just press
“Proceed”, or the Enter key to continue.

The IB_Direct main dialog

After pressing “Proceed”, the
main IB_Direct form should now be displayed as shown below.  Its footprint has been substantially
reduced from earlier versions.

Fig 2 (Actual layout may change
slightly in final release)

In a nutshell, the above dialog is composed
of a ticker area, order buttons (arrows), program menu buttons, and optional info
area at the bottom.

Before describing these various elements on
this main form, let’s first take a look at the system menu (top left icon
on the main dialog above), to which a few custom items have been added.

System menu

Ø
“Settings”,
“Connect” and “Disconnect” are just function copies of
the buttons on the main dialog form.

Ø
“Reset buttons
status” has been left while debugging the program, and may be of use in
some rare occasions.  In normal
trading operations, an entry/exit button is disabled after being clicked in
order to avoid entering multiple positions by mistake.  In some cases, a trader may however also
want to scale the current position up or down.  The program has not been fully tested
for this trading mode though.  On
many occasions, new features have been coded to see them added to the API a few
months later.  Let’s hope IB
will do something about this functionality.

Ø
“Enable/disable order
button control”. As said above, one may choose to disable buttons to make
sure that an exit always follows an entry.

Ø
“Clear Order Ids in
Registry” will reset recorded order Ids. It may sometimes be needed particularly
in the situation where the user has placed/cancelled orders directly into the
TWS, thus creating a possible discrepancy in order numbering.

Ø
“Clear Connect
Ports”: if a connection to the TWS fails for any reason, the ports
settings can be cleared here instead of closing IB_Direct altogether.  By default, IB_Direct will always connect
through the same ports, e.g. 7496 for TWS1, 7497 for TWS2, 7498 for TWS3.

Ø
“Clear All Registry
Settings”. Same as on the initial dialog, all registry settings can be
cleared here.

Ø
“Return to MKT order
type”.  When one enters a
trade Limit or Stop, one may forget to reset order type to Market, which seems
sensible in case one wants to get quickly out of a position.  If this option is ticked, order type
will be reset to MKT on fill confirmation of STP or LMT entry order.

Ø
“Request IB news
bulletins”[7].  There are several levels of news
bulletins which can be sent to the Info/Status window if so desired.  A dialog is displayed to select the
filter level.

Ø
“Set Log Level”. IB
info stored in c:\jts folder for
debugging or recording purposes.
This info is not modified in
any way by IB_Direct.  In case of a query to
IB (no fill, bad fill, late market fill, etc…), this log file can be sent
to IB as is for enquiries.

Ø
“Window stays on
top”

Ø
“About IB_Direct”

Let’s now take a closer look at the main elements now displayed:

Ticker area

The upper left list containing prices is
the ticker received in real time from IB.

Fig 4

The ticker starts automatically upon
connection.  Bid, Ask and Last prices[8] are displayed, along with
1 Tick Up and 1 Tick Down prices.
Double-clicking a price sets a limit price for the next order (order
type is also changed to LMT).  For
instance, a double click on the Bid price (1145.25) followed by a Buy will send
a “BUY 2 ES LMT 1145.25” order to IB.  This will be explained again later in
this document.

The ticker can be stopped using the On/Off
buttons if deemed distracting.  The
ticker is however required in most
cases, unless one chooses to trade market orders only (quick scalping,
reversal strategies for instance).

The time displayed on the left is the last
ticker update.  The figure on the
right (381) is the number of contracts or shares traded in the last
minute.  It may be an indication of
low trading activity.  Please note
however that volume reported by IB does not always seem to tally with volume
figures reported by other data sources.  This situation may improve now that IB
also provides data streams through the API (since v8.50).

Entry/Exit Buttons

Entries and exits use the same buttons as
shown here (arrows):

They can alternatively be displayed by acronyms (below).  In doubt, all buttons have context tips
(mouse hover).  The acronym version
is disabled at present, but it can be reinstated if arrows seem confusing.

BE is Buy Entry. BX is Buy Exit. BR is Buy
Reverse (exit long then entry short), etc…

In order to make sure entries or exits are
not duplicated, only allowed buttons[9] are enabled by
default.  IB would otherwise for
instance let you enter into a buy by pressing SX twice.  In case of a bug, or to override this
feature, button status can be reset in the system menu.

Please note that pressing the order button
is in a way a confirmation of any prior setting, particularly the Order Type
and Price for Stop or Limit orders.
There is no added confirmation box
here.  In other words,
everything has first to be correctly defined.  This particularly applies to Limit and
Stop entries or exits.

Settings remain unchanged after the order
is sent through, i.e. by default a Bid/Ask type entry will be followed by a
Bid/Ask exit.  You may however want
to enter limit and exit market.  It
is actually recommended to revert back to Market order once entry has been
filled and manage the open position with optional attached stop and limit
orders.

Function Buttons

Fig 6

These buttons are placed on the right of
the main dialog.

Ø
ON and OFF are connection
buttons to the IB TWS.

Ø
The next button below with
tools displays the Settings dialog (opened automatically upon valid connection
to the TWS).

Ø
“Info” displays the Status /
Info window.

Ø
“S/L Entry”
displays a modeless form where the user can set or adjust Stop/Limit entry
price(s)

Ø
“S/L Exit” displays
a modeless form where the user can set or adjust Stop / Limit exit prices.  It is recommended to exit a position
that way.

Ø
MktDepth or AdvMktDepth display
additional information about the order book.  AdvMktDepth can be used to place / amend
orders.  Since most trading
operations can be carried out from the AdvMktDepth features, a specific section
is available later in this document.

Ø
“Refresh” sends a
message to IB to refresh the open[10] order status.

Ø
“Cancel” as its
name says, cancels the currently pending open order[11].

Order Type and Size

Order type is defined with the list box (see right).

Valid order types vary according to
exchanges, and IB will in most cases offer a simulated order type if not
supported natively by the exchange.

Order types currently supported by the API
are:

Ø
MKT                           in
IB_Direct

Ø
MKTCLS                    relevant
to institutional clients only

Ø
LMT                           in
IB_Direct

Ø
LMTCLS                    relevant
to institutional clients only

Ø
PEGMKT                   relevant
to institutional clients only

Ø
STP                             in
IB_Direct

Ø
STPLMT                    in
IB_Direct

Ø
TRAIL                                    in
IB_Direct

Ø
LIT                              in
IB_Direct

Ø
MIT                            in
IB_Direct

Ø
REL                            coded
in IB_Direct, but not activated

Ø
VWAP                        may
be added in the future

Order construction does not differ
significantly according to its type, so it should be relatively easy to add new
ones if so desired.  Please always
check the selected order type is supported by the exchange and instrument
traded.

LIT
(Limit if Touched) and MIT (Market if Touched) are the latest additions to IB_Direct.

Like STP
and LMT orders, LIT and MIT require trigger prices.  To make sure the user does not forget,
the entry price dialog pops up when LIT or MIT order type is selected.

Default order size is defined in “Settings”.

Order size could also be amended on the
main form, but this feature is seldom used, so has been disabled in BETA
version.  In most cases, one will
choose to select a type of entry to increase order size.

A very simple rule is here used, i.e. a
simple multiplier:

Ø
Conservative:            use
default order size

Ø
Balanced:                  2
X default order size

Ø
Aggressive:                3
X default order size

Ø
Very aggressive:       4 X default
order size

Like order size, such multiplier cannot of
course only be modified while in position.

Financial Advisor Settings

Some settings are available on the main
dialog form.  These core
functionalities have been extracted from IB sample code, and should work OK.  They however could not be tested using
the IB demo account.

Order Status 1

The next display area is the order status 1
list control.  This part of the
dialog is hidden when not in the market.
It is possible to visualize it briefly however by pressing the
“Refresh” button.
Additionally, in order to keep the UI fairly uncluttered, this area
actually has several functions:

Ø
When the entry order is filled,
it will display the attached stop and limit exit orders, with current total
position and exit prices.

Ø
When the order is not filled yet
(stop/limit entry), it displays the pending order details submitted to IB.

One must understand that this list is a
container for order status messages sent back by IB.  Since those messages have to fit on one
line only (per TWS), on some occasions, they may supersede (or erase) a
previous message (if unrelated), or complete a previous message (for instance,
limit exit submission message after stop loss exit submission message
pertaining to the same entry)

Usage notes (UI):

Ø
Clicking on the Order Status 1
list refreshes the open order status.
Unlike the “Refresh” button, this applies to any status
change from orders initiated on IB_Direct only.  The
“Refresh” button calls for a status update on all open orders[12]
for the current symbol, including those made directly on the TWS.

Ø
Double-clicking the Order
Status 1 list clears the list.

Ø
Right-clicking the Order Status
1 list allows for cancellation of open orders (both pending entry/exit and attached
exit orders).

Ø
It is possible to select which
account(s) to include or not for next orders to come (this does not apply to
existing orders in the market, i.e. cannot be used to cancel orders).  The TWS1 cannot be excluded.

This option must be with extreme caution
as it may quite difficult to follow orders sent on such or such TWS.

Here is an example (Fig 5)
of a long position with 1 stop and 2 limit exit orders:

Fig 5

The status list shows stop and limit exit
orders for a total of 2 contracts.
In this case, 2 contracts will be sold at 1154 STP (StpP), 1 contract
will be sold 1157 LMT (LmtP1), 1 contract at 1159 LMT (LmtP2).  It is a “display only” area:
Exit orders cannot be modified here.

Please note that identical orders are
always sent to all enabled IB accounts (check box).  If an account is disabled, following
later positions may be very difficult.
This feature should therefore be used with extreme caution.

Order Status 2

The bottom list displays the last
order status retrieved from IB.
Upon fill, up to 6 attached orders (3 stops & 3 limits) can be sent,
so the returned status info will come in bursts, and only the last item
can be here displayed.  All
information is however recorded on the Status/Info window (Fig7) as well as in the log file.

This list is more useful to check the status
of a pending primary order (i.e. stop/limit entry or exit)

Possible values include:

Ø
PendingSubmit
- indicates that you have transmitted the order, but have not yet received
confirmation that it has been accepted by the order destination.

Ø
PendingCancel
- indicates that you have sent a request to cancel the order but have not yet
received cancel confirmation from the order destination. At this point, your
order is not confirmed canceled. You may still receive an execution while your
cancellation request is pending.

Ø
PreSubmitted
- indicates that a simulated order type has been accepted by the system and
that this order has yet to be elected. The order is held in the system (and the
status remains DARK BLUE on the TWS) until the election criteria are met. At
that time the order is transmitted to the order destination as specified (and
the order status color will change).

Ø
Submitted
- indicates that your order has been accepted at the order destination and is
working.

Ø
Cancelled
- indicates that the balance of your order has been confirmed canceled by the
system. This could occur unexpectedly when the destination has rejected your
order.

Please check on the IB web site
for possible updates (also see order
types).

Connecting to IB

Before going any further with this process,
it is important to present an important feature in the IB_Direct program:  the
“Status” window.

Status

Fig7

The status list is a small window adjustable
in size, where all major events will be shown (new lines come on top).  Errors will be displayed in Dark
Red.  Warnings are displayed in
Green, and general info in Blue.

This window has an “always on
top” flag, but it can be hidden.
It can also be extended width-wise if the message is too long to
display.

Let’s now look at the connection
procedure.

On the TWS side

An IB TWS Java console must be running for each IB account being traded, and ActiveX
clients must be enabled (see below).
TWS windows can be minimized since they should not be needed during
trading.  Memory usage should not
increase significantly with more than one IB account, as only one Java Virtual
Machine is running.

(TWS layout is likely to change)

Warning: please note the IB TWS having been
first designed to handle single accounts, running several TWS consoles may be a
little tedious at first.  IB_Direct will always associate each TWS to a definite port.  It is recommended to always open the
several TWS consoles in the same order and check their default socket port.  The ticker will be called from TWS 1.

Open orders and positions are always
checked by IB_Direct.  The “Download
Open Orders on Connection” setting may not really matter, but it is
recommended to leave it on.

On the IB_Direct side

Press the “Connect” button to
link to the TWS[13].  Connecting is actually a local system
process, since the TWS is the Java program which will handle the communication
over the Internet with the server at IB.

The Port number must of course coincide
with the socket parameter that has been set in the TWS configuration.

The IB_Direct program may be
running on a different machine than the TWS through IP channeling if
needed.  If the IP field remains
blank, it is assumed that the TWS is located on the same
PC (IP “local host”), otherwise please enter the IP address of the
computer running the TWS in question.
The remote TWS[14] may however be protected
behind a firewall, so please check your router settings as it may be necessary
to open a router port.  The port
number to open is the same as the TWS socket number.  This of course should not apply if the
IP address is located on the same LAN i.e. if the connection is made between
computers behind the same firewall.

The client Id[15] is generally irrelevant
for individual accounts.  The
program relies entirely on authentication as handled by the TWS, and the only
valid link identifier per se is the Port number (7496 in the example above).  However, Client Id can also be used to
allow several instances of IB_Direct to connect to the same
(local or remote) TWS, to trade different instruments for instance.

The option “Account Specifics” makes
it now possible to trade a different number of contracts/shares for each IB account.   Caution should be exercised here,
particularly if fractional exits are used.
Other account specifics may
be added in a future version.

Press OK when ready.

A message appears in the Status window[16], asking you to
acknowledge the connection request on the IB TWS window.   The only response from IB, when
connected, is the next valid order id[17] which may then be used in
the system.  Order ids are handled
automatically by simple increment within the program.  As you will see, when stop and limit
orders are used, the main entry order number is immediately followed by the
stop order(s) and limit order(s) numbers.

Connect / Disconnect[18] does not use a toggle
button as one might first expect.
The reason is that it is better to handle multiple connections this way.  If a connection to an individual TWS
drops[19], it can be restarted by
clicking the Connect button without affecting other running TWS.  Disconnecting does not reset connection
ports.  Ports can be cleared by
restarting the program or from the system menu.

Settings

The Settings dialog will appear
automatically upon successful connection to the TWS.  Please refer to IB Help page
for further details.

(Layout may change slightly in final release)

It can also be later called from the system
menu or by clicking the toolbox button.

Settings are sent to IB upon closing this
dialog, so while settings can be consulted off-line, they are only truly valid
upon successful connection to IB.

In most instances (particularly day trading
futures), little will need be changed here except maybe for default stop/limit
points, and the contract expiry.  All
settings are saved in the Windows Registry.  The above settings are OK for ES
e-mini.  The Extended Attributes[20] do not really need to be modified
at this stage (see IB
documentation for details).

Only 1 ticker is used at present (i.e. only
1 instrument is traded).  Please
note that the TWS only serves as a “Java” gateway to IB, i.e. the
broker.  The ticker being selected
does not have to be defined in the TWS, although it is most advisable to do so
to check orders are correctly built and transmitted.

Settings details

The ticker frame includes all minimum[21] settings required to
trade either futures or stocks.  It
does not however cater for options at this stage.  Order construction is basically the
same, so it should not be a problem to add options specifics to this form if
needed.

In most cases, IB orders are routed through
GLOBEX for futures or SMART for stocks.
Primary exchange and multiplier are to be left blank for futures (new
addition to the API v8.3).

The exit order frame includes details for
attached OCA[22]
orders.  In normal trading
situations, an entry will be covered on both sides by a stop loss order and one
or several limit orders (up to 3 fractional exits).  Stop orders can either be fixed or
trailing[23].
A unique price is used for all stop
orders[24].  OCA orders will be described in details
later in this document.

An option has been added to force exit on
End-Of-Day, specified by a set time (local exchange time + time offset).  “Market on Close” orders are
generally not accepted for retail customers, hence have not been coded in this
program.  Again, order construction
would be virtually identical, so this could be added if need be.  A forced EOD exit does about the same,
although processed differently at IB.

Volume alerts can be used to signal low
volumes or sudden bursts in volume (as reported by IB).

BETA VERSION:  levels of Verbose and Debug logging may
change until final release.

Paper Trading

As its name suggests the “Transmit
orders to IB” checkbox allows orders to be stopped at the TWS for
confirmation.  One could think of
using it to for instance distribute signals to remote TWS consoles (through the
IP address attached to the port number), where the recipient user would vet the
final decision on the TWS itself.

It is therefore not quite an
alternative to paper trading with the IB demo account (account: edemo, password
demouser).  When using the paper
trading option, orders are not generated at all but are displayed in the status
window and recorded in the log file.
As such this cannot emulate fills.

Please note that the IB demo account does
not provide accurate market data.
It is most recommended to log in and open a paper trading sub-account on
the IB web site.

Log File

Most events are recorded in a log file
stored in a C:\JTS sub-folder.

For example: “C:\JTS\IB_DIRECT_Log\IB_Log_1_210405.txt”
will contain details for Session 1 on April 21st, 2005.

A specific order log file is also created
in the folder “C:\JTS\IB_DIRECT_LogTrade\”.

Registry

For your information, all settings recorded
when closing the “Settings” form, are stored in the
HKEY_LOCAL_MACHINE, SOFTWARE section of the Registry under the IBDn key (n
being the session number) under the following sub-keys:

Ø
Connect

Ø
DefaultSettings

Ø
LastOrders

Trading with IB_Direct

We have now described most of the
program’s user interface. We are now connected to IB.  It is time to trade with it…

If the program has been run at least once,
just to check the various forms, the connection to the IB TWS, as well as the
ticker, then all settings have now been stored in the registry.  Subsequent uses of the program will
possibly require less attention as all previous settings will be restored
automatically.

Ticker

The ticker has been already briefly
described in the introduction. Bid/Ask/Last Trade price and volumes are
displayed in real time.  Time of the
last ticker update and accumulated volume in the last minute bar are also shown
(dark red background boxes).  One
generally avoids trading when volume per minute drops below 1000 (ES e-mini).

Clicking on the ticker bar can be used as a
simple shortcut for limit entries. The selected price is set to be used in the
next limit order (entry or exit), and Entry Type changes to Bid/Ask Limit (for
Bid/Ask price) or Limit (for 1 Tick down or 1 Tick up).  The Entry Type list box gives the same
entry/exit options, but also includes the Stop-Limit entry/exit.  Please note that the price itself is not
recorded at that point.  If Bid or Ask is updated before the
order button is pressed, the last current price will be used.

Clicking on “Last” reverts to “Market”
order type.  It is recommended to do
so, as one may sometimes have to exit quickly from an adverse position.  Alternatively, the System Menu includes
an option to always return to market type order after a stop or limit entry.

If the ticker is not active,
double-clicking the ticker opens the “Settings” dialog.

Order Management

IB_Direct is connected, ticker and order settings are defined, and the ticker
is running.  Everything is now ready
to place an order.

The order buttons have already been
described.  Placing an order is
therefore quite straightforward.
We however recommend to practice
placing orders with the IB demo account for a while to become familiar with
the order status and other messages received from IB.

Let’s assume an order[25] is sent to IB.  In this first example below, it is a
“BUY 2 ES 1147.75 LIMIT”.
Prices have started moving up, so we may consider increasing the limit
price[26] in case we anticipate the
order not to be filled.

Adjusting stop/limit prices
(primary[27] order)

(Layout may change in final release)

If the current entry/exit pending order is
STP, LMT, LIT, MIT or STOP-LIMIT, and has not been filled yet, price[28] can be updated.  Pressing the “S/L Entry”
button displays a modeless[29] form on which such
price(s) can be modified using the slider control.  Changing Order Type (1 TICK LMT on
previous screenshot) also displays the “S/L Entry” price setting
dialog.

The required entry price can be now set,
with or without closing the dialog.
The pending order can also be cancelled altogether here too (“red
cross” button).

Obviously, this price adjusting feature is
not applicable to a market order which is (meant to be) instantaneously filled.  Users who want to experiment STOP-LIMIT
orders should refer to the IB
documentation to make sure which the right trigger method may be used (may not
be applicable to GLOBEX).  A word of
caution is needed at this point: stop orders are not always native orders on
the exchange being trader.  Although
this should work just as well on simulated stop orders, discrepancies may occur
(actually often on the IB demo accounts).
The STOP-LIMIT trigger method can be set in the Extended Attributes
settings.

Changing a LMT price has no effect on a
STOP order.  Reversely, changing a
STP price has no effect either on a LIMIT order.

Please note that this setting can be
applied to both entries and exits.
It must be used with caution for reversals.  A reversal to short is made of an exit
long followed by a sell short.  A
Bid/Ask limit reversal will therefore built as a Sell Ask followed by Buy Bid
which may be difficult to fill, and relatively inefficient for a reversal which
is usually meant to be quickly executed.

Lastly, it is possible to set a limit exit
order by clicking a price on the ticker, pressing the buy exit or short exit
button and possibly adjusting it later as described above.  It is however recommended to instead use
attached exit orders for that purpose (see below).

Canceling an order

This may sound obvious, but it is clear
that only STP or LMT or LIT or MIT or STOP- LIMIT unfilled orders can be
cancelled, as MKT orders are executed immediately (cancellation is not
synonymous to closing a position).  The
“Cancel” button applies to primary orders (i.e. not attached
stop/limit orders).

Please note that order cancellation may
take some time to show on the TWS and on IB_Direct.

Attached Stop/Limit Orders

Stop loss and Limit target orders can be attached
to the primary order (see “Settings”), and it is always most
advisable to do so.

In the current version of IB_Direct, up to 3 stop and 3 limit orders can be generated.  The 3 stop orders are set at the same
price, and are each linked to a corresponding limit order in a separate OCA
group.  This allows keeping the
right balance (current position) in open orders, i.e. when the 1st
limit is hit and filled the attached stop is cancelled immediately.  Please note that being an OCA group,
everything is handled at IB servers, so this is quite safe to use should
anything happen locally.

Price can be adjusted anytime while not
filled by pressing the “S/L Exits” button, which displays a
modeless dialog.  Order updates are
generally carried out within a fraction of a second.  Updating exit levels is the main trading
tool to maximize profit (limit) and minimize risk (stop) while in position.

Unfilled attached orders cancel each other
when one is filled (OCA), or are all cancelled on normal exit/reversal.

Here is an example where an entry order has
been filled and 2 limit orders have been generated with their corresponding
stops (i.e. 2 OCA groups).  The 3rd
Limit order area has been disabled since irrelevant.

(Layout may change in final release)

The sliders have a set increment equal to
the tick size, which is quite appropriate for futures.  Each order can be adjusted separately,
in case an overall update would in certain cases reset the position of other
stop or limit order(s) in the order book.

In the example above, the user selected to
have fractional exits (1 stop order, and 2 limit target exits), so the 3rd
exit level is disabled.

Each individual button on the right-hand
side validates your choice.  The
other buttons (top right) either update your exit orders or just close the
dialog.  It is likely that updating
exit orders does reset the position in the order book, hence it is recommended
to avoid doing so unnecessarily.

A word of caution

OCA orders as the name entails will have
all orders in the same OCA group cancelled when one is filled.  If the order is however partially
filled, the rest of the group disappears, and yet there is no reason to assume
the remaining contracts or shares will ever be filled.  This may lead to imbalance in the open
position.  Extreme caution must
therefore be exercised here, particularly when the trading is slow or when
volume traded is low.

NOTE:  API 8.5 now offers different OCA
types.  The feature is implemented
and is offered for beta testing.

Canceling Stop/Limit Orders

On some occasions, it may be desired (or needed)
to force the cancellation of an order, for instance to let the last limit order
“run”, or the order clean-up failed (OCA error), or any other
reason.

To do so, just right-click the Open Orders
List 1 and cancel open orders one by one:

It is recommended to first call for a
status refresh to better associate order ids with the corresponding order.

Last word

Every attempt has been made to release this
program free of “bugs”.
As you have surely understood by now, this program relies on an API
which is anything but stable (errors 202 and 505 are still trapped pending
updates from IB).  In addition,
testing it using the demo server has not always been entirely satisfactory (simulated
stops are sometimes not operational).

A lot of effort has been put to ensure that
information is always saved into the registry in case of momentary PC failure,
disconnection.  The program should
be able to recover from all situations.
On normal program exit, recorded information for open positions and
pending order is cleared.  Testing
and feedback will be very much appreciated.

There is a possible remaining issue with
partial fills, which has until now also been difficult to test fully.  I will try my best effort to ensure
trading with IB_Direct is always as safe as possible, with due consideration that it is
impossible to cover all eventualities.  It has been for instance found during
testing that the connection to IB may drop for any odd reason (IB server or
Internet connection).  Upon automatic
reconnection, IB sends a message “Data maintained” whereas orders
have in fact disappeared.  It is therefore imperative to always monitor
open positions.  IB_Direct is in my opinion a valuable tool in the direction of automated
trading.  However, we are still
miles away from having the PC trade for you while sipping a daiquiri watching a
beautiful sunset…

Happy trading,

bruno voisin

Some Troubleshooting tips…

It
is not possible to ensure 100% guaranteed error-free order management.  There may be rare
cases where orders will have to be modified or cancelled directly on the TWS.

Even if IB_Direct always tries to
always keep everything in check on the TWS, discrepancies may happen, and should
be reported to me.  There is always
a slight chance of a bug creeping up in the code, or more likely the user
environment may be not tight enough.
In such event, it is recommended to cancel the order on the TWS (click-right
and close position for instance), and clear all registry settings.

Errors will be very rare.  Please try and replicate the error on
the IB paper trading account at least twice, then send a detailed log file to [email-masked] .  It may be a bug, but in most cases, it
will be some misunderstanding of the program (poor documentation…) or
some issue with the messaging system in IB.  This program relies entirely on IB
sending the right information at the right time…

Other reported issues or clarifications:

Ø
IB_Direct is by default configured to have all orders covered by opposite
stop and limit orders.  It is mostly
recommended to exit prematurely by adjusting those existing orders instead of
creating a new exit order.  Orders
work in OCA mode, and it is simply far less error prone to close an order group
that way instead of generating a new exit order cancelling the previous order
group.

[1]
Recorded in the HKEY_LOCAL_MACHINE, SOFTWARE section of the Registry

[2]
Remote TWS can be accessed via their IP address (a port may have to be opened
to access it through a firewall).

[3] Since API v8, IB_Direct now also caters
for Advisor
accounts. This will allow trading many more accounts through “umbrella”
accounts (max 15 per non-professional advisor).  In order to keep the UI simple and easy
to use, the Advisor function (contract allocation, monitoring individual
accounts, etc…) have however not been fully coded in IB_Direct yet (due to lack of demand), but the functionalities
are there.

[4]
Please note that the number of connected TWS consoles cannot be changed once
the main dialog is loaded, but accounts can be momentarily deactivated on the
main dialog form if so desired.

[5] Log
on to the  IB web site for details
(exchange fees etc)

[6]
Technically
IB_Direct will accept simple market orders
without an active IB ticker, but this is certainly not the recommended usage.

[7]  Please note that news bulletins and
logging info are called through the
1st TWS only.

[8]
Price changes color if it goes up, down, or stays unchanged.

[9]
CAUTION: if button control is disabled, and orders can be inadvertently
repeated by pressing an order button twice (or more).  Pressing the wrong button, like exit
long for a sell short may also have adverse consequences.  IB should differentiate both entries (technically
it is a SELL for a exit long, and a SSHORT for a sell short) but testing on the
IB demo account proved that it does not always do it…

[10]
This calls for status update for ALL open orders, including changes made
directly on the TWS.

[11]
This applies to the primary order, i.e. normal entry or exit, but not the
attached OCA exits, which are handled separately.

[12]
This slight difference may seem subtle, however one must take in consideration
that the TWS may not always be local to IB_Direct.  IB_Direct can be used to disseminate
signals to one or several remote TWS console(s).  In addition, irrespective of its
location, the TWS may stop all orders for confirmation.

[13]
The Info window will pop up automatically unless this option is disabled in
program settings.  That window is
set to be displayed on top of other windows.

[14] A
remote TWS is generally used to separate order management from charting.  It can also be used to send orders i.e.
signals to a truly remote client.
In such case, caution should be exercised as of legal implications
regarding actual order management (location vs. origin of decision)

[15]
Client Id may or may not be merged with Session No in a future version.

[16]
The Status window stays on top of other windows. It can however be
minimized.  It must be active to
record events (even if minimized).

[17]
Order Ids are stored in a JTS sub-folder.
Hence they should keep being incremented.  It is possible to reset the counter by
deleting that folder (named “darykq” in current API releases).  Deleting that folder will probably also reset
all your TWS default settings.

[18]
Double clicking the Disconnect button also clears port settings

[19]
IB will try and restore the connection. No action needed.

[20] Please
note that all orders are valid “DAY” by default, which is the
common choice for day-traders.
Position traders may want to change that setting to “GTC”
(Good Till Cancelled).  Other
choices are available.  See IB Help
file for details.

[21]
Some settings have not been coded, like GAT (Good After Time). Please refer to
the documentation for details.

[22]
One Cancels All

[23] A
trailing order is a sliding stop order following positive price movement.

[24]
For simplicity, a single price is used for all exit limit orders.  This may change in future versions, but
since a stop loss order should be a “risk of ruin” order and not a
trading tool per se, this has considered sufficient.

[25]
Sending an order to IB generates immediately a series of follow-up events and
messages.  IB_Direct repeats a status request to IB after 5 seconds.

[26]
Data here shown is incorrect.  This
is a flaw or limitation from the IB demo accounts, to prevent users from
getting actual market data for free…

[27]
Primary order means normal entry/exit as opposed to attached OCA exit orders.

[28]
Technically, order size can also be updated, but this has not been allowed in
this version of the IB_Direct
program.

[29] A
modeless form does not capture the focus.  The user can leave it open and click back
to the main form.  It is actually
recommended to do so until the order is filled.