Algorithmic and Mechanical Forex Strategies | OneStepRemoved

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

Understanding Overbought and Oversold

February 26, 2015 by Richard Krivo Leave a Comment

If you are cooking something and you check on it and you see that it is “overdone” or “overcooked”, what is your immediate reaction?  Exactly.  You take the dish out of the oven.  Remove it from what caused its current overdone state and the sooner the better.

Too late for our chicken dinner below…

burned

 

What if your car’s engine is “overheated”?  Same deal…you do what it takes to get the engine cooled down.  Immediately stop doing what caused the engine to become overheated in the first place.

overheat

 

Given these natural reactions, it is easy to see why the initial and almost immediate move by many newer traders to an “overbought” or “oversold” trading scenario is to do the opposite in that case as well.

They reason that since many buy (long) orders moved price up and pushed the indicator into overbought territory, we must do the opposite and take a short (sell) position.  Conversely, if many sell orders caused the price to drop and move into oversold territory we much begin to take long positions.  It’s almost as though they expect price to snap back like a rubber band when it reaches these overextended zones.

Well…what is instinctively the proper reaction for chicken dinners and car engines is not necessarily the proper reaction when trading.

It is important to remember that when an indicator goes into the Overbought/Oversold areas, it can remain there for quite some time.  Just because the RSI or Stochastics indicator reads overbought for example, does not mean that price action on the pair is like a tightly compressed spring that is going to immediately snap back toward the Oversold area.

Let’s take a look at a historical Daily chart of the NZDJPY pair below for an example of this…

overbought chart

Notice on this chart that when Slow Stochastics went above 80 (in the red rectangle) into the overbought area, price continued to go up for another 780+ pips and Stochastics stayed overbought the entire time.  Clearly a trader who went short when it first when into overbought territory would have missed out on a great move.  They also would have gotten stopped out of their short position very quickly.

To see an example of where price retreats  when Slow Stochastics goes into overbought territory we need to look no further than the area labeled “A” on the chart.  In this case the candlesticks around “A”, dojis, spinning tops, shooting star and a hammer, indicate the potential for a pullback.

The point to be made is that either scenario can play out so don’t have a knee jerk reaction to the overbought and oversold areas of an indicator.

Remember…

Only take entry signals from an indicator that are in the direction of the longer term trend.

For example, if the trend has been strong and prolonged to the upside, it stands to reason that the indicator will be in overbought territory since it reflects the bullish push of price action.  To take a short position at that point would to trade against the trend and that would be introducing more risk into the trade.

Good trading,

Richard Krivo

RKrivoFX@gmail.com

@RKrivoFX

Filed Under: Uncategorized Tagged With: doji, hammer, NZDJPY, overbought, oversold, shooting star, short, Stochastics, trend

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

Support and Resistance Metric

September 17, 2013 by Timothy Lewkow 2 Comments

Converting back of the envelope ideas to trading algorithms is extremely challenging, but requires significant attention. This could be the single item that makes your system great. In this post, I suggest a way to find more defined support and resistance metric using limit order books.

Creating a Order Book Metric

To start, I want to create a frozen moment in time where two order books appear as in the following picture. For the sake of this example, I assume other signals have detected a $20.00 resistance level.

Support Resistance Metric Limit Order Book Comparison

Figure 1: Comparison of two limit order books during a suspected $20.00 resistance level.

Blue represents the limit bid and orange the limit ask. The order book on the left suggests strong resistance at 20, while the order book on the right suggests weakness . If you’re not convinced, see my post on the support and resistance in the limit order book.

The idea above is great in theory. How can you quantify the above two situations so that it’s actually useful? Otherwise, it’s just another fluff technical analysis piece with no real substance.

A successful method applied to Figure 1 should determined if a short position should be entered at $20.00 (left) or not (right).

The first of two decisions that you must make is how far to look into the order book — a value I will call N. The above two order books have N = 4 because each side of the book contains orders at 4 different price levels.

Of course this will depend on your access to data. However, you might also find through back testing that increasing N provides no useful information.

The next decision you have to make is how to weigh the volume in the order book.

You might be foolish to think that each level of the order book is created equally.

For simplicity, I am going to describe a linear weighting system where ticks closer to the price midpoint are given more weight. Referring to the first order book example, N=4 implies we need four weights on the ask side. My system has weights that satisfy the following conditions:

  • w1 – corresponds to $19.99
  • w2 – corresponds to $20.00
  • w3 – corresponds to $20.01
  • w4 – corresponds to $20.02
  • w1+w2+w3+w4 = 1
  • w1 > w2 > w3 > w4

These weights essentially alter the volume in the order book so that overcoming the level of resistance is a more pronounced event. Here’s how you can choose them for a linear case.

  • w1 = N = 4
  • w2 = (N-1) = 3
  • w3 = (N-2) = 2
  • w4 = (N-3) = 1
  • total = w1+w2 + w3 + w4 = 10

Through a process of normalization, the final weights are found as follows

  • w1 = N/total = 4/10 = .4 = 40%
  • w2 = (N-1)/total = 3/10 = .3 = 30%
  • w3 = (N-2)/total = 2/10 = .2 = 20%
  • w4 = (N-3)/total = 1/10 = .1 = 10%

Notice that the whole system comes by simply defining N, thus is easy to generalize and back test in your trading system.

The next step is to compute the average weighted price that would have to be paid if a market buyers chooses to pass the level of resistance. Again, I will refer to figure 1 on the ask side of the market. This will show the difference between a strong level of $20.00 resistance (left ask book) and a weak level of resistance (right ask book)

Support Resistance Metric Limit Order Book Comparison

Figure 1 repeated

Average price (left ask book) : $19.99*2+$20.00*8+$20.01*4+$20.02*5/19 = 20.0063

Average weighted price (left ask book) : $19.99*2*w1+$20.00*8*w2+$20.01*4*w3+$20.02*5*w4/(19) = 20.0022

Average price (right ask book) : $19.99*2+$20.00*8+$20.01*1+$20.02*1/12 = 20.0008

Average weighted price (right ask book) : $19.99*2*w1+$20.00*8*w2+$20.01*1*w3+$20.02*1*w4/(12) = 19.9989

From the weighting system, you can see that a assumed resistance of $20.00 is passed by only paying an average (weighted) price per share of $19.998 during a time of weak resistance.

The weighted average price shows more defined support and resistance levels

Generating Signals

Finally, to generate a solid metric, I considered the percent movement a stock would have to take to move past a weighted average price. For example:

Left ask book (strong resistance) : 100*(current price – average weighted price)/current price = 0.11%

Right ask book (weak resistance) : 100*(current price – average weighted price)/current price = 0.094%

My rule is set so that if the current price must move over 0.10% weighted average order book price (for a given value of N) then the resistance level is strong. Less that 0.10% makes me think the resistance is weak, and would signal for me to not initiate a short position.

Filed Under: Test your concepts historically, Trading strategy ideas Tagged With: average price, backtest, limit order, long, order book, resistance, short, signal, support, volume

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 © 2023 OneStepRemoved.com, Inc. All Rights Reserved.