Interactive Brokers Connection Guide | NinjaTrader (2023)

Please note that connectivity is only available through NinjaTrader 8

Summary

There are two interfaces which can be used to connect NinjaTrader to an Interactive Brokers account. You only need to follow one of the initial setup instructions outlined on this page for the interface you plan on using:

  • IB Trader’s Workstation (TWS) – Fully featured Trading Application provided by Interactive Brokers (allows you to view and manage API orders which were submitted through NinjaTrader)
  • IB Gateway – Lightweight Interactive Brokers interface (provides status updates on the API connection but does not provide interface to manage API orders)

The interface that is used when you attempt to connect your Interactive Brokers account from NinjaTrader is determined based on the “Connect using” option configured in the “Connection Configuration Instructions” detailed later on in this guide.

Requirements

  • NinjaTrader 8.0.27.0 or later
  • A valid account at Interactive Brokers
  • Logon credentials provided by Interactive Brokers
    • User name
    • Password
  • You must have at least one of the following standalone Interactive Brokers API Software versions installed (browser versions are not supported)
    • TWS 10.19.1c - Download
    • IB Gateway 10.19.1c - Download
  • Latest Java version - Download

Initial Setup Instructions for Connecting with IB Gateway

  1. Start IB Gateway
  2. As per the image below, set “API type” to “IB API” and enter your IB username and password to login to the gateway
  3. Interactive Brokers Connection Guide | NinjaTrader (1)
  4. As per the image below, select the menu “Configure > Settings”
  5. Interactive Brokers Connection Guide | NinjaTrader (2)
  6. From the Trade Workstation Configuration window, select “API > Settings”
  7. As per the image below, enable the following options:
    • Include virtual FX positions when sending portfolio
    • Allow connections from localhost only
    • Send status updates…
      • Note: Uncheck “Read-Only API” if you plan on placing live trades from NinjaTrader; otherwise you will only be able to view market data and account information.
  8. Interactive Brokers Connection Guide | NinjaTrader (3)
  9. Press OK and continue reading the “Connection Configuration Instructions” further down on this page
  10. Warning: Trader Workstation and NinjaTrader must have matching time zone settings to properly time stamp executions, orders and historical data. By default these will be your local PC time and no change is needed. Contact [emailprotected] if you need assistance in configuring the time zone settings.

Initial Setup Instructions for Connecting with IB Trader’s Workstation (TWS)

  1. Start Interactive Brokers TWS and enter your IB username and password to login to TWS
  2. As per the image below, select the menu "File > Global Configuration…" Note: For Classic TWS view select the menu “Edit > Global Configuration…”
  3. Interactive Brokers Connection Guide | NinjaTrader (4)
  4. From the Trade Workstation Configuration window, select “API > Settings”
  5. As per the image below, enable the following options:
    • Enable ActiveX and Socket Clients
    • Download open orders on connection
    • Include FX positions when sending portfolio
    • Send status updates…
      • Note: Uncheck “Read-Only API” if you plan on placing live trades from NinjaTrader; otherwise you will only be able to view market data and account information.
  6. Interactive Brokers Connection Guide | NinjaTrader (5)
  7. Press OK and continue reading the “Connection Configuration Instructions” further down on this page
  8. Warning: Trader Workstation and NinjaTrader must have matching time zone settings to properly time stamp executions, orders and historical data. By default these will be your local PC time and no change is needed. Contact [emailprotected] if you need assistance in configuring the time zone settings.

Connection Configuration Instructions

  1. NinjaTrader 8 must be installed
  2. Start NinjaTrader 8
  3. From the Control Center window, select the menu "Connections” > “configure”
  4. Interactive Brokers Connection Guide | NinjaTrader (6)
  5. Select "Interactive Brokers" from the list of “Available” connections and then press the “add” text from the “Configured” section below
  6. Interactive Brokers Connection Guide | NinjaTrader (7)
  7. The Connection “Properties” section will be made available on the right side
  8. Enter your Interactive Brokers credentials as per the image below:
    • Connection name: Create a name to identify your connection
    • Connect on start up: Enable if you want NinjaTrader to automatically establish a connection on start up
    • User name (optional): Enter your Interactive Brokers account user name (leave blank if you wish to manually enter your user name each time TWS is started)
    • Password (optional): Enter your Interactive Brokers account password (leave blank if you wish to manually enter your password each time TWS is started)
    • Ask password on connect: Enable to require manually entering the password when connecting (Password field above will be disabled)
    • Enable beta functionality: Enables the beta functionality made available in NinjaTrader 8.0.16.0 (release notes)
    • Connect using: Set to either “TWS” or “Gateway” depending on the initial setup steps you choice earlier
    • Auto logon: Check this option in order for NinjaTrader to automatically start and enter your credentials to log into your account. Selecting this check box will enable the “Auto logon path” property which is used to tell NinjaTrader where your TWS/Gateway version is located. Leave unchecked if you wish to manually start and login to TWS/Gateway before using your connection
      • Important: You are required to use the API version listed on this page for this feature to work properly
    • Auto logon path: Only used if “Auto logon” is enabled. Not compatible with paper accounts. Choose the file location of your TWS/Gateway installation (your installation may vary depending on your setup)
      • TWS: C:\Jts\985\tws.exe, etc.
      • IBGateway: C:\Jts\ibgateway\981\ibgateway.exe
    • Client ID: Leave this set to a value of zero "0" unless otherwise instructed by a technical support representative
    • Host (optional): Leave this as “127.0.01” (localhost) unless you want to connect NinjaTrader to TWS running on another PC within your local area network. If connecting over a network enter the computer name or IP address.
    • Local OCO simulation: Enables NinjaTrader to handle OCO (one cancels other order handling) on your local PC. DO NOT enable this unless otherwise instructed by a technical support representative
    • Log level: Leave default unless otherwise instructed by a technical support representative
    • Port TWS: Ensure that this value is set to the same value in the TWS/Gateway API Settings. The default values are below:
      • TWS: production / live account 7496, paper account 7497
      • Gateway: production / live account 4001, paper account 4002
      • To avoid changing ports on the NinjaTrader side, you could setup 2 account connections, one for your production / live login, and one for your paper login
    • Run-time pop up handling: Enables NinjaTrader to suppress TWS pop up windows
    • SSL: Enable secure socket layer
    • Trigger after hours: Enable this if you want stop orders to trigger outside of standard trading hours. This will only work if you also have "Allow order to be activated, triggered, or filled outside of regular trading hours" enabled in TWS (Configure > Order > Order Presets > Timing menu)
  9. Interactive Brokers Connection Guide | NinjaTrader (8)
  10. Press OK

To connect to your account, go to the NinjaTrader Control Center window, select the menu "Connections" and then select your account “Connection name” you configured during step 6.

Interactive Brokers Connection Guide | NinjaTrader (9)

Once connected, you will see your connection highlighted in the connections menu per provider. There is also an aggregated connection status in the bottom left hand corner of the Control Center. For more information please see the "Connection Status" section of the help guide.

Interactive Brokers Connection Guide | NinjaTrader (10)

Critical: The forex positions reported in NinjaTrader are based on the positions reported in TWS FX Trader and the FX Portfolio section of the TWS Account window. This is NOT the cash value reported in the Market Value section of the TWS Account window.

Common Problems Connecting to your Interactive Brokers Account

Always check the Control Center Log tab to see if there are any connection error messages.

I try to connect but nothing happens

This is usually because TWS is not configured correctly. Please review the Initial Setup Instructions for Connecting with IB API settings in the guide above.

I see an error message "Target machine actively refused…"

  1. Ensure you have configured the TWS/Gateway API Settings to "Enable ActiveX and Socket Clients" per the "Initial Setup Instructions" section for the TWS or IB Gateway version you are using
  2. If you have another 3rd party application connected to TWS, ensure that it is not using a Client ID value of zero. Try shutting down this application and then connecting NinjaTrader to TWS.

I see an error message “Unable to auto start IB…”

This is because you have enabled the “Auto logon” feature, but NinjaTrader was unable to find the recommended version

  1. Try starting TWS/Gateway manually and logging in before attempting the connection from NinjaTrader.
  2. Ensure you have configured the correct “Auto logon path” to point to your local installation of either tws.exe or the ibgateway.exe per step 6g from the Connection Configuration Instruction section of this guide.
  3. Ensure you have installed the recommend API configuration per the “Requirements” section of this guide.
  4. Contact [emailprotected] if you need assistance in configuring the Auto logon feature to work properly.

I see an error message “Unable to connect to IB TWS/Gateway instance…”

This is usually because TWS is not running, or the “Socket Port” configured in the NinjaTrader Configuration settings do not match the Socket Port configured in the TWS or Gateway API Settings. While the port number used is optional, they must be the same between both software configurations in order to connect

Top Articles
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated: 12/05/2022

Views: 5823

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.