Building a profitable trading system is very difficult. I'm not going to sugarcoat it. It's a challenging project where most of your ideas will not work. To make matters worse, you're bombarded with misleading advertising, confusing claims, and wrong information. Learning a computer language to build a system is excellent, but that's NOT enough to build a successful system.
Combining a few technical indicators with a buy order and adding trailing stops are not going to make you a profitable trading system. You are going to need an organized approach and perform specific steps to create a successful trading system.
Developing trading systems is not an exact science like physics. It's really a mix of both art and science. Your creativity comes into play when attempting to uncover market edges that may lead to a great trading system.
The science side of the process comes into play with careful observation, note-taking, and rigorous testing of your trading model. Unlike science, however, there are no hard-set rules that will produce consistent results or winning systems.
In physics, the law of gravity affects all objects on Earth the same way, all the time, everywhere. It's a law that is universally known and understood. The theory of gravity can make excellent predictions about the future. For example, it can predict when the moon will rise and how to estimate the flight time of an international flight. Market follows no such law. You can't predict where the market will be with 100% accuracy 10 minutes into the future or next year.
This article describes an overall process in building and testing automated trading systems that I personally follow. It's a step-by-step process that helps me build a profitable trading system. Does it always work? Of course not. But I follow it religiously because I've seen it work many times.
12 Steps To Build Profitable Trading Systems
Step 1: Your Key Idea
The first step in developing a trading system is coming up with the key idea. A key idea is the core of your trading system. It's an observation of the market that can be used as a starting point for creating a system. It can be a straightforward observation, such as how price behaves around the 50-period moving average during a strong trend. Or it could be noticing that opening day gaps on high volume often leads to price climbing most of the day.
From a scientific point of view, your key idea is your hypothesis on how the market behaves. With this key idea we hope to discover a potential market edge and exploit it with our trading system.
This key idea should be simple and easy to program into an automated system. For example, a key idea might be to purchase a 20-day high. The hypothesis behind such a key idea is the belief that all new trends start with a 20-day high. This is an example of a trend following trading concept. However, not all markets have trending characteristics. For example, there are many examples on EasyLanguage Mastery that show the S&P E-mini futures market exhibiting strong mean reversion behavior. In this case, fading or going short upon 20-day highs may be a better idea. The point here is you need to know your market. You need to know its characteristics and come up with a key idea.
Step 2: Define Testing Environment
The pre-work phase for developing a system is to nail down the development environment in which you will be developing your system. This is where you will decide on what market you are going to trade and define some important parameters that will impact your development and testing. You'll want to write these down, so you don't forget them.
- Platform & Version Numbers
- Market to trade
- Time frame to trade
- Slippage & Commissions
- Estimated starting equity
- In-sample period
- Out-of-sample period
- Maximum Bar Lookback
Step 3: Sanity Check
At this is point, I perform a sanity check on my Key Idea to compare it with my other Key Ideas I have yet to test. With so many ideas, I'll often have a dozen Key Ideas awaiting for me to check. I can't always get to them right away, so I set them aside for later. Because I have so many ideas to work on I don't want to "lose my sanity" so, I focus on the best ideas first. How?
We need a way to rank our Key Ideas and eliminate unproductive ideas. By doing this, we can focus our time and energy on the most promising prospects. This will help us get the results we want, more quickly and effectively.
A simple sanity check is to rank your key idea based upon an objective score. This score can be something as simple as the net profit, the profit factor or the annual rate of return. I like to use TradeStation Index or Profit Factor. But you could use whatever you wish.
Once we have the expectancy score, we can now rank each of our Key Ideas by this value. I personally keep a spreadsheet containing a list of the Key Ideas that need review. One of the columns on this spreadsheet includes the Profit Factor. I then can quickly sort my Key Ideas based upon this score; thus, revealing which are the top performing Key Ideas. I can then start testing my best ideas first.
Doing this also allows you to keep a log of what ideas you considered, rejected, or have yet to explore. Very helpful!
Step 4: Stress Test Key Idea
A stress test is subjective but plays a vital role in order to help ensure that a given input parameter is not curve fitted to the historical data.
Stress testing involves making changes to the input values to see how the system performs. To do this, we will need the ability to vary an input value. Sometimes a key idea will only have one or two variables. Others will be more complex.
What we want to do is vary the input parameter to see how our key idea holds up. For example, let's say one of our input values in a lookback period used within an RSI calculation. Let's also say the default value is 10. If we change the lookback period from our default value of 10 to 9, I don't want to see the system's equity curve change dramatically.
Neighboring values should still show positive results. Likewise, if we increase the lookback period from 10 to 11, I don't want to see a drastic change in results. The key point is, the neighboring values around the default value of 10 should still produce positive results. In fact, it would be great to see the system remain profitable over a wide range of values.
Use TradeStation's optimizer to test values around the default value and generate a bar graph like the one below. Then you can quickly see if the value is likely over-optimized or not.
A system that holds up over a wide range of parameters demonstrates robustness and passes our stress test. If you see dramatic changes in performance, it's possible that the input values are too optimized, and the strategy is not robust enough to withstand the live market. Be warned!
Step 5: Market Environmental Filters
Often when designing a system, it's essential to keep the big picture in mind. What is the overall market doing?
Market environmental filters is a term I use to describe the overall market conditions for the instrument you're trading. These are the large macro-level pictures that appear on the daily or weekly charts.
This large macro picture can be applied to any market. For example, when looking at a daily chart, the market can be either in a bull market, bear market, or perhaps in a range-bound market. To keep things simple, we can use the binary technique to divide a market: bullish or bearish.
A bull or bear market regime filter divides the market into modes: bullish or bearish. Often this is done so you can trade with the major market trend.
For example, only take long trades during a bull market and step aside or short during a bear market. That is, only take long trades during a bull market and take short trades during a bear market. It's a simple concept and many discretionary traders take into account the overall trend of the market before opening a new position. You will find that not fighting the major market trend could very well improve your system drastically.
Of course, you do not have to stop by merely dividing the market into two regimes (bull or bear market). You could divide the market into three regimes. Bull, Bear, and range bound. This begins to complicate your system more but might be worth looking into.
Another market characteristic that is common for all markets is the strength of a trend. A market may be in a bull regime, but how strong is the trend? Is the market rising fast, or is it a weak trend. By measuring the strength of the trend, we can further divide the market to make our trading system more adaptive. By introducing trend strength, we now create four distinct market environments that can be used to determine how an automated system trades.
Step 6: Creating The Baseline
Now we'll begin performing more in-depth testing. This will be done by adding different rules to the system. These rules include testing hard stops, various entry methods, and multiple exit methods. We'll keep a rule if we can significantly improve system performance. Otherwise, we'll drop the rule. But how do we know if a given rule that we're testing has improved the system? We need something to compare it to. This is where our baseline system comes into play.
To properly perform our testing, we first need a baseline system. This baseline system will be used as a benchmark to determine if we have improved our trading system substantially enough to justify the given modification. What is our baseline system? It is merely our key idea with our environmental filters applied.
During this step, I will also Stress Test the regime filter(s).
Step 7: Independent Testing
The point of this step is to explore other trade filters, exit methods, and entry methods so we may incorporate these rules into our final trading system. During this step, we are interested in not only if we can improve our system but does the new rule demonstrate robustness. Just as shown above, we'll Stress Test our filters by following the same principles.
In general, the more trading rules you optimize together, the more likely your system will suffer from being overly optimized. It's essential to make an attempt to keep your trading system as simple as possible. If you only take away one concept from this article, make it this one because over-optimizing is an area where many people stumble. To help avoid curve fitting, the key is independent testing of each rule.
What does Independent Testing mean? Let's say you have a simple moving average crossover system. You then wish to test a trailing stop and a trend-strength indicator to filter trades. So we have the following items to test:
- Look-back period of the moving average crossover
- The threshold value used on the trend filter
- Trailing stop distance
How do you pick values for each of these indicators? How do you optimize your system? Each new rule that we test must be done independently of the other rules. While it's not always possible to completely do, it should be done whenever possible.
Let's say we would like to test a trailing stop. After adding the trailing stop to our baseline system we determine such a rule is robust across a wide range of values and decide $500 is reasonable.
Let's say we next choose to test a profit target. To verify our profit target rule we must revert back to the baseline system. That is, we do not add our profit target rule to the system with the trailing stop rule. Our profit target rule must be applied to the baseline system (which has no stop loss).
Each new rule that we test must be made independent of the other rules. This is done to avoid over-optimization and will help maintain a robust system.
Step 8: Combining Rules
After we have completed our independent testing, you will have a collection of entry methods, exit methods, and filters along with their associated non-optimized parameter values. These rules can now be combined into a single system.
Obviously, we are not going to use everything. Instead, we will start out with our baseline system and add rules one at a time as needed and measure its effect on the system's performance.
Sometimes when adding a rule, you see substantial improvement in the performance results. In this case, you can keep it. Other times adding a rule does little to help the system performance. In this case, it's best to keep things simple and eliminate the least productive rule. Be selective and only include a rule if it clearly helps. If it does not significantly improve the system's performance, it's probably best to leave it out. Remember, we want to keep our strategy as simple as possible.
Step 9: Out-of-Sample Testing
Once you have combined your rules into a final system you can now perform Out-Of-Sample (OOS) Testing. This simply involves taking your final system and testing it on data that was not used during the development of the system. We do this to see how the system performs on this “unseen” data and to answer some important questions.
- Does the equity curve break down?
- Does the equity curve produce wild swings?
- Do we make new equity highs or does the equity curve remain flat?
- Are the strategy parameters still reasonable/tradable?
What we want to see is an equity curve that has characteristics similar to what we see during the testing period. In other words, drawdowns and new equity highs should look similar. If they do, you have created a system that might be a winner. However, if the equity curve deviates from what you see on our historical data, such as dramatically breaking, it's time to get back to the drawing board.
Sometimes you will have a system that goes flat on the OOS data. Does this mean it's a failure? Well, not always. If your historical test period, the in-sample data, had similar flat periods then the current flat period may very well be normal. I would be more suspicious if you had a steady rising equity curve on the in-sample data and then saw a flat period on the OOS data. A flat period or even a drawdown on the OOS data does not automatically disqualify the system. As long as it's within the parameters of what was observed during the in-sample period.
The subject of testing trading systems is a vast and growing topic that can get very complex. From hypothesis testing, data-mining bias, cross-validation, and bootstrapping, you can get deep into this subject very quickly. I encourage you to explore these subjects down the road. For now, I would focus on building the systems following the guidelines within this article to avoid over-fitting your system to the historical data.
To expand your testing knowledge I would recommend you to study the following topics next:
- Walk Forward Optimization
- Monte Carlo to further test the strategy
During this phase of development I would use these two tools (above) to further test my trading model.
Step 10: Live Market Testing
This is a rather simple process of loading your strategy into your trading platform and allowing it to execute trades on live market data in simulator mode. This is the closest testing you're going to get without using your own money.
What you wish to see is your trading system performing as expected. That is, identical to its historical performance. I would examine the trading performance of the live data and compare it to the performance statistics of the backtested data (this can include the OOS data as well). It should be similar. You should see both winning trades and losing trades that all fit within the parameters of the backtested results. The equity curve should behave as it does in the historical data, slight pullbacks, and pushes to new equity highs. Remember the maximum drawdown while reviewing the historical results? Within this test period, I would be very suspicious of a system that breached this maximum drawdown value.
It is during this time you may see coding logic problems appear. One that got me a few years ago was attempting to close a trade on Friday afternoon with a newly created futures trading system. The code worked well during the historical data, but on the live market, there was a little glitch. The system was designed to close any open trade at the end of the trading day on Friday. It used a market order to exit. Unfortunately, the system needed to close the trade at the open of the next bar. The key phrase here is "next bar." Well, the market was now closed for the weekend, and the next bar would not appear until Sunday afternoon. So a trade which was supposed to close Friday did not close until Sunday afternoon. Not exactly what I wanted.
These types of coding issues are what you will want to look for before putting your money at risk on the live market. They often can happen on what I call boundary conditions such as, the end of the week boundary in this example.
Step 11: Position Sizing
There really is no Holy Grail of trading; however, position sizing comes close. Position sizing is an integral part of both system trading and discretionary trading alike. It answers the question, how many shares or contracts should I buy?
Too often this question is answered by nothing more than an educated guess. Too many traders position size their trades by not accounting for risk in determining the number of units to buy. In doing so you could be sabotaging your results, your system and maybe your career as a system trader! By tying your trade size to a risk metric you are acting defensively in the face of a dynamic market. Managing risk should be a top priority of any good trader. Thus, using a risk-based metric to help you mathematically determine how to size your trade is vitally important.
For most people, they use a fixed number of contracts/shares or dedicate a fixed dollar amount for a trade. Let's think about this for a moment. When a trading system generates a new buy signal, you could risk all of your cash on that one signal. If you win, you might double your money very quickly. Yet if you lose, your account is at zero. It's probably not a good idea to bet all of your account on a single trade, right?
Most people understand this extreme example and, thus, will not bet their entire trading equity on a single trade. It's way too foolish. So, how much do you bet? Maybe 90% of your account? Or perhaps you decide 100 shares is about right.
What many system developers fail to see is how their trade size affects the risk and reward of the given trade. As you risk more, the payoff can be more significant. However, risk too much, and you can be quickly wiped out by a string of losing trades. There exists a theoretical optimal balance between the risk and reward based upon the given trading system. Your job is to find a near-optimal level that is comfortable for you as a trader.
Below are some popular position sizing formulas.
- Method 1 - Fixed Shares
Shares To Buy = 200
- Method 2 - Fixed Dollar
Shares To Buy = $10,000 / Current Price
- Method 3 - Percent Risk
Shares To Buy = (2% of Total Equity) / ( 5% of Current Price)
- Method 4 - Percent Volatility
Shares To Buy = (2% of Total Equity) / 4*(10-Day Average True Range)
I hope this demonstrates the difference between non-risked based position sizing methods (Fixed Shares and Fixed Dollar) and risk-based methods (Percent Risk and Percent Volatility). I also wanted to highlight the importance of understating risk management and implore you to use it!
Step 12: Trading Live!
Once you have tested your system on the live market in simulation mode and you feel confident in it, you can transition your trading to the live market. There are many things to be aware of when trading on the live market, including how do you handle...
- Power outages
- Dropped internet connections
- When your live accounts become out-of-sync with your brokerage account
- What do you do when you go on vacation?
All of these topics are beyond the scope of this article, which is focused entirely on the development process, not on platform-specific issues or live trade execution. Here are some recommendations on transitioning your trading to the live market.
First and foremost is risk management! This comes in many forms, including having a stop on all trades that's within your risk tolerance. In this case, since we are starting to trade a new system with real money, it is recommended that you start trading with a significantly reduced position. If you usually risk about 2% of your account equity, cut that down to 1%. The idea is to reduce your risk until you have demonstrated that your trading system is working correctly with live executions.
Other items of importance are how well funded you are and how psychologically fit you are to trade this system. Are you adequately capitalized to trade this system? Also, take a look at the times when the system takes heat (drawdown) and ask yourself, "could you handle that?" Your success will depend on how you endure drawdown!
Let's also say you decide to only trade one contract until you gain confidence that your system is working correctly - always a good idea. Do you jump in and start auto trading? You can, but I often like to time the start of live trading during a drawdown period. This is probably just a personal preference, but I hate the idea of jumping into a system when it's making new equity highs. I wait until a small pullback then start. Often this might be one or two losing trades. But this may not always be practical. Sometimes I'm replacing a system with my new system, and I want it trading now.
In the end, you have to put money on the line and trade your strategy. This can be an uncomfortable feeling, but it's a fear that must be overcome!
My advice, start building systems - lots of systems! It does not matter if they do not work well or if you build systems on markets and timeframes, you don't trade. Just start practicing building systems. Get your hands dirty and put to use what you have learned. You will soon find what works for you in the system development process and what will need to be changed.
Take my 12-step process and make it yours. Record your process, thoughts, and ideas in a notebook. Over the months, you will begin to refine your development process into something that works for you.
There you have it! My 12-step process to build trading systems. If you want to go into a lot more detailed on my 12-step system, then pick up a copy of my eBook, "How To Build Profitable Trading Systems using EasyLanguage." This eBook explains my process in great detail as I walk you through my 12-step process. It's over 100 pages long, and it also includes sample code, a TradeStation WorkSpace, mind maps, and my strategy development templates. If you build systems in EasyLanguage or MultiCharts, you're going to love it!
Get Jeff's eBook!
Learn To Build Profitable Trading Systems
This eBook is over 100 pages in length and explains my 12-step process in great detail!