How To Trade Live With Amibroker (Automated Trading)

Last Updated on December 1, 2021 by Oddmund Groette

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).

Fortunately, trading your strategies live is not as difficult as it sounds. This article summarizes the main aspects you need to address to make a robust code for sending and sorting your orders and trades. For a fee, we offer a simple script that gets you started pretty fast.

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 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, like Tradestation is.

The good thing is that it’s not so difficult to take your backtests to the next level.

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, but they have made a plugin that lets you trade 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 live 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. 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).

What do you need to consider when you go live with your strategy?

Despite the plugin, 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:

  1. If you generate a buy or sell signal, Amibroker must connect to the broker via the plugin/bridge.
  2. 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.
  3. If you have a flat position or you want to add to the existing position, you want Amibroker to send an order.
  4. 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.).
  5. 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).
  6. If an order is filled, then again Amibroker needs to keep track of the fill to avoid multiple fills for the same strategy.
  7. 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.

How to run live trading in Amibroker and Interactive Brokers

We have an Amibroker course that gets into detail about how to set up all this. The broker of our choice is Interactive Brokers. The course even has detailed code as an example to show how it can be done:

  1. 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.
  2. If your settings indicate you should go ahead, you can set the order type that IB allows.
  3. 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.)
  4. When you later scan your buy or short signals, any signals will be rejected if you have already have a position.
  5. 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 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.

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!

 

Disclaimer: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.