August 12

4 comments

How To Build Profitable Trading Systems

By Jeff Swanson

August 12, 2024

Algorithmic Trading, TradeStation

Building a profitable trading system takes a lot of work. It's a challenging project where only some of your ideas will 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 more is needed for a successful trading system.

Combining a few technical indicators with a buy order and adding trailing stops will not 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 a 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 scientific side of the process comes into play with careful observation, note-taking, and rigorous testing of your trading model. Unlike science, however, no hard-set rules will produce consistent results or winning systems every single time.

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 estimate the flight time of an international flight. The 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 my overall process in building and testing automated trading systems that I follow. I call it the Profit Lab Method. 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. It's my blueprint for building winning trading systems. Much like before building a home, you need a blueprint.

10 Steps To Build Profitable Trading Systems

Profit Lab Method Infographic

Step 1: Finding Great Trading Ideas

The first step in developing a trading system is 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 the observation that opening day gaps on high volume often lead 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 and exploit a potential market edge 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 instance, many examples on EasyLanguage Mastery 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 better.

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: Focus On Best Ideas First

It's easy to collet Key Ideas from YouTube videos, book, magazines, personal observations, and blogs. I record them all in a notebook. I'll often have a dozens of Key Ideas awaiting for me in a notebook. 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, how do I know which one to work on first?

The Stress Test

A stress test is subjective but plays a vital role in helping ensure that a given input parameter is not curve fitted to the historical data.

Stress testing involves changing 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, and others will be more complex.

We want to vary the input parameter to see how our key idea holds up. For example, one of our input values in a lookback period is used within an RSI calculation. The default value is 10. We should change the lookback period from our default value of 10 to 9. In that case, 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 critical 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. See the optimization below.  If you see dramatic changes in performance, the input values may be too optimized. Be warned!

Example of robustness - a wide range of successful input values.

Ranking Key Ideas

We need a way to rank our Key Ideas and eliminate unproductive ideas. Doing this lets us 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 on an objective score. This score can be as simple as the net profit, the profit factor, or the annual rate of return. I like to use TradeStation Index or Net Profit vs. Drawdown (NPDD). But you could use whatever you wish.

Once we have the expectancy score, we can rank each of our Key Ideas by this value. I 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 on this score, thus revealing the top-performing Key Ideas. I can then start testing my best ideas first.

Having a master list of Key Ideas lets you keep a log of what ideas you considered, rejected, or have yet to explore. Very helpful!

Step 3: Define Testing Environment

The pre-work phase for developing a system is to nail down the development environment in which you will build your trading system. This is where you decide what market to trade in and define some important parameters that will impact your development and testing. You'll want to write these down, so you remember them. This also provides the ability to re-create your development environment in the future.

Here are some things I like to record.

  • 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 4: Define The Baseline

We're close to testing different filters, targets, and exits to our baseline strategy to see if it improves the performance. When we try these filters, how will we know if it's working well? Easy, we'll compare the performance metrics to our baseline.

In short, our baseline will act as a bench market for future comparison.

So, our baseline strategy must be working correctly. Thus, we want to review our code to ensure everything is working as expected.

Things to look for are trades closing when expected.

  • Are trades opening and closing on the same bar
  • Are trades mysteriously opening on the first bar of a new day
  • Are you using the reserved word setexitonclose, and will that be an issue
  • Are your price calculations rounding to a realistic price?

Adding Stops?

Another important aspect of our baseline is introducing a stop value. Most people only trade with stops. Thus, we should add a stop value to make our baseline more realistic, given our individual risk tolerance.

Most of my Key Ideas will don't have a stop value. At this point, I decided whether to add a stop value. Sometimes I do, while other times I don't. If I don't add one here, I will wait until the end of the development process to add a stop.

Remember that even though we pick a stop value for our baseline, we can change it later. In fact, we will be testing other stops deeper within our development process.

Integrating RSDT Templates

Next, I integrate my Key Idea into my Rapid Strategy Development Templates. I use these custom build EasyLanguage templates during development to help me quickly test different filters, stops, and exits. If you want to see a demo of these templates, you can watch this video demo. These templates are available only to students of the Builder Edition of my System Development Master Class.

Step 5: Market Environmental Filters

When designing a system, it's essential to remember the big picture. What is the overall market doing?

Market environmental filters are a term I use to describe the overall market conditions for the instrument you're trading. These large macro-level pictures 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, bear, or 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. 

Example of a 200-day simple moving average (yellow line) acting as bull/bear filter.

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 consider the market's overall trend before opening a new position. Not fighting the major market trend could improve your system drastically.

Only taking trades in the direction of the major trend as defined by a 200-day simple moving average.

Of course, you do not have to stop by dividing the market into two regimes (bull or bear market). You could divide the market into three regimes. Bull, Bear, and range bound. This complicates your system more, but it might be worth looking into.

Another common market characteristic 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 demand rising fast, or is it a weak trend? We can further divide the market by measuring the trend's strength 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: Independent Testing

This step aims 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. As shown in the previous step above, we'll stress test our filters by following the same principles.

Generally, the more trading rules you optimize together, the more likely your system will need to be optimized. It's essential to keep your trading system as simple as possible. If you only take one concept from this article, make it this one because over-optimizing is an area where many people need help. To help avoid curve fitting, the independent testing of each rule is vital.

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 we test must be made independently of the other rules. While it's not always possible to ultimately do it, 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. We must revert to the baseline system to verify our profit target rule. 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 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 7: Intelligent Construction

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 going to use only some things. Instead, we will start with our baseline system, add rules one at a time as needed, and measure their 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's 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. I use the general guideline that if a newly added rule does not improve an important performance metric (such as NPDD) by 50% or more, I don't keep it. Remember, we want to keep our strategy as simple as possible.

Step 8: Validate Strategy Robustness

Once you have combined your rules into a final trading system, you can perform Out-Of-Sample (OOS) Testing. This involves taking your final trading system and testing it on data 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 critical 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?

We want to see an equity curve with 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, suppose the equity curve deviates from what you see in our historical data, such as dramatically falling below the zero line. In that case, it's time to return 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, only sometimes. Suppose your historical test period, the in-sample data, had similar flat periods. In that case, the current flat period may be expected. I would be more suspicious if you had a steadily rising equity curve on the in-sample data and saw a flat OOS data period. This is likely not a good sign, and you may want to fail this system.

However, a flat period or 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.

I recommend you have at least 30 trades on your out-of-sample. If you have less than 30, you'll need to stop evaluating your strategy. Save your work and revisit your trading system when you have 30+ trades on the out-of-sample. Then you can decide if it's working as expected on the out-of-sample.

The subject of testing trading systems is a vast and growing topic that can get very complex. I perform several other tests that include:

  • Data Augmentation
  • Walk Forward Analysis
  • Monte Carlo testing

Covering these will make this article far too long. To expand your testing knowledge, I recommend looking into these techniques further. The out-of-sample testing is one of the more critical tests and one of the easiest to perform, and thus I covered it in this article.

Step 9: The Bullet Proof Portfolio

So what most traders do is look for the single best trading system. I've talked to you out there, and I've done it myself. I'll spend weeks or months tailoring testing, tweaking a trading system, and attempting to find the best rules that will work. But the idea that you will build one trading system to make enough money to live on is a fallacy.

Nobody focuses on a single system if you want to be a successful trader. Instead, successful traders focus on a portfolio.

The holy grail is not a system, an indicator, or a trading style, and it's not EasyLanguage or python. Instead, it's building a bulletproof portfolio of trading systems. Again, a portfolio is probably as close as the holy grail of trading.

We want to rely on more than just one system. We want to have several systems, dozens of systems. That way, we are diversifying our risk across multiple systems. That's going to help us bring in that consistent money. This will help you become a much better and consistently profitable trader. I cannot emphasize that enough.

Check out this video of Ray Dalio on YouTube as he breaks down the holy grail concept. Ray does an excellent job showing you this graph and the magic of having a portfolio. Once you understand it, you'll see how this is the key to bringing in consistent money as a trader. It's a short video, and I urge you to watch it.

When building a portfolio, I focus on getting the correlation of daily returns as low as possible between my trading systems. I also aim to select strategies that work well together to maximize NPDD. How do I do that? I use Portfolio Analyst.

A portfolio of low-correlated strategies helps reduce drawdown and bring in more consistent returns. This is an important asset you'll want to focus on building.

Step 10: Trading Live!

There are many things to be aware of when trading on the live market, including how 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?

These topics are beyond this article's scope, which is focused entirely on the development process, not on platform-specific issues or live trade execution. But you will want to research this.

Many of the above issues can be solved or significantly reduced by using remote hosting services to power their trading computers. 

Traders who use remote hosting services can trade from anywhere with an internet connection without having to worry about the whereabouts of their physical trading computer. This is especially useful for traders who travel frequently or want to avoid dealing with the hassles of running trading computers. But even if you never or rarely leave your home trading computer, there can be considerable advantages to hosting your trading platform on a remote site.

I'm currently using ChartVPS and have also used Speed Trading Servers.

That's it! That is my develop process in a nutshell.

My Advice...

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. 

If you want my help with building and validating trading system, join me in my in-depth training, System Development Master Class.

Jeff Swanson

About the author

Jeff has built and traded automated trading systems for the futures markets since 2008. He is the creator of the online courses System Development Master Class and Alpha Compass. Jeff is also the founder of EasyLanguage Mastery - a website and mission to empower the EasyLanguage trader with the proper knowledge and tools to become a profitable trader.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Learn To Code & Build Strategies
    Using EasyLanguage. 

    >