Algorithmic and Mechanical Forex Strategies | OneStepRemoved

  • +1 (817) 210-4019
  • Articles
  • Sophisticated Web Sites
  • Automated Trading
  • Free Expert Advisors
  • Testimonials
  • Contact

Trading with the Commodity Channel Index

September 14, 2016 by Lior Alkalay 4 Comments

When trading, one of the most important pieces of information to have is the ability to identify momentum—when it begins and when it ends. It can help you plan your next trade and to ensure that that trade is successful. It is in the process of charting momentum that the Commodity Channel Index is especially effective, and that is regardless whether you are trading commodities, stocks or Forex.

The rationale behind the Commodity Channel Index or CCI is that it is an oscillator that measures the deviation from the simple moving average over the period. Just like most oscillators, it has an overbought level and an oversold.

In theory, using the CCI is similar to reading a Relative Strength Indicator (RSI). If the CCI is relatively high then the pair is overbought and when it is relatively low, the pair is oversold. In practice, however, using the CCI is a bit more complicated than the RSI. Unless the CCI is calibrated correctly it is practically worthless in identifying momentum cycles. Moreover, without correct calibration, it can generate plenty of false signals. But if you calibrated the CCI well it is an extremely efficient and powerful tool.

Commodity Channel Index: Calibration

The first step in calibrating the CCI is to identify when the current cycle began. This will help us decide the right period in which to run the CCI. In order to identify the beginning of the current cycle we can use Fibonacci Time Zones, which will give us an accurate measure.

For example, when we look at the Fibonacci Time Zones in the weekly chart below, we can conclude that the current cycle started 36 weeks ago. The rule of thumb is to divide the total period by three to give the average a bit more sensitivity. In the example below, it will be 36/3=12 weeks. That is the average the CCI should run on.

The reason we use Fibonacci Time Zones to calibrate the CCI is because the cycle’s length changes from wave to wave as they become longer and consequently the relevant average changes. Through the Fibonacci Time Zones, we can estimate with some degree of confidence when the cycle started.

Commodity Channel Index

Analysing the CCI

Once the CCI is calibrated, the rest is simple. The CCI, as previously mentioned, measures overbought and oversold levels. But rather than just looking at relative highs of the index we need to look at its behavior.

For example, in the Gold chart below, we can see that the CCI is converging with the price movement. That is a clear sign that bullish momentum is fading. If we take it a step further and continue our trend line all the way to the bottom, we can conclude another thing; that is that the pair, in this case XAU/USD, has already peaked and is heading lower in a bearish momentum.

Commodity Channel Index

Another way to chart the momentum is by examining the CCI behavior between the Fibonacci Time Zones. Notice that the CCI has a tendency to bottom out when the cycle ends and then rise. We can use that to ride on a rebound. There are cases, especially on a long term bullish trend, that we can get the exact opposite effect, i.e., the CCI peaks every time a Fibonacci Time Zone ends. The idea is to observe the pattern and then use it to your advantage.

Of course, as I’ve said in the past, oscillators should always be used alongside other indicators to get the full picture, and the Commodity Price Channel is no different. As usual in trading, there are no guarantees, but certainly the well calibrated CCI can provide a very coherent picture of where a pair’s momentum is headed, north or south.

Filed Under: Trading strategy ideas Tagged With: CCI, Fibonacci, gold, indicator

Things to Know Before Trading Silver

August 8, 2016 by Lior Alkalay 3 Comments

If you think Silver trading is almost identical to Gold trading, you are wrong. But if you think Silver is utterly different you are wrong, as well. Confused? Don’t be. Trading Silver has a lot of similarities to trading Gold but there are two key dimensions that impact the way Silver behaves in relation to Gold—volatility and the Gold-Silver ratio.

Trading Silver: Volatility

Below is a comparison of Gold and Silver volatility levels. It’s hard not to notice that Silver is substantially more volatile than Gold. The reason for that is because liquidity in Silver futures across the exchanges is substantially lower than Gold futures. This, of course, means that smaller amounts (albeit still in the billions) can move the price of Silver much more than Gold. As a trader you should accordingly adjust your strategy to higher volatility.

Trading Silver

In practice, Silver’s higher level of volatility first and foremost has an implication on stop losses. Because higher volatility tends to trigger more stop losses it means more margin of safety is needed when you place your stop loss. In other words,if you are trading silver, you have to place your stop loss a little further to make sure a sudden burst of volatility won’t throw you off the trade only to later hit your market. Of course, this also means you might reconsider certain trades, because if your stop loss is now further from your entry but your limit stays where it is your risk reward ratio is now lower and that could mean your trade is not necessarily worth it.

The second noticeable impact of higher Silver volatility is the manner in which Silver trends behave. Both Gold and Silver have a tendency to move in bursts of momentum but in Silver, the bursts tend to be stronger because of the higher volatility. As can be seen in the example below, both Gold and Silver eventually gains more or less the same percentages. But while Gold’s ascent was more gradual, Silver lagged Gold only to catch up with it later, in a fraction of the time and with a strong burst. This, of course, can be of great value for the Silver trader, especially one who can exploit such opportunities to make a rather quick gain from Silver catching up with Gold.

trading silver

Gold-Silver Ratio

Perhaps one of the most important ratios in the commodity space. The ratio, as its name implies, measures the price ratio between Gold and Silver. In other words, how much Silver is Gold worth? Why is that ratio useful? Because the ratio between Gold’s price and Silver’s price moves in cycles (see chart below).

When the ratio is at cyclical lows Silver is relatively cheap compared to Gold. In a bullish run it usually means that Silver’s price has more upside and will therefore outperform Gold. The same goes for a bearish trend. When the ratio is at cyclical highs then Silver will underperform Gold, both on the way up and on the way down. Therefore, watching the Gold-Silver price ratio allows you to gauge the potential momentum w

Trading Silver

In practice, this means you can expect Silver to outperform Gold when the Gold-Silver ratio is at cyclical highs. A classic example occurred in 2011 when as the Gold-Silver chart was at record lows (see above) which resulted in Silver outperforming Gold on the way up (see below). As the ratio gradually moved into cyclical highs, Silver started to underperform Gold again.

Trading Silver

The Bottom Line

Sometimes, Silver just moves too high too fast. When that happens it’s better to bail out before the burst. On the other hand, sometimes Silver lags, so much so that you have to ask is it worth riding on volatility to catch up? The key to trading Silver is understanding its similarities with Gold but exploiting the differences between the two.

Filed Under: What's happening in the current markets? Tagged With: correlation, gold, gold-silver ratio, silver, trend

Why the Gold Silver Ratio is Worth Watching

July 19, 2016 by Lior Alkalay 1 Comment

There are many ratios in the trading world that are worth watching. But when it comes to trading precious metals there is one key ratio that everyone must know and should watch. That, of course, is the Gold Silver ratio which is essentially the price of Gold divided by the price of silver. You might be asking yourself what insights one could possible glean with such a ratio? The answer is potentially very valuable insights.

What the Gold Silver Ratio Means

On the surface, Gold and Silver should be identical, from a fundamental standpoint. They are both precious metals which investors buy as a hedge against fear. But, of course, that explanation just barely scratches the surface. When we dive a bit deeper into the fundamental nature of Gold demand vs Silver the difference becomes more apparent.

Gold, as its reputation suggests, is a safe haven tool primarily driven by investments. Investments in Gold are often driven by fear and risk aversion (which are two sides the same coin). Thus, we can attribute most of Gold’s price fluctuations to those sentiments.

Silver demand, on the other hand, is  driven both by safe haven demand by investments but also  by Industrial usage.

That difference creates a very interesting dynamic. When investors’ fears mount, demand for Gold tends to be stronger and the ratio tends to rise. When fears fade then investors believe industrial output will rise. That, of course, tends to benefit Silver and thus the ratio falls.

The Gold Silver Ratio as an Indicator

Examining the Gold Silver ratio chart below, a trader is able to take the pulse of fear levels. If the ratio is rising it may signal an escalation in investors’ fears. Consequently, that could signal that Gold demand is turning stronger. If the ratio is falling, fear is dissipating and Gold is turning weaker.

How is this useful in practice?

If you’re holding a long Gold position and the ratio is falling, you’re essentially riding a dying horse and Silver would be the better place to be. On the other hand, if the ratio is on the rise and you’re buying Gold, that’s positive reassurance to own Gold over Silver.

Of course, for Silver, the effects of the ratio would be the exact opposite. A rising ratio is an indication of weaker Silver demand compared to Gold.

It Gets Complicated

But besides gauging which precious metal is strengthening at the expense of the other, there’s one other dimension. Once again, the Gold Silver ratio chart sheds some light on this useful ratio.

The Gold Silver ratio has cycles. It has historical highs, where it tends to top out and fall, and it has historical lows. If the ratio is near its highs, then it might be a good idea to move into trading Silver. If the ratio is near its historical lows, it might be time to switch from trading Silver to trading Gold.

Gold silver ratio

Trading the Gold Silver Ratio

This might come as a surprise but the Gold Silver ratio is not just an indicator it’s also tradable. Even better, it’s actually rather easy to trade. Often, the ratio has simple and very distinct patterns that can follow a simple trend line. If you believe the ratio will trend higher, then you can buy Gold and short Silver with identical lot sizes. That way you will gain as the ratio rises.

For shorting the index one should do the opposite; short Gold and buy Silver with the same lot sizes.

For example, take a look at Point A from October of 2015. The ratio gained more than 10%, rising from 71, to where the trend line is above 80; that’s more than a 10% gain. Compare that to trading the EUR/USD; a 10% gain in the pair would roughly equal 1,000 pips.

Naturally, this simplicity doesn’t come cheap. First, you have to rely primarily on trend lines for short to mid-term trends (and you know what I think about relying too heavily on trend lines).  Of course, you can use the historical lows and highs to figure out what’s coming next but that means opportunities might be fewer. Second, this is margin heavy, since you essentially need to hold twice the margin, aka two positions in opposite directions.

Put another way, trading the Gold Silver ratio can be simple when it’s going right, but consider this could easily go wrong.

Gold Silver ratio

How to get started

If you plan to actually trade the Gold Silver ratio, first get used to using it as an indicator. Then, once you have a better sense of the way it behaves, you can use your own discretion as to whether or not it’s worth trading. If you’re thinking about using the ratio solely as an indicator, let me throw this out there: Don’t entirely rule out trading it. Occasionally, when the ratio is at a multi-year low or high, there can be a very nice opportunity arising that you might not want to miss. But the fact is, either way, as an indicator or as a tradable asset, the Gold Silver ratio is always worth watching

Filed Under: Trading strategy ideas Tagged With: gold, pairs trading gold silver, ratio, silver

Trading Lessons from the Latest Gold Spike

February 19, 2016 by Lior Alkalay 10 Comments

After a relatively long period of calm, Gold has come back from the dead. Half way through February, Gold prices have spiked by more than 12%. This, of course, has got some traders scratching their head, wondering where the heck the spike came from… as if Gold moves materialize out of thin air.

Well, Gold moves don’t just “happen.” In fact, the latest spike in Gold price provides some powerful trading lessons on trading Gold.

Charting Gold Volatility with MT4

Before we jump into the lessons to be learned let’s first focus on the cycles of Gold. That should help explain the latest Gold Spike. Despite what you may have heard, Gold does have cycles. Surprisingly, the cycles are not in the price itself but in the level of volatility. In the past, I expanded on the advanced use of derivatives to predict an upcoming Gold move and direction. But the lesson here is far simpler.

In the weekly Gold chart below, we have measured Gold’s volatility through Standard Deviation (or StdDev), which is available in MetaTrader.

As one can see, Gold’s StdDev is remarkably simple to analyze. Every time the StdDev falls to 20 it jumps back up. And every time Gold’s StdDev jumps to 80 it falls down, back to the 20 low. The only exceptions were two extreme cases when the StdDev reached 145.

Moreover, we can see that if StdDev has hit lows more than once the spike of volatility higher is almost certain.

Gold

Source: MT4

First Trading Lesson

Of course, our StdDev analysis is not unique to the latest spike. But what can we learn? The first interesting lesson is that volatility spikes tend to concentrate around resistance/support levels. In our case, that is the 1,050 support, aka Point A. That means that Gold opportunities tend to occur around support and resistance levels. Now, it may seem an obvious conclusion but here is what it actually means:

When you have a support or resistance level and StdDev is at 20 that’s the ideal time for entry. You will have both textbook support and resistance levels working smoothly.  Then you’ll know that a strong momentum is coming.

Second Lesson

The second lesson is a simple but important one. A spike in Gold volatility does not necessarily mean a break of support and resistance levels. When technicals suggest that the support level will hold look at the StdDev. If the StdDev is at 20 that’s good; it re-enforces that simple fact that the support level will hold.

Third Lesson

The third lesson, which combines the first two, is perhaps the most interesting. It is the understanding that one jump in StdDev is not equal to one move. Let me elaborate; say StdDev has hit the 20 low near the 1,050 support. Meanwhile, Gold prices have spiked but StdDev hasn’t yet reached the 80 high. That means that volatility is set to rise but it doesn’t necessarily mean that Gold will keep moving in the same direction.

Rather, it means it will just move with a strong momentum. In the case above we can see Gold has hit the upper price channel resistance at Point B. But StdDev suggests volatility still hasn’t been maximized. And that means that the rise in volatility, next time, could come in the form of a short.

What Did We Learn?

So if we take our three lessons and try to summarize them, what did we learn? We learned that when StdDev is at its 20 lows it’s the best time to trade Gold. That’s because it guarantees that you will get a strong price momentum and it validates your technical analysis on Gold.

Filed Under: What's happening in the current markets? Tagged With: gold, resistance, standard deviation, support

Major Portfolio Update

November 1, 2015 by Shaun Overton 6 Comments

We ended the month in the black with a 0.74% return. I realize that nobody is jumping up and down with that kind of performance, but I’m honestly very excited to see the change.

At the beginning of October, I made a substantial change to the portfolio. Previously I attempted to pick pairs that were doing well. This approach was something of a mixed bag. While some periods of performance were quite nice, such as June of this year, the month of August was pretty harsh on the portfolio. I also didn’t like that the pair selection process was still very subjective.

The QB Pro strategy, like any strategy, makes its most important trading decisions when it selects its portfolio. The strategy is not one that can make money in any given environment. Instead, it requires careful selection of instruments in order to give itself the best possible opportunity to earn a profit.

QB Pro equity curve October 2015

The equity curve for the month of October 2015.

Based on about 100 hours of research with Jingwei back in September, I’ve been able to reduce the amount of discretion when selecting portfolio instruments. For example, the mega-monster performance from August 2014-March 2015 was driven exclusively by the strength of the US dollar.

As anyone who buys gasoline for their car knows, the trend shifted this year out of currencies and into commodities. Specifically, commodities have taken a real beating. China’s economy is sputtering, the US like it’s unable to raise interest rates and most industries suffer from serious gluts. Oil production in the US is widely rumored to possess a severe over-capacity, as evidenced by all the junk-debt ratings on US drillers. Gold mining stocks around the world have been the red-headed stepchild of financial markets, trading at PE ratios as low as 1.0.

That weakness spread to commodity currencies, even major currencies like AUD, CAD and NZD. As I ran backtests using a portfolios of those currencies and their crosses, I noticed that the equity curve more less marched straight up through the summer. More importantly, that basket of pairs benefited from the Chinese devaluation, whereas my custom basket took a step drawdown.

I’m expecting more problems of out both China and the US through the rest of the year. Although China managed to settle down after the summer, the problems plaguing it are anything but fixed. Recent bankruptcies and bailout of state owned firms point to more cockroaches. And, you know the rule about cockroaches. Where there’s one, there’s 10 more. I expect more Chinese devaluation to follow.

QB Pro lifetime Oct. 2015

Lifetime equity curve of QB Pro’s high-risk version.

The commodity currency exposure is an indirect, systematic play on this expectation. The portfolio has done well in the current environment and, given that I don’t expect any improvement at all in China, should continue to do well.

The other variable is the Fed. I had the rather unfortunate luck of launching the portfolio just in time for a Fed governor to cast doubt on any US interest rate hikes this year. The change got off on the wrong foot. But QB Pro didn’t just stem the losses. It bounced off the equity low and marched upward in nearly a straight line for the rest of the month.

The Fed meeting in October forced the governors to pretend as though a 2015 rate hike is on the table. There’s always the chance that the Fed might hike rates just to prove a point. They’ve been talking about this for 9 months now. The futures market at one point put the odds somewhere near 67% for a 2015 rate hike. Prior to the meeting, those expectations fell under 25%, then jumped back to around 50%.

Even if the Fed did raise rates, I see an impossibly low probability of a sustained program of rate hikes. The data looks like a car sputtering on fumes. There’s deflation everywhere expect for the financial markets and beef, where “investors” have been encouraged to park their money in junk debt in exchange for a pitiful 4-5% yield. The economy is sick. The idea of consumers breaking out their wallets and spending like the drunken sailors of 2007 is laughable.

My expectation for the next 6-24 months is that the Fed slowly retreats from talk of hiking rates and into another round of QE. That will mark the final admission that the Keynesian policies aren’t working and where the markets lose all confidence in central banks.

A confidence collapse would slam currency markets, but it should exercise the most severe impact on the commodity currencies that my traders and I focus on with QB Pro. The deflation would press prices even further to the downside, which provides ideal conditions for this type of strategy.

Open slots for new traders

I’m hosting a webinar on November 12 to teach you as much as I can about algorithmic trading. The webinar is going to cover in detail the QB Pro strategy, especially the SB score. I’m also planning to discuss the Fed and Chinese situation in more detail, as these are the two most important factors for us to consider when applying strategies. Make sure to sign up to the newsletter to be notified when I start accepting registrations. This is also open to traders in the United States, which is a big change from previous options!

If you’re interested in trading the QB Pro strategy in your own account, attending the webinar will be mandatory. And as a thank you for spending 45 minutes of your day learning from me, you’ll be given a strong financial incentive to trade QB Pro. More details to come soon, so make sure that you subscribe to the newsletter now before you forget.

Filed Under: QB Pro Tagged With: algorithmic trading, AUD, CAD, China, commodities, Federal Reserve, gold, NZD, oil, QE

Spotting Pivots in Gold Prices

September 15, 2015 by Lior Alkalay 1 Comment

Gold is hard to predict. Often, when it seems to be gearing up to a bearish momentum, it stops and flips. It also often looks highly bullish only to melt down and carry the bulls with it. Of course, this kind of uncertainty is an inherent part of trading, especially when it comes to gold. This means you have to invest more effort in spotting the possible breakouts and pivots that enable us to plan our trades. In this article, we will focus on how derivatives can help you discover accurate pivots in gold prices.

Gold Prices Through Derivatives

The real problem with gold is that it can fall or rise quickly, without warning. That makes it hard to spot opportunities for those who trade it as though it’s a forex pair. However, those out-of-the-blue rapid movements are, in many cases, closely tied to the derivatives market, where most of the gold trade takes place just like any other commodity. In one of my previous articles about implied volatility, I demonstrated how derivatives can help you monitor volatility relatively easily. But what about pivots? You guessed it: derivatives – or, more specifically, option prices on the CME – could be rather handy in that respect, too. How? By showing us at what price most bets are concentrated.

Using Option Analytics on Gold

Below the CME Option Analytics illustrates the puts (short) and calls (long) options open on gold at any price. The orange columns are puts, and the blue ones are calls – in other words, sellers versus buyers. The vertical red line in the middle is the current price. Now, what does this mean and how the hell can it help us spot pivots? Very simple. All the orange columns (puts) on the left of the red line (current price) are short bets waiting for the price to fall, while all the blue columns (calls) are long bets waiting for the price to fall.

As can be seen on the 1,100 price, the short bets are overwhelmingly higher than the long bets. This leads to a rather straightforward conclusion: if the price of gold crosses below the 1,100 level, it will immediately trigger a pile of short options and trigger a strong bearish wave, marking a very important pivot we should watch from. If you are long on gold, a break below 1,100 might be a sign to bail out, while if you are a short seller, you might want to wait for gold to cross below 1,100 for bearish momentum to accelerate.

Gold

CME Group

Of course, this is a mirror of what might happen on the right side of our price, where at 1,150 there are piles of call options waiting for gold to rise above. As you can see, this is way lower than the pile of puts below 1,100 but it’s still significant and makes our upper pivot.

On the left side of the red line (options below our current price), if the number of call options was much higher than the puts – lots of bullish bets at 1,100 – it would pin down 1,100 as a strong support zone. Of course, once again dynamics on the left side (above current price) would be the mirror of this. This so-called screen is essentially the CME order book – just like when you look at your own account on the buy and sell orders, this illustrates the buy and sell options of the entire CME exchange on gold and for us. This means we can see where the broader market places its bets and sees pivots, and plan our next gold trade much better.

 

Filed Under: Uncategorized Tagged With: gold, implied volatility

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

Correlation vs. Cointegration

May 6, 2013 by Shaun Overton Leave a Comment

Correlation and cointegration are two regression based concepts that are commonly misused by the trading community. Complex in their formulation, both are inter related and are used to calculate the relationships between two or more products (ie commodities, forex, stock prices) over a specific time period.

Correlation

A value of +1 (positive correlation) or -1 (negative correlation) is assigned based on the how efficiently the two prices react to each other. Correlation identifies pairs that move in either tandem or opposing directions.

A good example of a long term correlation pairing is that of the EURUSD and the USDCHF crosses, which trade in a similar direction. On the other side of the coin, the EURGBP and the AUDNZD trade in opposing directions. They show a negative correlation of -0.81.

Although this figure indicates that the crosses moved against each other, there is a slight degree of uncertainty over the long term sustainability of this negative result. Professional traders commonly set the entry benchmark for pairs above or below 0.9 or -0.9.

Correlation does have a significant drawback, which can greatly affect profitability. Although two pairs may be correlated, they are still not in complete unison, which can cause a slight drift in the prices. In the case of the EURGBP and the AUDNZD, it is a drift -0.19.

Read the post on forex correlation for more details on the topic.

Correlation

Image credit: Vassia Atanassova
The left box shows a strong correlation. The middle shows a weak correlation. The far right shows an image with no correlation.

Cointegration

Cointegration analyses the movements in prices and identifies the degree to which two values are sensitive to the same mean or average price over a given time period. It doesn’t say anything about the direction that the pairs will move. Cointegration only measures whether or not the distance between them remains stable over time.

If we look at gold and silver, for example, we may find that they track a common average value. They may trade in opposite directions from day to day. At some unknown point in the future, they should revert back towards that average and hence they are cointegrated. Hedge funds commonly use this formula to program statistical arbitrage models to identify pairs to trade.

Another important factor to keep in mind is the look back period of the mean and standard deviation. In essence, if you make the look back value 700, then the regression channel will calculate what the average price is over 700 periods. This can be too inefficient and will limit the sensitivity to changes in the market dynamic.

On the other hand, if you set a short look back period, then it will cause a whipsaw effect and will be far too sensitive. It is important to get a balanced look back within the range of 200-350.

Gold and sliver chart show correlation and cointegration

Gold / Silver Example

• Top Section: Standard Deviation and Linear Regression
• Middle Section: Relative Performance Gold (dark blue) and Silver (light/ turquoise blue)
• Bottom Section: Gold Daily Chart and Time Line

The above chart highlights the overall correlation of Gold and Silver and the degree to which breakouts could trigger trade opportunities. I have circled a number of different cointegration scenarios and referenced these on the second section with P1, P2, P3 and P4 labels.

Silver Spike – March

A significant spike in the price of Silver in March sent the linear regression value below the lower standard deviation channel of -2.0. To capitalize on the significant discrepancy in prices, the trader would have looked at shorting silver and going long gold. Performance wise, this would have resulted in an overall profit as silver weakened heavily, crossing below gold in May.

Silver Oversold – July

The silver price continues to weaken on a relative level to gold. In June and July, the regression value passes above the top standard deviation channel, indicating that silver is oversold and the price will have to revert back to its mean. The trader decides to open a long position in silver and short gold. As forecast, it returns to its mean and the gap between both spot prices closes quickly.

Silver Overshoots – December

Once again the silver price overshoots gold. This sets up a long gold, short silver opportunity. On a performance level, the trader would capitalize on
the spread and profit from the position.

Silver Selloff – April

Puncturing the second standard deviation channel, the gold price stabilises whilst silver weakens heavily. This has now supplied the trader with a long
silver, short gold opportunity.

Filed Under: Trading strategy ideas Tagged With: cointegration, correlation, gold, silver

Buy and Hold Gold

December 11, 2012 by Shaun Overton Leave a Comment

I came across a paper entitled A Quantitative Approach to Tactical Asset Allocation by Mebane Faber. This paper appears to have been extremely popular over the years. Reading through the contents and reviewing the charts, I loudly wondered if the strategy might apply to gold.

Rules for buying gold

The idea is very simple. Taken directly from the paper, the rules are:

BUY RULE
Buy when monthly price > 10-month SMA.

SELL RULE
Sell and move to cash when monthly price < 10-month SMA.

1. All entry and exit prices are on the day of the signal at the close. The model is only
updated once a month on the last day of the month. Price fluctuations during the rest of
the month are ignored.
2. All data series are total return series including dividends, updated monthly.
3. Cash returns are estimated with 90-day Treasury bills, and margin rates (for leveraged
models to be discussed later) are estimated with the broker call rate.
4. Taxes, commissions, and slippage are excluded.

Test results

The tests were done using Kinetick’s free end of day data. The data extends from August 4, 1997 until December 10, 2012.

One thing which drives me crazy about NinjaTrader is that the percent return calculations are so opaque. The actual numbers used a clearly wrong. The buy and hold return for gold is easy to calculate. The 1997 price was about $350 an ounce. Today, gold trades near $1,700. The buy and hold return should be in the neighborhood of 385%. NinjaTrader claims that the return is somewhere near 150%. I’ve gone through the charts to confirm that the trades are correct. You can download the gold strategy for NinjaTrader and verify the trades for yourself.

The percent return metric is consistent within the platform, so luckily the exact numbers are unimportant. The only thing that really matters is whether or not the strategy returns a bigger number than the buy and hold approach.

Equity curve of buying and holding gold

A chart of gold’s daily equity curve, extending back to June 1997.

Equity curve of the gold trading strategy

The tactical gold strategy dramatically underperforms the buy and hold return.

Reverse gold strategy equity curve

Pursuing the opposite idea of buying on crosses underneath the SMA10 doesn’t help

The strategy severely underperforms the buy and hold return. The idea held in the paper itself is deeply flawed. Buy and hold is a silly concept. Most of the “returns” in the portfolio stem from long term inflation and the devaluing of the dollar. The prices of the securities rose because the dollar, which you can think of as the counter currency, declined enormously in value over this time period.

Additionally, the idea of the price crossing the moving average implies that the trend escapes the moving average. The MA, in effect, gets dragged along with the price. While this is true with a handful of monster trends, the way that price moves usually work is something along the lines of 10 steps forward, 9 steps backward. The results of the test indicate this.

If the proposed strategy returns less than buy and hold and the total buy and hold strategy returned 150%, then it stands to reason that the total buying return is trades taken by the strategy + trades not taken by the strategy. The test includes what are supposed to be trades not taken by the strategy – the reverse signals. Adding up the proposed strategy’s returns with the returns of the opposite signal only accounts for roughly one third (22% + 34%) of the 150% earned. Where did the rest of the money go?

Most of the move happens around the short term moving average. The majority of the move has already happened after the price to crosses and closes above the moving average. The instinct of many novice strategy developers is to move to intrabar signals. Intrabar trading ignores the basic problem; you cannot know whether or not the bar will close above the moving average.

Filed Under: NinjaTrader Tips, Trading strategy ideas Tagged With: gold, intrabar, ninjatrader, SMA, strategy

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

EnglishEnglish
中文(简体)中文(简体)
DeutschDeutsch
日本語日本語
Bahasa MelayuBahasa Melayu
PortuguêsPortuguês
EspañolEspañol
by Transposh - translation plugin for wordpress

Free Trading Strategies

Privacy PolicyRisk Disclosure

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