Introduction
Are you a systematic trader? A systematic trader can be defined as someone who uses a set of objective rules/conditions for entering and/or exiting trades. This allows a systematic trader to take objective and rational trading decisions rather than getting stressed out due to emotions and take irrational decisions. If you are a systematic trader or looking to become one, then this article is for you. In this article we will see how traders can use Interactive Brokers TWS API to assist in their trading process.
Interactive Brokers TWS API
First, let's discuss a bit about Interactive Brokers and their TWS API. Interactive Brokers (IB) is one of most popular brokers among institutional traders, professional traders and serious retail traders. It is one of the oldest broker which provides trading access to exchanges all over the world. IB was one of the first few brokers to provide retail traders an option to automate their trading processes using their TWS API. IB TWS API allows the traders/programmers the ability to automate functionality within TWS using external scripts/program, for example:
- Order placement, modification & cancellation
- Checking status of open orders and positions
- Receiving historical and live market data feed
- Receiving portfolio data and account values
- Querying financial instrument details
Now let's look at the different ways in which systematic traders can use IB TWS API.
1. Strategy Development
Perhaps the most important step in a traders journey is development of a strategy which has an edge in the market. One way to develop a strategy is to manually back-test the strategy by visualizing entries and exits on the chart, but back-testing manually can be:
- Very slow and inefficient
- Not scalable
- Inaccurate
Better way is to write the logic of your trading strategy in a programming language (like python, pine script, AFL etc.) and then back test the strategy on historical data. If you want to take this route, you can use IB API to fetch historical data of securities your are interested in trading. You can fetch historical intraday price data for up to 1 year for smaller time frames (for example 1 minute) and complete history for daily and higher time frames (weekly, monthly and yearly).
2. Strategy Automation
Once you have developed a trading strategy that has an edge in the market, you can use IB TWS API to fully automate the execution of your strategy using. Advantages of automation:
- It frees up your time to focus your time on other important things like doing research on newer uncorrelated strategies. Every strategy has a life time and it is not sufficient to have just one strategy in your arsenal. As a strategy becomes public and known to more and more people, the edge starts to disappear and performance starts to degrade. Therefore it is very important to continue doing research on new strategies while your older strategies are performing well. As you never know when your older strategies will stop performing.
- Executing trades can be very stressful and emotional when trading with personal capital. Having a program to automate the execution of a trading strategy not only reduces stress, but also reduces the chances of making errors when placing orders. It also prevents you from irrationally interfering with your strategy logic due to emotions.
3. Paper Trading
Once you have developed your strategy based on historical data. It's not a good idea to straight away start trading with real money. You can use Interactive Broker's paper trading account to paper trade the strategy for some time before going live with it.
4. Custom Scanners and Alerts
Some traders have a systematic process for identifying opportunities in the market. For example, some traders look for specific patterns to develop before taking any trades. Here are some well known patterns:
- Head and shoulder
- Flags and pennants
- Ascending and descending triangles
- Double tops and bottoms
- Wedges
Apart from these patterns, some traders use some predefined set of rules for finding the stocks in play. For example:
- Previous day's range
- Pre-market range
- Pre-market volume
- Major support/resistance break
It can be a very labor intensive task to stare at screen continuously and scan for these patterns or conditions. And if your universe consists of hundreds of securities then it is not possible to visually scan hundreds of securities manually. This is where TWS API comes in, you can use TWS IB API to fetch streaming/historical market data and run pattern recognition and/or filtering scripts on the securities to scan opportunities in the market.
You can also write programs to trigger alerts on your mobile whenever certain predefined technical conditions/patterns are satisfied. For example, you can write a program to alert you whenever Apple stock:
- Breaks 5-day high AND
- Is above 25-day EMA
Conclusion and next steps
IB TWS API is one of the most popular API used by institutions, professional trader and serious retail traders. We highly recommend using Interactive Brokers to professional traders and if you are not sure, we suggest you to explore the features of TWS API by taking advantage of their free demo account.