If not correctly built and backtested, mechanical trading systems could make a lot of damages to your capital. Each trading system you develop must pass through a series of tests to ensure that it is robust enough and that its results are statistically significant and not due to chance.
To create a robust stock trading system you must ensure that:
It is profitable for different markets or stocks
A robust stock trading system must be able to produce profitable results for different group of stocks (Example: Stocks whose ticker symbol starts with "a" and stocks whose ticker symbol starts with "b")
Changing the start date of the simulation does not affect its performance
Change the start date of a simulation and observe changes.
The performance of your stock trading system is not affected by simply changing the value of one of its parameters
If you are using a 50-Bar moving average in your buy rule, then try another period (60 or 40) and make sure that the performance of your system is still strong.
It is not over-optimized (curve-fit)
When optimizing the different variables of your trading system, make sure you apply the in-sample/out-of-sample technique.
The logic and trading rules behind the strategy make sense
The following rule makes sense: Close above moving average
The following rule doesn't make sense: Close above the relative strength index (RSI)
The performance of the strategy is not due to a very small number of trades
In the trading system report, select "Trades" tab then verify that the top 5 or 10 trades are no responsible for the majority of your trading system's profits.
It has a good return almost every year
In the trading system report, select "D.W.M.Y" and check the return of each year (fourth graph)
Vary the start date to test the robustness of your stock trading system
In this article, we will test the robustness of a trading system by applying a technique that consists of performing several backtests each one with a different start date (second point from the above list). This allows the backtester to pick different stocks or securities on each run then calculates the performance of your trading systems so that you can measure the average performance and thus verify whether you have a robust trading system or not.
The implementation of this technique requires a money management script. In the next paragraph, we will show you how to implement this script. Note that you can download a ready-to-use version here (Vary the Start Date of a Trading System Simulation).
First, we must catch the "OnStartSimulation" event and add an optimizable variable. This variable is going to be used to create different start periods.
Functions.SetNumericInput("Lag", 5, "Wait the specified number of bars before starting the simulation");
In the "Global" event, let us create a new variable (lag):
double lag = 10;
In the "OnEndPeriod" event, we must read this optimizable variable and associate it with the "lag" variable specified in the "Global" event. We must also decrease the "lag" variable by one on each new period.
lag = (double)Variables.GetVariable("Lag");
Finally, in the "OnNewPosition" event, we simply need to reject any new position if the "lag" variable is still positive.
if(lag >= 0)
Note: To create a new money management script, select "Analysis -> Advanced Money Management Script", type the different scripts (for each event) then click on "Save".
How does it works?
Now, let us try this trading system robustness technique on one strategy. Either you must download the money management script from here (Vary the Start Date of a Trading System Simulation), or you can create it by following the above steps.
- Select a trading system you want to test
- Click on "Update" to update your trading system
- Select "Money Management" tab (top)
- Click on "Add an existing money management script"
- Select your MM script then click on "Load Selected Item"
- Click on "Update Trading System" (bottom) to save changes
Now, you will see a new tab in the right panel. There, you can specify the "Lag" period or the number of bars to wait before starting entering trades.
To optimize this variable:
- Click on the icon next to "Optimize" (Under "Money Management Variables")
- Select, for example, "From 0 to 20, increment by 5"
- Click on "Optimize" button to start the robustness test of your trading system (optimization process)
In the simulation report, you will see five different backtests, each one corresponding to a different "lag" period (check the "Lag MM" column). If the performance (return, maximum drawdown, Sharpe...) measures are stable then your stock trading system passed this robustness test and it is time to make further verifications (See the list above). Otherwise, the trading system you have developed is not strong enough and you probably should not trade it with real money.