Introduction
Welcome to Algolang
In a nutshell, Algolang is a development toolkit for serious traders who also happen to be serious programmers.
Why Algolang?
There is no shortage of trading system development tools already on the market, so why do we need another one? Broadly, trading system development environments can be broken down into three categories: no-code/visual tools (such as StrategyQuant X), simplified trading-specific languages (such as TradeStation’s EasyLanguage or Trading View’s Pine Script), and toolkits/libraries to enable programming in your language of choice (often R or Python). The third category is more likely to be the preference for quant developers, and it is this third category into which Algolang fits. Algolang was developed on the basis that the first two categories are unsuitable for serious system developers and in the third category there are no great choices.
Let’s look at the three categories.
1. Visual tools
The lure of a simple point-and-click solution to a complex problem is enticing. The tools in this category have certainly come a long way over the last few years. These tools are a good choice for system developers who have no programming skill and don’t intend to develop any. Ironically, as these tools have developed they have become more complex to use as they grapple with trying to present a simple interface to a complex problem. There is no doubt that there is a market for these tools but traders with software development experience are not in the target market for these products.
2. Simplified trading-specific languages
Traders with some programming skills are often drawn to the products that enable more customized strategies to be developed with trading-specific, proprietary languages. Experienced software developers can quickly come up to speed on these languages but will quickly become frustrated with them. The poster child in this space is TradeStation’s EasyLanguage.
EasyLanguage was first introduced in 1991 and became the default standard for trading system development languages. It’s lure was that it was easy for non-programmers to learn the language and build trading systems. Its last major update was in 2009 and the world has now well and truly passed it by. Notwithstanding this, it has a base of dedicated users who don’t want to let it go. But any real software engineer is unlikely to tolerate its litany of extreme shortcomings.
Newer competitors don’t have all of EasyLanguage’s flaws, but they are all dumbed-down languages that are unsuitable for serious developers.
3. Generic programming languages
If the domain-specific languages described above are too simple, then for most people trying to build a trading system, starting with a programming language (such as C/C++, R, Python, and so on) and an idea is too hard.
As Python has become the language favoured by data scientists (but not computer scientists!) many Python packages have been built to assist with the analysis of time-series data, making Python somewhat of a favourite for developers looking to build trading systems. We consider Python to be an inadequate choice for a multitude of reasons, including (but not limited to) poor performance, lack of proper type checking, poor concurrency support, and external module management/version issues.
While most programmers would be put off by the idea of building trading system strategies from scratch in C or C++, tools like Zorro can provide a head-start for C/C++ programmers. Zorro is a Windows (only) application that allows users to run code written in their proprietary C-like language or call code written in a native Microsoft C/C++ DLL (with all the attendant ugliness that this entails). Whilst Zorro does address some of the issues that arise with the dumbed-down programming languages described above, it introduces its own set of issues.
The Algolang approach
Algolang is built with Google’s Golang programming language. It provides a suite of tools to write and test trading strategies in pure Golang. Whilst you needn’t necessarily be a skilled Golang programmer to use Algolang, a basic grounding in Golang is strongly suggested. If you are not already a Golang programmer, there is no shortage of instructional material available to get you up to speed.
The choice to build on Golang was driven by a number of factors:
- performance;
- modern programming paradigms;
- type-safety;
- built-in memory management;
- concurrency support;
- extensive tool-chain support;
- operating system independence (although, as always, Windows ends up being problematic!);
- the enormous third-party code base (on Github etc.);
- the size and commitment of the community; and
- the language’s on-going development by Google.
A simple Algolang strategy
Let’s look at a simple strategy to go long one share/contract when the 5-day exponential moving average of the closing price crosses above the 15-day exponential moving average of the closing price, exiting when it crosses back under.
// Example strategy to go long when the 5-day EMA crosses above the 15-day EMA,
// and exit when it crosses back under.
func Strategy(rs *engine.RunState) error {
xmaFast := rs.Close(0).XMA(5)
xmaSlow := rs.Close(0).XMA(15)
if rs.MarketPosition() == 0 && xmaFast.CrossesAbove(xmaSlow) {
rs.Buy()
}
if rs.MarketPosition() > 0 && xmaFast.CrossesBelow(xmaSlow) {
rs.ExitLong()
}
return nil
}