Practical Aspects of Integrated Trading with Interactive Brokers (IB)

This is a practical guide to setting up integrated trading with Interactive Brokers. It
contains practical advice beyond that offered by our help files, and it should be read by
anyone considering trading with IB automatically using NeuroShell’s Integrated Trading
Feature.

Practical Aspects of Integrated Trading with Interactive Brokers (IB)

Copyright 2018, Ward Systems Group, Inc.

This is a practical guide to setting up integrated trading with Interactive Brokers. It contains practical advice beyond that offered by our help files, and it should be read by anyone considering trading with IB automatically using NeuroShell’s Integrated Trading Feature.

I. Things to Consider First

  1. Is integrated trading really right for you?

Integrated trading (sending trades automatically from NeuroShell to your broker) is not for everyone. If you are trading frequently during the day using intraday bars it certainly makes sense. If your trades are infrequent and not particularly time sensitive, it probably makes less sense. If you do not own the NeuroShell DayTrader and you trade once a day using daily bars after they close in the evening, it may not make much sense at all unless you trade dozens of symbols. NeuroShell’s integrated trading does not automatically “sync up” to IB if there is an interruption in communications or a failure of any of the programs involved.

You should weigh this carefully and make sure you are prepared to manually rectify the account positions should a failure occur (see the topic V. Interruptions below).

  1. Are you prepared?

Integrated trading is not for beginners. You should not even attempt to use integrated trading until you are very familiar with NeuroShell and the models you are planning to trade. You should also be familiar with the workings of the TWS, having traded or paper traded in the TWS directly with the exact types of issues you plan to trade automatically (e.g. futures, FX, equities). To not follow

this advice is to invite extreme frustration for you as well as us as we attempt to help you. Please do not be in a hurry to try out integrated trading.

  1. Do NOT install the IB API !!!!!!!

IB changes their interfaces frequently and without notice. NeuroShell may not always utilize the latest IB API, and IB has not in the past been careful about making their new versions compatible with their old ones. NeuroShell installs the correct IB API when you install NeuroShell, and you should not do anything further than install the TWS.

If you have already installed the IB API in order to automatically trade IB from Excel or some other software besides NeuroShell, our Integrated trading will probably not function, and you will need to remove the wrong API, which is not an easy thing to do. It may therefore not be possible to do integrated trading with both NeuroShell and the other software through IB. See Appendix D for instructions on removing the wrong API.

The following error is likely if you have installed the API yourself:

“The currently installed and registered Interactive Brokers API is not compatible with this version of NeuroShell Trader.”

II. Before You Start

  1. Is your IB account ready?

If you are not authorized by IB to trade certain instruments, integrated trading may not work on those instruments, even with the paper trading account (see below). Unfortunately, IB rarely issues illuminating error messages through the API interface when symbols cannot be traded. So make sure your account is set up the way you want it before you start.

  1. Do you have a paper trading account with IB?

A paper trading account is free, and a must to practice trading or integrated trading before risking real money. NeuroShell connects to whatever account is currently signed on to the TWS, so use the paper trading account in TWS extensively until you are sure the interface and your model are working smoothly and correctly.

Before you try automated trading, practice manually trading in the TWS without NeuroShell. Use the same symbols you plan to trade from NeuroShell. Do not use IB specialized platforms like the FX Trader or the Book Trader, because the IB interface does not connect with those. In the past users have reported problems trading with integrated trading to learn only later that the symbols they were trading couldn’t be traded manually in the TWS either.

NeuroShell only connects to one account at a time on a particular computer, and that is the account currently active in the TWS.

  1. Setting up the Trader Workstation (TWS)

The first thing you must do is activate client support by configuring the IB Trader Workstation (TWS). Go to the ‘Configure’ Menu on the TWS menu screen, select the ‘API’ menu item and make sure the ‘Enable ActiveX and Socket Clients’ is checked.  Verify that the Socket Port is set to 7496.

Next set up your computer as a trusted IP address, so that the TWS doesn’t constantly ask you if you want to let NeuroShell connect. You do this in the same API menu on the TWS. Select All API Settings, and then created a “Trusted IB address” of 127.0.0.1

  1. Selecting the brokerage in NeuroShell

The Tools > Options >Trading orders menu in NeuroShell is where you go to set up integrated trading. There is where you will select the interface to your brokerage. The IB interface is installed with NeuroShell.

There are two IB interfaces. If you are going to Trade an IB Advisor account, choose “Interactive Brokers Advisor Profile”, otherwise choose “Interactive Brokers”.

The Ticker and Exchange Mapping button is described in “Getting the Symbols Right” below.

  1. Advisors Accounts

If you are trading an Interactive Broker’s Advisor Account and have selected the “Interactive Brokers Advisor Profile” from NeuroShell’s Brokerage dropdown list, then you must also have a ‘NeuroShell’ allocation profile setup within the IB Trader Workstation (TWS).

To create an allocation profile in the IB Trader Workstation (TWS), go to the ‘Configure’ Menu on the TWS menu screen, select the ‘Advisor’ menu item and then select ‘Allocation Profiles’. You will then need to create a profile by the name of ‘NeuroShell’ which specifies how trades made from NeuroShell will be allocated between the available accounts. The profile name MUST be named NeuroShell to work correctly. Follow IB instructions on how to create an Advisor profile named “NeuroShell”.

III. Getting the Symbols Right

  1. Why this is important

The most common problem our users have with integrated trading with IB is that the TWS rejects orders saying only that the symbol is incorrect. To find out which symbol is being used in IB, add a symbol you want to trade to the Interactive Brokers Trader Workstation.

FX symbols are designated with a period separating the currencies in the pair, not a slash, as follows:

AUD.JPY

EUR.USD

  1. Finding out the correct IB symbol to use.

The best way to find the correct ticker symbol in IB is to first insert it into the TWS Into your Favorites tab by clicking on a blank line and typing either the name or ticker symbol of interest. Next hit the “Enter” button and a list of potential securities will be displayed. Select the one of interest. (If you don’t know how to do this, get assistance from IB.)

If the exact symbol is not displayed on the list, click on the word “Contract” at the top of the window and click on the + by Insert Column, and choose Symbol.

The correct IB symbol should now show up in the Symbol column. You can add columns for the exchange or other items of interest.

  1. Mapping the data feed symbol to the brokerage symbol

This is a crucial step, because possibly except for stock symbols, the data feed tickers almost never match the IB tickers, not even the IBFeed tickers. Even if you are trading equities and the symbols match, you should probably tell IB the correct exchange, e.g. SMART.

To tell NeuroShell what symbol to instruct IB to trade when it gets a signal from the datafeed symbol on your chart(s), go to Tools > Options and press the “Ticker and Exchange mapping.” button. The “Add Mapping” button allows you to correspond an IB symbol and exchange with a datafeed ticker. Be sure to set the Brokerage Security type too (use Cash for FX). See the next section for instructions on setting the exchange correctly in this dialog box.

Example: The eSignal symbol ESbU5 will need to be mapped to ESU5 (b stands for a blank space) The Exchange = GLOBEX/USD and Brokerage Security Type = FUT

The NeuroShell Trader Ticker and Exchange Map dialog box is accessed from the Tools Menu/Options/Trading Orders tab.

  1. Setting the exchange and currency correctly

IB requires the trading currency to be designated as well as the symbol and the exchange, but only for some symbols. We think it is best to designate the trading currency as a matter of course. If you are in the USA, your currency is USD, and it is specified by placing a slash and USD after the exchange designation, e.g.:

IDEAL/USD or IDEAL\USD
SMART/USD or SMART\USD
GLOBEX/USD or GLOBEX\USD

One exception is when trading currency pairs. If you are trading EUR.USD then USD works. However, if you are trading a cross pair like AUD.JPY then leave the USD currency off of the IDEALPRO exchange designation, or IB will not recognize your symbol.

  1. Some symbols cannot be traded fully

There are still issues that quote prices in the old fractional method in 16ths, 32nds, etc. These symbols can be traded in NeuroShell with Integrated trading, but at this writing IB insists that limit prices be the exact fractions. NeuroShell cannot be made to set limit prices as exact fractions, so these issues will need to be traded with market orders.

One example is 30 year T Bonds (ZB on the ECBOT).

IV. Position Sizes

  1. NeuroShell has the ability to set point values for contracts like futures and FX contracts. However, these point values are for NeuroShell to use in calculating profits and statistics, and they are not sent to IB. So if you send a trade of 2 contracts to IB, the size of those contracts is determined by IB, not by NeuroShell.
  1. Most users trade FX with IB these days by using dollar amounts rather than fixed sized contracts. Again, NeuroShell’s point values play no part in the interaction with IB. If you want to trade $50,000 of FX with IB, make your position size in NeuroShell 50,000, but leave the point value at 1 so that NeuroShell calculates profits correctly.
  1. Getting position sizes right is another reason you should practice trading manually with the IB TWS before trying to trade from NeuroShell.V. Interruptions

There are many reasons why integrated trading can be interrupted, including:

  1. IB shuts the TWS down once per day, but you can adjust the time (in the TWS File/Global Configuration menu, see “Lock and exit”).
  2. Internet communications failure
  3. TWS failure
  4. NeuroShell failure
  5. Windows failure
  6. System reboots caused by Windows or anti-virus program updates

If any failure occurs, including one of the above, NeuroShell cannot automatically restart and there is no guarantee that when everything is running again, that NeuroShell and the TWS will be synchronized with respect to positions and orders.

It will be your responsibility to make sure that the NeuroShell charts you are trading are still in the correct positions before you continue integrated trading. If you are in doubt, or cannot do that, close out all your positions manually in the TWS, and rebacktest the NeuroShell chart in order to start trading fresh.

However, if you want to shut down NeuroShell while you still have open positions, save the chart(s) you are trading first. NeuroShell then “remembers” open positions in the chart, and when you reload the chart(s) NeuroShell will ask if you are still in the same positions. If you are, NeuroShell will continue in those positions. If not, NeuroShell will assume you are starting over with new positions.

VI. Other Issues

  1. Be aware that NeuroShell will only send trades to IB upon the close of the current bar. If you load NeuroShell, no signals that have already occurred will be sent.
  1. Also, if your model is defective in a way that generates trades for older bars, those trades will not be sent either. There have been cases where users see older trades that were never sent, and the problem turned out to be that their model was using inputs or rules that did not fire until several bars had passed. This can happen if your inputs or rules either look into the future, or change in the past based on new data.

VII. Trouble Shooting

If you experience problems that are not covered in this document, you can bring them to the attention of our technical support. However, please reproduce the problem after taking the following steps:

  1. Download and install the latest version of NeuroShell from www.ward.net. If there is a current beta version available, download and install that version.
  1. Before you start NeuroShell, manually erase the following files in the NeuroShell root folder (c:\NeuroShell Trader 6 if you installed the program in the default directory).

inttrd.log
inttrd2.log
inttrd3.log
inttrd4.log

  1. Reproduce the problem that you saw before. As soon as the problem occurs, save the chart with a new name and with data included in it (when you select “Save as.” you will see an option to include data).
  1. If you know how, take a jpg image of the screen.
  1. Locate a file in the NeuroShell folder, subfolder BrokerageServers called “Interactivebrokers.map” or “Interactivebroker Advisor Profile.map”.
  1. Send an email to support@wardsystems.com with a detailed description of what the problem is and exactly on what bar it occurred. Attached the saved chart, the jpg image, and all the .log files above that you see (they will have been regenerated), and the .map file.

Appendix A – How NeuroShell Interacts with IB

Order Types:
NeuroShell Trader supports only the “Market”, “Limit”, “Stop”, and “Stop Limit” order types for Interactive Brokers. All other order types are currently unsupported (i.e. order types like “Limit if Touched”, “Trailing Stop”, “Market if Touched”, etc. are unsupported). Note that Stop and Limit orders are NOT simulated orders, where by NeuroShell Trader would monitor the price action and send out a market order to your brokerage when the price has been reached. The Stop and Limit orders in NeuroShell Trader are actual Stop and Limit orders that get placed with your Brokerage at the end of a price bar. The brokerage will forward the order to the actual market being traded and the order will sit in the market waiting to get executed until the specified stop or limit price has been reached (or until NeuroShell Trader cancels or modifies the order on a subsequent price bar).

For markets that do not accept stop or limit orders, please contact your Brokerage about how they handle stop and limit orders for that particular market. The brokerage may either simulate the stop or limit order on their computer system or they may simply not accept stop or limit orders for that particular market.

Duration of Orders:
NeuroShell Trader currently places all orders as GTC (Good till Cancelled) with Interactive Brokers. However, keep in mind that NeuroShell Trader will cancel any open orders necessary due to the logic of a Trading Strategy.

Take for example a Trading Strategy setup to place a Limit or Stop order only when the last bar’s volume exceeds 10,000. In this case, NeuroShell Trader will place the Limit or Stop order with Interactive Brokers when a bar expires with a volume exceeding 10,000. NeuroShell Trader will keep the Limit/Stop order active as long as each successive bar’s volume exceeds 10,000 and the Limit/Stop order has not been filled. However, NeuroShell Trader will send Interactive Brokers a command to cancel the Limit/Stop order on the first subsequent bar with a volume less than 10,000 if the Limit/Stop order has not yet been filled.

Simultaneous Orders
There is currently no support for OCO (One Cancels Other) or OCA (One-Cancels-All) group orders. However, keep in mind that NeuroShell Trader will cancel any simultaneous order pairs that need canceling due to the confirmed order fill of one of the orders.

Take for instance a Trading Strategy that has a simultaneous protective stop and price target limit order exits. In this scenario, NeuroShell Trader will place both a stop order to exit and a limit order to exit with Interactive Brokers. When NeuroShell Trader receives a confirmation that one of the orders has been filled, it will immediately send Interactive Brokers a command to cancel the opposite order of the pair.

Order Fills
Fill prices from Interactive Brokers will be communicated back to NeuroShell Trader for use in the Trading Strategy. Even if price action on the chart makes it appear as if a fill should have occurred, NeuroShell Trader will only actually fill an order and proceed with subsequent trading strategy orders after Interactive Brokers has returned a fill price. If Interactive Brokers does not fill the order, neither will the NeuroShell Trading Strategy. This guarantees that the Trading Strategy will not get out of step with the orders/fills occurring with Interactive Brokers and also allows you to view the actual fill prices and related statistics within NeuroShell Trader.

Partial Fills
NeuroShell Trader will wait until Interactive Brokers returns confirmation that an order is completely filled before proceeding with subsequent trading strategy orders. In the case that an entry order is partially filled when the Trading Strategy needs to cancel an order, NeuroShell Trader will automatically adjust any subsequent order sizes to reflect the partial fill.

Take for instance a Long Entry order for 100,000 shares which has only been filled partially with 20,000 shares at the time that a Short Entry reversal signal to short 100,000 shares occurs. In this case, NeuroShell Trader will send out a cancel message for the Long Entry order. NeuroShell Trader then waits for confirmation that the order is canceled. Once confirmed cancelled, NeuroShell will reverify the final number of shares filled by the Long Entry order just in case more shares were filled between the time of the cancel being placed and the cancel confirmation. NeuroShell Trader will then place a sell order for the long position shares and the desired short position. So in this case a sell order for 120,000 shares would be placed to both exit the partially filled long position of 20,000 shares and take a short position of 100,000 shares.

What is the difference between the Protective Stops tab and the Exit tab with Stop Order selected?

The only difference is that selecting a stop order on the Exit tab will conditionally fire stop orders based upon the exit condition, whereas specifying a stop price on the Protective Stop tab will fire stop orders on every bar if the price changes (canceling the old ones). So for example a stop price of Sub(High,5) put in the Protective Stops tab would send out a stop order 5 points below the high at the end of each bar while still in a position. However, a stop price of Sub(High,5) entered under the Exit tab with a condition of volume exceeds 10,000, would only send out a stop order 5 points below the high at the end of each bar in which the volume exceed 10,000 and still in a position. On bars where the volume was less than 10,000, no exit stop order would be placed and in fact if the previous bar had a volume exceeding 10,000, then the old stop order would be canceled.

It should be noted that there is absolutely no functional difference between specifying a stop price on the Protective Stop tab and specifying the same stop price on an exit tab whose order type is selected to be a Stop Order and whose exit condition is always true.

When are Protective Stops and Exit Orders placed relative to the Entry Order:
If the entry is made with a market order, then exit stop and exit limit orders specified on the Protective Stop and/or Exit Tab will be evaluated and fired on the same bar that the entry condition was true. This allows a stop and/or limit exit to be placed at the same time that a market order entry is placed. However, if the entry is based upon a stop or limit order instead of a simple market order, then the Protective Stop and Exit tabs will not be evaluated and fired until the end of the bar on which the entry order stop or limit was actually filled. Additionally, if your protective stop or exit uses the entry price indicator or any indicator requiring entry info, then even with a market order entry, the stop calculations will not be evaluated and fired until the end of the bar on which the actual entry fill price occurs and is therefore available for use in the calculation.

Appendix B – NeuroShell Color Schemes During Integrated Trading

NeuroShell Trader uses the following color schemes to distinguish whether integrated trading has just started, is proceeding normally or is ending:

a. Army Green on chart and green in alerts and order window means that active trading was just turned on and it is waiting to place an entry order. No position closing exit orders will be placed with the brokerage, only an entry order to open the position.

b. Bright Yellow on chart and green in alerts and order window means that the first entry order was placed on that bar or a previous bar, but an entry fill did not yet occur on that bar.

c. Light Pale Yellow on the chart and black in the alerts and orders window means that active trading is occurring, both entry and exit orders will be placed with the brokerage.

d. Bright Yellow when you turn off active trading, the alerts and orders window shows red, meaning that trading is ending and no new entry orders will be placed with the brokerage, only an exit order to close out the existing position.

e. Purple bars denote the the bars between when you closed the chart and opened the chart if you are actively trading a chart, save and close that chart, but then reload the chart later.  NeuroShell will not signal any trade entries, exits or stops during the purple colored time period because the chart was closed, but still being actively traded.

 

Appendix C – Removing the Wrong API

The following message should appear if you have an incompatible IB API installed. Even if it does not appear, but you know you have installed the IB API yourself, follow the instructions below. If you are unable to follow the directions below, please contact technical support for assistance.

The currently installed and registered Interactive Brokers API is not compatible with this version of NeuroShell Trader. To restore the compatible Interactive Brokers API which is automatically installed with NeuroShell Trader:

1) Uninstall the ‘TWS Interoperability Components’ using Add/Remove Programs from Windows Control Panel.

2) Uninstall NeuroShell Trader

3) Erase the files Tws.OCX and TwsSocketClient.DLL from C:\Windows\System32

4) Reinstall NeuroShell Trader

5) If necessary, reinstall Interactive Brokers Trader Workstation. However, DO NOT REINSTALL any Interactive Brokers APIs!

Was this article helpful?

Related Articles