Coding and Debugging in Systematic Trading - Complete Guide


    If you are into systematic trading you already know that programming skills are important. Fortunately, it is not necessary to become a real IT expert. Basic coding knowledge can be enough to reach reasonable trading goals.

    This means that programming is an obstacle that is generally easily overcome by systematic traders.

    However, there is another obstacle that can be a real wrench in the works when creating your trading strategies: syntax errors that can happen while writing trading systems.

    Syntax Errors in Trading System Codes

    In order to use a trading system on a market, you first need to compile the script. While compiling a script, the trading platform validates the code by verifying that all the steps contained in the script comply with the writing rules of the platform itself and confirms their applicability.

    Sometimes it may happen that while compiling a script, the trading platform reports some errors related to the form of the code, that is, to its syntax.

    It can be very simple errors such as a missing semicolon at the end of an instruction (or other conventions related to the programming language) or a variable that is declared in the wrong way, or even an error in the use of some keywords.

    To spot these errors, you must patiently go through the entire script and correct them.

    Mistakes of Content in Trading System Codes

    debugging a trading system finding errors

    The mistakes related to the content of a trading system are certainly more difficult to identify, manage, and fix since they depend on what the system does when you apply it to a market.

    Your trading platform doesn’t detect these errors during compilation because the code is written correctly in terms of syntax, although the instructions it contains do not correspond to what we planned for the trading system to do.

    In this case, it is essential to apply a skill that we call debugging, in analogy with the process of finding and correcting errors (bugs) in software and program codes.

    In systematic trading, debugging means analyzing each step of building a trading system, from development to optimization, and identifying possible errors.

    In the following video, Andrea Unger talks about debugging skills applied to systematic trading and offers some useful tips on learning how to identify and fix errors:

    Main Sources of Error While Creating Trading Systems

    It is impossible to run a code that contains syntax errors. If the system is not compiled correctly, the platform will not know how to execute the function. However, it is possible and dangerous to go live with systems that have content errors.

    In fact, a system that behaves differently from how we planned risks leading to huge losses that we had not foreseen in the development phase.

    Among the errors that can cause system performance issues, we find inappropriate order types or failing to adapt parameters such as stop loss and take profit to the logic of the system, or the market being traded.

    For example, using a very tight stop loss to trade on a very liquid and volatile market or applying a take profit to a trend-following strategy can definitely damage the performance of our strategies.

    Over-optimizing, or overfitting, the parameters used to trade the system can also lead to strategies that do not work as expected. The same goes for using portions of historical data that are not sufficiently extended or that do not cover a sufficient variety of market conditions.


    As you see, there are various types of mistakes that can be made when developing and optimizing an automated trading strategy.

    To prevent them, it is essential to apply common sense and carry out all the necessary tests and checks to make sure that the system does exactly what we want it to do and that the results produced by the strategy are truthful and reliable.