Last Updated on June 19, 2022 by Quantified Trading
This article looks at how to trade live and automated with Amibroker via Interactive Brokers. We have been using Amibroker for live automated trading for a few years, without any problems worth mentioning.
Automatic trading with Amibroker and Interactive Brokers is relatively easy. You need to address a few issues to make a robust code for sending and sorting your trades. For a fee, we offer a simple script that gets you started pretty fast with automatic trading at Interactive Brokers. Fortunately, trading your strategies live and automated with Amibroker is not as difficult as it sounds.
All backtesting and system development on this website is done with Amibroker. Despite its cheap price, we believe Amibroker is the best software for backtesting and charting.
However, Amibroker offers no ready solution for how to take your trading strategies into live mode, like for example, Tradestation does. In Tradestation you just check a box for “live mode” and you’re done. Amibroker is simply not built to connect to the almost unlimited brokers that exist (Tradestation is also a broker).
What is Amibroker?
Before you continue, you might want to read our review of Amibroker to get some background about the software. That article should give you a basic understanding of how to use Amibroker.
Does Amibroker offer live automated trading and algo trading?
Amibroker does offer the possibility to trade your backtests and strategies live. However, Amibroker is a standalone software and is not affiliated with any broker, similar to Tradestation which has its, own broker.
The good thing is that it’s not so difficult to take your backtests in Amibroker to the next level of algo trading.
To connect to a broker you need a plugin. This plugin is the “bridge” between Amibroker and the broker.
Why do you need a plugin?
You need a plugin for quotes and start communication with the broker. Amibroker needs to communicate with your broker to send orders and find out if you get a fill or not.
There are almost limitless brokers and Amibroker can’t make plugins for all of them for algo trading, but they have made a free plugin that lets you trade automatically with Interactive Brokers, probably the most used broker for active traders.
Even though Amibroker offers no plugin to all brokers, you can make your own plugin. That requires, of course, a great deal of programming knowledge and is out of reach for most traders.
If you are good at coding you might make your own customized plugin to your broker of choice that is just as good as anyone else’s. You can connect to any broker you like – as long as you know how to code.
But if you are not so good at coding, like most of us are, you might face some problems taking your strategies from the drawing board to a live environment – even if you have access to a plugin.
Amibroker course for a live automated trading setup
If you need help in getting into live trading with Amibroker, we have made a course that gets into details on how to do this. The setup and code are the same as we have been using for three years. Further below you get more details about the Amibroker course.
VPS and live trading
If you are serious about trading we recommend setting up a VPS – virtual private server. The cost is from 15 to 50 USD a month and you can keep all your data, programs, and systems in one place. We have done that for years and it’s handy when you are traveling, for example (you just log in via your laptop from wherever you are).
Amibroker and Interactive Brokers
Interactive Brokers is a very popular broker for traders – with good reason. They have a support that has a lot to be desired, but in terms of costs, markets, and execution they are (probably) the best. It’s a broker mainly for traders and less so for long-term investors.
Amibroker has made a plugin that lets Amibroker connect to Interactive Brokers. You don’t even need to install the plugin if you have installed Amibroker 5.7 or later (it’s already installed by the Amibroker setup).
Amibroker automated trading live:
To start live automated trading with Amibroker, you need to code a script that lets you manage your orders and trades to avoid multiple orders being sent (and filled). Below we have a few bullet points that need to be addressed when you make the code for automatic trading via Amibroker.
Obviously, the first thing you need is a backtested strategy with strict rules for buying and selling. When you are ready to try live trading with Amibroker, you need to include some extra code that needs to contain the following:
Here is how to automate your trading strategy for live trading in Amibroker.
- If you generate a buy or sell signal, Amibroker must connect to the broker via the plugin/bridge.
- After connecting to the broker, you must check if your strategy already has a position for this strategy. If you don’t do this step you’ll have multiple buys for the same strategy and you might end up penniless. The easiest method is to use a staticvariable for this.
- If you have a flat position or you want to add to the existing position, you want Amibroker to send an order.
- The brokers have different types of orders and thus the order type is dependent on the broker you use. You send the order of your choice (OPG, MOC, Limit order, Market order, etc.).
- Amibroker needs to keep track or store that an order is sent to avoid sending multiple orders (or at least to limit the number of orders).
- If an order is filled, then again Amibroker needs to keep track of the fill to avoid multiple fills for the same strategy.
- The same procedure must be repeated for a sell order.
In short, these are the main issues you face when you want to take your backtested trading strategies to live trading in Amibroker.
You can avoid some of the procedures above if you trade at a certain time of the day by manually scanning your trading strategies for buy and sell signals. It depends on the complexity of your trading operation.
Automate Strategy in Interactive Brokers
We have an Amibroker course that gets into all the details about how to automate strategy in Interactive Brokers. The broker of our choice is Interactive Brokers because of its product availability and low commissions. The course even has detailed code as an example to show how it can be done:
- If you generate a buy or short signal, you can adjust if you want to send an order based on a) if you already have a position in this trading strategy, or b) if you already have a max position in this specific ticker.
- If your settings indicate you should go ahead, you can set the order type that IB allows.
- When an order is sent, the script record it as you have a position. (If your order doesn’t get filled, you manually need to remove a saved variable to “free” your strategy.)
- When you later scan your buy or short signals, any signals will be rejected if you have already have a position.
- If you get a sell or cover signal, an order is generated to sell the order type of your choice and the script removes the variable that again lets you send the opposite signal later.
It’s a very simple script, but it should suit 95% of the automatic traders using Amibroker. We have been using the same script for years when we automate a strategy in interactive brokers without any problems. What we do is to turn on the script when we want to trade and make sure we are always not very far from the computer. With just a few lines of code, you are able to automate trading strategies in Interactive Brokers!
If you want to buy the code, please keep in mind that you need to check off our disclaimer. Mechanical trading always involves the risk of things going terribly wrong, and you should ALWAYS spend a lot of time paper trading your systems in a demo account before you go live. We make no guarantees about the code.
Additionally, you should never let your computer run without any supervision. Unknown factors and black swans happen all the time. Even though you believe you have covered all aspects of what can possibly go wrong, you can be sure something surprising pops up when you least expect it. Always be on your tiptoes!
If you understand and address the issues above, it doesn’t require much to do live automated trading in Amibroker and Interactive Brokers.