When building trading systems, naturally you want to make the program as fast and as efficient as possible. That is why I love C++. It removes many of the limitations that some programming languages have regarding performance. But that performance is not free.
Developing software in C++ takes time. There are ways to put automated trading systems together by dragging and dropping components, with little to no code necessary. And for some strategies, they work just fine! If your strategy is not sensitive to micro movements in price, why would you write it in a language that takes extra time to write? There are a few reasons that you would perhaps write it in C++ anyway, but I won’t argue. Sometimes C++ is not the correct language for your strategy.
When you get into the HFT realm, there are pieces that C++ can’t even help with. For instance, kernel drivers are often written in C, not C++. Some fine-tuning requires assembler (although you can often put it within your C++ code). And most FPGA stuff is not C++ but Verilog, VHDL, or another HDL.
So what language should you use to write your trading system? As with many decisions in life, it depends on the details.
What tools are you familiar with?
If you have an existing toolkit that you are familiar with, it has the features you need, and performs sufficiently fast, then the decision to switch languages would be hard to justify. You’ve invested time and effort in getting this far. Switching may simply not be worth the education cost.
What tools are available to you?
For many, the tools are dictated by the broker. In the forex world for example, there are a large number of brokers running MetaTrader. They dictate to their clients that MetaTrader must be used. For some, that is not a problem. MetaTrader has a decent community with forums and documentation to help even beginners build trading systems.
Other brokers are web-based, and communities have built libraries for Python or JavaScript. If it fits your needs, go for it!
What problem are you trying to solve?
This can be a big one, and often the true answer is obscured within a detail. Some datasets are huge, and an an academic wrote a paper solving your problem (or a portion thereof) in R, Matlab, or some obscure language you are not familiar with. Do you rewrite what they did in your preferred language? Or do you learn theirs?
Why write it in C++?
Based on all of the above, why do I write the majority of my trading systems in C++? Because in my case, often the answer to the 3 questions above reveals C++ to be the best answer.
- I know it. I can write, test and deploy C++ without thinking too hard. Many struggle with C++. I don’t. It is very predictable in its results. I write X, it will always do Y.
- The tools available are often available in C++, or at least reachable from C++. As an example, MetaTrader can call a DLL, which can be written in C++. That means you can write the basics in MQL, and the heavy lifting can be done in C++.
- If the problem you are trying to solve is a big one, the chances are that a solution is already in C++. Many heavy math routines you find in Matlab or R have also been written in C++.
And if the strategy I am writing for needs a boost in performance, the answer has never been “change languages”. It is often “profile the code, and rework a bottleneck”.
Again, I am not saying C++ is always the best answer. In fact, I am saying the opposite. If you want to tinker, and your broker gives you a drag-and-drop solution, go for it! Do not let any one discourage or disparage you. There is a good chance it will be all you need!
I am saying that in my case, C++ is often the best solution.
A note about the language wars…
A recent TIOBE article ruffled some feathers because C++ moved up in the rankings. Some people get passionate about their opinions. I ask my fellow software engineers to take the high road here. Face it, sometimes your favorite language is not the best solution. This page was written using a web-based editor that was written in PHP! I did not write the editor. Writing the editor or just this page in C++ would have been large waste of time. PHP did just fine. And I don’t have to maintain it!