Trading Systems Coding: Testing, Troubleshooting and Optimizing
  1. Trading Systems Coding: Introduction
  2. Trading Systems Coding: System Design
  3. Trading Systems Coding: The Coding Stage
  4. Trading Systems Coding: The Coding Process
  5. Trading Systems Coding: Testing, Troubleshooting and Optimizing
  6. Trading Systems Coding: Using Your System
  7. Trading Systems Coding: Conclusion

Trading Systems Coding: Testing, Troubleshooting and Optimizing

By Justin Kuepper
Contact Justin

Now that you have a trading system designed and coded, it is time to test it to make sure that your coding is free of logical and technical errors. We will also look at something known as optimization - a feature in some trading programs that allows you to fine tune your trading rules to fit the stocks that you plan on trading.

Testing Your Trading System
The vast majority of trading applications that support programming languages also support testing tools. These tools are divided into two categories:

1. Technical
Technical testing tools search for technical errors in your code. For example, if you forget to add a semicolon after a statement, the technical testing tool will notify you that your statement is invalid.

The location of the technical testing tool depends on the trading application being used. MetaTrader displays an error or flawed results when you try to compile your code, while trading applications like Tradecision have a "code check" utility built into the interface that lets you check your code for errors before applying it.

2. Logical
Logical testing tools search for logical errors in your code. For example, if you happened to use a "greater than" sign instead of a "less than" sign (which is not a technical error), a logical testing tool will show you that your results don't make sense.

The most popular logical testing tool is the backtesting tool. This tool allows you to take past data and apply your trading system to that data. This gives you an idea of the following:

  • Whether your trading system is a profitable one
  • What conditions prove to be most profitable
  • Where any errors in your rules might exist
(For more information, see Backtesting: Interpreting The Past.)

Troubleshooting Your Trading System
As with any other type of programming, troubleshooting can be a tedious and difficult task. Finding errors in your code requires systematically sorting through your code to identify syntactical errors that, although often minor, can bring your program to a halt.

Here are some common errors to look for:

  • Missing semicolons after statements - These have to be after every statement.
  • Undefined variables - Remember that you have to declare them before you use them!
  • Spelling mistakes - If any names or functions are spelled incorrectly, the trading application will return an error (see example below).
  • Incorrect usage of (=) - Remember that "=" assigns one value to another value, while "==" means "equal to".
  • Incorrect usage of built-in functions - Consult your trading application's documentation or application programming interface (API) to make sure that you are using the correct syntax.
Some trading applications contain a feature that will let you test your code before using or compiling it. This feature allows you to see what the error is and on which line it can be found. Take Tradecision for example:

Figure 1

Here we can see that Tradecision gives us the location (line and column) of the error, a description of the error and the type of error (in this case, it is syntactical). If we look at the expression, we can see that in column 8 "xrossBelow" is not a valid function. If we replace the "x" (which is in column 8) with a "c", then we will have valid code.

If we look at MetaTrader, we can see that the errors come up when we try to compile the program:

Here we can see that in the description it says the "BuyNow" variable wasn't defined. Double clicking on this error message will bring us to the specific location of the error in the code.

As you can see, most trading applications give you an easy way to locate technical errors and fix them. Fixing the errors simply involves systematically going through each error message and then recompiling the code and/or applying the trading system to your charts.

Optimizing Your Trading System
Some trading applications let you select variables to be optimized. Tradecision, for example, lets you easily select a variable and replace it with code that will attempt optimization. Optimization itself is simply a process that finds the optimal value for a particular trading system element based on past results and performance. Note that over-optimization results in trading systems that are unable to adapt to market conditions; therefore, it is important to only optimize a few important variables, not every variable!

Here is what the optimization feature looks like in Tradecision:

Figure 3

You can see that we declared two new variables and set them equal to "#". The "#" simply means that the trading program will replace this with the optimal number. Next, you can see that we used the new variables within our trading strategy. Finally, we set a range for the numbers (so that the program will not search to infinity).

Some other trading programs have features that operate in a similar way, allowing you to replace the numerical value with a "#" and telling the trading application to optimize it.

By now you should have developed a working trading system in which you can have confidence. In the next part of this series, you will learn how to apply your trading system to charts and how to use it to make trading decisions!

Trading Systems Coding: Using Your System

  1. Trading Systems Coding: Introduction
  2. Trading Systems Coding: System Design
  3. Trading Systems Coding: The Coding Stage
  4. Trading Systems Coding: The Coding Process
  5. Trading Systems Coding: Testing, Troubleshooting and Optimizing
  6. Trading Systems Coding: Using Your System
  7. Trading Systems Coding: Conclusion
  1. Indicator

    Indicators are statistics used to measure current conditions ...
  2. Intraday Momentum Index (IMI)

    A technical indicator that combines aspects of candlestick analysis ...
  3. Money Flow Index - MFI

    A momentum indicator that uses a stock’s price and volume to ...
  4. OsMA

    An abbreviation for Oscillator - Moving Average. OsMA is used ...
  5. Triple Exponential Average - TRIX

    A momentum indicator used by technical traders that shows the ...
  6. Hybrid Indicator

    A technical indicator that combines core elements of chart analysis ...
  1. How do quant traders build the relative strength index (RSI) into their algorithms?

    Different quantitative traders use different methods to build the relative strength index (RSI) into their algorithms. Three ... Read Full Answer >>
  2. How do you know where on the oscillator you should make a purchase or sale?

    Common oscillator readings to consider making a buy or sale are below 20 or above 80, respectively. More aggressive investors ... Read Full Answer >>
  3. How do I Implement a Forex Strategy when spotting a Sanku (Three Gaps) Pattern?

    A forex trading strategy can easily be implemented to profit from a market reversal signal that comes from the sanku, or ... Read Full Answer >>
  4. How effective is creating trade entries after spotting a Tri-Star pattern?

    The tri-star patterns, both bullish and bearish, are about as rare as they are unreliable. Comprised of three consecutive ... Read Full Answer >>
  5. What are the most popular forms of technical analysis?

    The most popular forms of technical analysis are simple moving averages, support and resistance, trend lines and momentum-based ... Read Full Answer >>
  6. What are the most common market indicators forex traders follow?

    There are literally hundreds of technical indicators for forex traders to choose from, however, there are a few which may ... Read Full Answer >>

You May Also Like

Hot Definitions
  1. Term Deposit

    A deposit held at a financial institution that has a fixed term, and guarantees return of principal.
  2. Zero-Sum Game

    A situation in which one person’s gain is equivalent to another’s loss, so that the net change in wealth or benefit is zero. ...
  3. Capitalization Rate

    The rate of return on a real estate investment property based on the income that the property is expected to generate.
  4. Gross Profit

    A company's total revenue (equivalent to total sales) minus the cost of goods sold. Gross profit is the profit a company ...
  5. Revenue

    The amount of money that a company actually receives during a specific period, including discounts and deductions for returned ...
  6. Normal Profit

    An economic condition occurring when the difference between a firm’s total revenue and total cost is equal to zero.
Trading Center
You are using adblocking software

Want access to all of Investopedia? Add us to your “whitelist”
so you'll never miss a feature!