- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies
Lesson 5 of 6
In Lesson 3, the DDE sample spreadsheet has a variety of functionalities which demonstrates most of the capabilities of the API.
In this lesson, we will discuss some of the more advanced functionality of the spreadsheet, including placing orders and bracket orders. We will also discuss what goes on “under the hood” of the sample spreadsheet.
Please note – the sample spreadsheet is not meant to be used as a robust trading application. We will discuss the logic of order placement to show what is possible with DDE and VBA coding.
You can define a bracket order which is designed to help capture profit and help minimize loss. A BUY order is bracketed by a high-side sell limit order and a low-side sell stop order. A SELL order is bracketed by a high-side buy stop order and a low side buy limit order.
To get started creating our bracket in Excel, we can look at the API documentation for brackets.
Here’s a tip – instead of using the Extended Order Attributes tab for the bracket order setup – you can scroll to the right on the Basic orders tab and place the values into these columns.
Compared to the legacy DDE sample spreadsheet, the new DDE sample relies heavily on programmed functions in VBA code to perform actions.
For example, when requesting historical data in the DDE sample, VBA code must be used to process incoming bars and place them in the appropriate cells. The creation of studies and indicators and custom conditional orders are other common uses of VBA. To view the code, press Alt+F11 from any page in the spreadsheet. The Visual Basic Editor opens.
The code window will then display the code for the immediate worksheet, in this historical data. For those of you who are unfamiliar with the Visual Basic Editor, there are three main areas of the Visual Basic Editor window:
You can see the Microsoft Excel Objects in the Project Window that correspond to the pages in the spreadsheet. Double-click any of them to display the code for that page. There are also additional forms and code modules used by the rest of the code that you can see if you scroll down in the Project Window.
Reviewing the underlying VBA code is advised when trying to create your own custom sheet and automating functions. Further programming instruction and support is outside the scope of this tutorial and IBKR API Support.
The other Microsoft Excel feature used throughout the TwsDde.xls spreadsheet is the macro.
Additional Links
The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Interactive Brokers, its affiliates, or its employees.
Please keep in mind that the examples discussed in this material are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.
Join The Conversation
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!