Algorithmic and Mechanical Forex Strategies | OneStepRemoved

  • Articles
  • Sophisticated Web Sites
  • Automated Trading
  • Testimonials
  • Contact

The Blueprint for Creating Your Own Forex Strategy, Part 2

February 18, 2014 by Andrew Selby Leave a Comment

Earlier this month, we looked at an article from Forex Crunch that covered the first three steps for building a new quantitative Forex strategy. Those first three steps covered brainstorming strategy ideas, defining the rules, and optimizing the parameters.

At that point we had a strategy that we had reason to believe would perform well in a trading situation. The next steps would involve properly testing our strategy in order to prove its value.

forex strategy

After brainstorming, defining rules, and optimizing a new Forex strategy, the next steps involve rigorous testing.

Forex Crunch has since published the second three steps for creating a robust Forex system. This post focuses on testing the system that was created with the first three steps. It suggests starting with in-sample testing, then moving to out-of-sample testing, and then suggests some even deeper methods of testing.

The Most Important Point Regarding Testing

While there is plenty of great information in the article about the different types of testing that should be performed on a new Forex strategy, the most significant point that the article makes is actually stated in the introduction:

Relying on the CAR (compound annual return) figure is not always a good idea because this metric does not take into account the risk that was involved in producing those gains.

This point is extremely basic, which makes it easy to overlook. While a strong compound annual return is the end goal of every trader, we all know that there are many ways to arrive at a strong compound annual return, and some of them aren’t worth the effort.

In addition to compound annual return, we also need to be concerned with how the strategy performs from a risk perspective. Looking at statistics like maximum drawdown, profit factor, Sharpe ratio, and winning percentage gives us a better idea of how the strategy arrives at its compound annual return.

This bigger picture view will give us a more qualified overview of what trading the strategy will feel like. We can use that to determine if the amount of risk the strategy exposes our capital to is in our tolerable range.

Testing Forex Strategies

Testing on in-sample data is where we can fine tune our strategies in order to get the return and risk statistics into the desired range. From there, we move to out-of-sample testing where we attempt to replicate those statistics on a fresh data set.

There are also testing methods like Walk-Forward Optimization and Monte Carlo Simulations that can shed even more light onto how our new system can be expected to perform in live trading. The important thing to watch for during this testing phase is consistency. The strategy should perform similarly across all of these different types of testing.

If the strategy produces solid returns through a wide range of testing, it can be expected to produce similar results in live trading.

Filed Under: Test your concepts historically Tagged With: backtesting, in-sample, monte carlo, out-of-sample, walk forward

Walk Forward Optimization

January 13, 2014 by Shaun Overton 6 Comments

If you were walking and randomly it started to rain, would you consider carrying an umbrella tomorrow? Of course you would.

The reason I ask a rhetorical question like that is when people observe a behavior, they respond accordingly. If they expect that something might happen again, they change their behavior to accommodate the change in outcomes.

When you think about forex robots, everybody has the dream of developing a strategy that works forever. It requires no changes. The initial settings always work. Turn it on and move to the beach.

Reality, of course, is more complicated than that.

walk forward optimization

Walk forward optimization continually optimizes throughout time instead of looking for one set of static settings

That leads to expectations of what you need to do when your strategy inevitably goes awry. It’s very possible that you come up with a strategy that works and does amazingly well on the current market. However, a past genius doesn’t mean future genius. There’s always the chance that your strategy will no longer work in the future.

Why is that? It’s the same reason that you might carry an umbrella tomorrow if it rains today. People observe the market performing in a consistent manner. As more and more people make the observation, people start trading on it.  The market responds to those changes, and eventually the opportunity completely washes out as too many people have eared about it.

Walk forward testing is the process of determining whether or not your strategy has washed out. By testing on one set of data, and then testing it on a blind set, you can give yourself an indication of whether your strategy is bad or not. The goal of walk forward isn’t to prove that your strategy is good. It’s to prove that your strategy is not known to be bad.

The process of walk forward testing is very simple. You identify a set of information that you want to use for your testing and optimization. Using a real example, right now it’s the beginning of 2014. So maybe you want to look and test data from 2011 through 2012. That would be your in sample data, and then your out of sample data might be all of 2013.

In order to conduct a walk forward test, you would test and analyze your strategy 2011-2012. Then, to determine if it’s “not known to be bad”, you then walk forward to 2103 to see review the performance.

What you’ve done is a blind test. You didn’t know what how the strategy would perform in 2013 when you tested it in 2011-2012. By putting it on a blind sample, you give it the opportunity to fail.

The reason so many traders put their faith in walk forward testing is because it’s the absolute best tool to identify weaknesses in your optimization. When you’re testing a strategy, it is very likely that you’ve overfit to past opportunities.

Self feedback loops in the current market

Let me give you an example. In the current markets, a lot of traders have been banging gold on the market open where every day at market open., they sell as much gold as they possibly can. Sometimes it’s several multiples of the annual production in a span of a few minutes. What you see is an absolute freefall for five or ten minutes. That state persists for days at a time. But that doesn’t last forever. When enough traders start seeing that people bang gold on the open, they start doing the same thing.

Effectively, whoever wants gold to falloff on the market open has taught other traders to do that trade for them. As people expect gold to fall in the first five minutes of the open, they then change their behavior. Some try to jump on banging the open and go short.

Others start modifying their behavior. They notice that gold free falls for five minutes. Then, all of a sudden it stops, and more than like it reverts to the mean. They’ll start changing their tack and buying after so many minutes have elapsed from the open. They expect that the heavy volume that preceded the selling will eventually return to normal. As people change their behavior, other people respond in kind.

If enough people start selling on the open and then buying on the open five minutes later, you can see that a pattern is forming where one person responds to the actions of another. It’s a self feedback loop where the state that was working for the first couple of days no longer works in the future.

If you can identify a strategy that is able to survive those conditions, and is able to survive conditions where you didn’t do any testing and optimization, you give yourself better odds of succeeding in the future. It means that not very many traders have clued into this trading opportunity that you’ve discovered.

The approach to to walk forward testing is the antidote to the problem known as curve fitting. Curve fitting is the ultimate woulda coulda shoulda strategy.  It’s akin to opening a chart from yesterday and saying I would’ve bought here and I would’ve sold here, already knowing what transpired.

Of course you’re going to “make money” in that situation. You know with perfect information what the market did. In the future, you don’t know the perfect information. The goal of a strategy is to deal with that ambiguity.

Curve fitting means that you’ve fit everything so perfectly to past market conditions that when new situations inevitably arise, sort of akin to the phrase, “history doesn’t repeat itself, but it rhymes,” your strategy does the same thing.

You want a strategy that does well on past performance, but you’re not coming up with a strategy to make money on historical markets. The purpose of developing a strategy is to make money in future markets. When you’re backtesting, you’re trying to strike the balance between solid historical performance and, most importantly, making sure that that historical knowledge extrapolates to future performance. Your goal is to make money.

Rolling Walk Forward Optimization

Rolling walk forward optimization takes the walk forward idea and continuously improves the strategy by exposing it to new data. So let’s say that you have a twenty four month sample period. One way to go about it would be to optimize your strategy for a period of two months, then to walk it forward to the third month. You observe the behavior and you reoptimize for the second and third month, then walk it forward to the fourth month.

By doing so continuously, you eliminate the decay time of the strategy and give it a chance to adapt to ongoing market conditions. It is sort of the redheaded stepchild to machine learning. Experience and losses give the strategy the opportunity to improve and adjust to the market changes through walk forward optimization.

…you eliminate the decay time of the strategy and give it a chance to adapt to ongoing market conditions

Another important consideration for walk forward analysis is the degrees of freedom within a system. For example, let’s say that you are analyzing a moving averaage cross. You’re using two moving averages and use a fixed stoploss and take profit. That would give you four degrees freedom. The fast moving average is the first degree. The slow moving average is the second degree. The third is the stoploss and the fourth is the take profit.

The more degrees of freedom that you allow in a system vastly increases the chances 0f curve fitting your systems to historical data. The absolute best systems maintain twelve degrees of freedom or less. You want to find trading opportunities that have large numbers of trades and that offer performance that you find satisfactory.

Another element to consider in your optimization is what are you optimizing for.  Most people focus on the absolute return.  Returns are great, but most traders care much more about how they make their money instead of how much. Let me give you an example. If I had a system that made $25,000 last year, would you want it? Almost everybody says yes.

If I have a system that made $25,000 last year, but you had to lose to $15,000 before you made any money. Most people don’t want that system. What this means is that you care a lot more about the performance on a day-to-day basis rather than end result. The problem with optimization and even walk forward optimization is that you’re not necessarily focused on what you care about in the real world: the way that you’re making your money.

Most charting packages focused on the net outcome and that can cause some weaknesses in your system. If you’re range trading, what you’ve really done is cherry pick the results that are the least affected by substantial news. In effect, you’ve chosen the settings that have not yet been affected by fat tails.

If you’re trend trading, you’ve done the exact opposite. You intentionally pick the settings that maximize the fat tailes that have happened in the past. With trend trading strategies, you probably aren’t going to find consistent performance. Instead, what you’ll find is that the optimization frequently causes long, ongoing droughts of incessant drawdown. Then suddenly, almost out of nowhere, it finds a mega monster winner that returns several multiples of the drawdown that you experienced. This is fine for a hypothetical backtests, but in the real world where you’re suffering losses on a near daily basis, most traders can’t take the pain.  The weakness I find with most optimizations is that they don’t look at the consistency of performance. A potential substitute for optimizing a strategy would be looking at the linear regression of the equity curve over time. The best equity curve has the strongest linear regression slope.

Popular charting packages that implement rolling walk forward optimization are Amibroker, TradeStation, Multicharts and NinjaTrader.

Walk forward optimization in NinjaTrader

Open the Strategy Analyzer from the Control Center. Click File / New / Strategy Analyzer.

NinjaTrader Strategy Analyzer selection

Open the strategy analyzer in NinjaTrader

  1. Left mouse click on an instrument or instrument list and right mouse click to bring up the right mouse click menu. Select the menu item Walk Forward. You can also click on the “w” icon in the Strategy Analyzer toolbar. If you prefer hot keys, you can also use CTRL + W. Lastly, you can also push the “W” icon at the top left of the Strategy Analyzer.
  2. Select a strategy from the Strategy slide out menu
  3. Set the Walk Forward properties (See the “Understanding Walk Forward properties” section below for property definitions) and press the OK button.
NinjaTrader Walk Forward Optimization

There are many ways to select walk forward optimization in NinjaTrader

The Walk Forward progress will be shown in the Status Bar of the Control Center.

Filed Under: NinjaTrader Tips, Test your concepts historically Tagged With: Amibroker, backtest, curve fitting, fat tails, gold, MultiCharts, ninjatrader, range trading, self feedback loop, short, strategy analyzer, TradeStation, trend, walk forward

Have You Prepared For System Failure?

January 3, 2014 by Andrew Selby Leave a Comment

One of the misconceptions that many quantitative traders fall prey to is neglecting to consider that their strategy will eventually stop working. We are led to believe that once we develop and backtest a profitable strategy, we will simply be able to print money indefinitely. However, this is almost never the case.

Due to the unpredictable nature of financial markets, all systems and strategies will eventually fail. At the very least, they will need to be adjusted. This means that developing a trading strategy is an ongoing process, not a one-time project.

system failure

Eventual system failure is inevitable for all types of strategies. Are you prepared for it to happen to you?

Daniel Fernandez from Mechanical Forex wrote a post on this topic earlier this week. He suggests that the ability to detect system failure with as little pain as possible is a pivotally important aspect of Forex strategy development. He explains why all quantitative strategies are bound to fail eventually:

Eventual system failure – what we can call system death – is an inevitable consequence of an edge developed on a finite amount of information on a market with potentially infinite variations.

Detecting System Failure

Fernandez made some particularly interesting points about the process of detecting potential system failure. In order to detect that a strategy no longer working, a trader will most likely have to go through a difficult losing period. 

Through extensive backtesting, walk-forward testing, and monte carlo simulations, a trader can establish parameters that describe a normal losing period for a given strategy. In order for that trader to determine system failure, they will have to trade through that normal losing period and then some.

The interesting concept that Fernandez brings up is that different strategies will have different conditions for those standard losing periods.

Low Win Ratio Strategies

Trading systems that are based on low winning percentages and high reward to risk ratios are expected to have long losing streaks. Therefore, it would take an exceptionally long losing streak to signal that system failure is possible.

Fernandez also adds that these types of strategies often rely on a few very profitable trades to make up for lots of small losses. That means that missing one key trade could result in a false signal that the system has failed.

High Win Ratio Strategies

Strategies based on high winning percentages and low reward to risk ratios pose the exact opposite problem. They experience much shorter losing streaks, so they are able to identify system failure much sooner.

Of course, the losses that these types of systems do take are often very large. While it might be a short string of losses that identifies the system failure, those losses are likely going to be incredibly painful.

Best Strategies for Detecting Failure

Fernandez concludes that the systems that provide the least painful means of detecting system failure are strategies with moderate winning percentages and reward to risk ratios.

He suggests that systems with reward to risk ratios around 1 to 1 and winning percentages just over 50% are able to signal failure in the best manner. These types of strategies can signal failure quickly, without crippling the buying power of an account.

Trading Frequency

The last topic that Fernandez mentions is the trading frequency of a strategy. Again, he suggests targeting a middle-of-the-road approach.

The fact that high-frequency trading systems can run through long losing streaks quickly might be seen as an advantage. Fernandez points out that this can be a double edge sword. Short term disruptions in market behavior can lead to false signals of system failure. 

 

Filed Under: Test your concepts historically Tagged With: backtesting, risk reward, system failure, walk forward, winning percentage

Research Plan

January 17, 2013 by Shaun Overton Leave a Comment

Creating a to-do list sounds boring and bureaucratic. It reminds me of the trading coaches that insist on keeping trade journals. BORING!

On the other hand, journals are important. They force the trader to reflect on the thinking behind an action.

And… I’m prone to rabbit trails and the like. A known plan with a checklist would keep me organized and thorough. So, it’s with some regret that I’m forcing myself to build a research plan.

Rabbit standing

I don’t want to end up following this guy’s lead

The step by step plan for analyzing my strategy

I mentioned in the last post that the strategy’s time frame will be the M1 chart. The current data under study uses EURUSD prices for the year 2011. Whenever the strategy is ready to walk forward, I’ll test it on all of 2012.

Now that most of the ideas came in (thanks to everyone for all of your emails and blog comments), I’ve made a list of things to try.

Before I get carried away with a new idea, I have to check off old ideas from the list. Doing so will keep my efforts disciplined and focused.

  1. Visualize the problem. This is what I started to do in the group forex trading strategy post. The next blog post in the series will go a step further and look at individual segments of the SMA/price curve.
  2. Evaluate range bound methods for scaling into a trade.
  3. Consider reversing strategies that lose dependably since I’m not including trading costs in the test. I.e., I don’t have to worry about overtrading being the cause of the loss
  4. Add filters to the most promising candidates
  5. Walk forward to 2012 data

Filters

Many of the suggestions that came centered on adding filters. I appreciate everyone’s feedback and for really thinking through the problem.

My personal thoughts are to focus on money management as a technique for improving a strategy. I’m going to leave filters as the final option as a way to potentially polish a mostly complete strategy.

Step 2 is multi layered. The items that I laid out are to scale in:

  • aggressively up to a certain, predefined threshold
  • slowly up to a threshold
  • slowly with a peak in the middle, then taper off the size of new trades. Think of it like a bell curve. The sweet spot should be in the middle of my graphic at the inflection point. (a hat tip to Mark Chapman for sparking that idea).

Writing this information out made me realize that I still feel like I’m guessing which types of strategies may work. So, I’m going to head back to step 1 to visualize the problem better. I’ll start with taking trades immediately on price crossing the moving average. I will then systematically record how performance and the number of trades varies as I get farther from the MA.

Although it’s not quite a strategy at this stage, the goal will be to identify regions under the curve that present better opportunities than others.

After-thoughts

This series eventually led to a profitable trading strategy. If you’d like to read through the journey, then I suggest reading the articles sequentially

The initial strategy idea
Selecting an appropriate time frame
A research plan
An annoying surprise in the initial backtests
An attempt at range trading
Range trading results
The moving average envelope scalper

Filed Under: Trading strategy ideas Tagged With: eurusd, forex, money management, trading strategy, walk forward

FREE trading strategies by email

Trending

Sorry. No data so far.

Archives

  • Dominari
  • How does the forex market work?
  • Indicators
  • MetaTrader Tips
  • MQL (for nerds)
  • NinjaTrader Tips
  • Pilum
  • QB Pro
  • Stop losing money
  • Test your concepts historically
  • Trading strategy ideas
  • Uncategorized
  • What's happening in the current markets?

Translation


Free Trading Strategies

Privacy PolicyRisk Disclosure

Copyright © 2022 OneStepRemoved.com, Inc. All Rights Reserved.