Algorithmic and Mechanical Forex Strategies | OneStepRemoved

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

How to Back Test if a Forex EA is Profitable

January 12, 2018 by Shaun Overton 1 Comment

So, you believe you have found a sound forex trading system or Expert Advisor (EA) and you are feeling ready to dip your toe in the water. It’s important not to rush in and instead take a step back to thoroughly test the strategy or EA through back testing.

Before we look at how to test if an Expert Advisor is profitable, first let’s look at what forex back testing actually is?

Forex back testing allows you to test the EA in order to see whether it actually does what it should do. Any forex trading system is completely useless if it doesn’t do what you expected it to do. Back testing uses historical data to enable you to see how the EA would have performed. By entering the historical data, you would be able to see which trades your EA would have recommended to you. This way you can check whether the EA is going to work for your chosen trading style and individual goals. Furthermore, this process allows you to understand in more depth how your EA works and to identify flaws in the system.

MetaTrader 4

Back testing is time consuming but it is worth it. It is important to back test in both a bull and bear market and to collect sufficient data so that you know how your EA will perform regardless of whether the market is rising or falling. Another point, is the more accurate the data you use, the more precise your back testing will be. Therefore, it is preferential to use accurate historical data rather than indicative data and also use a realistic level for slippage.

Forex back testing is an essential part of developing and using a forex trading system. However, it is important to keep in mind that the results your back testing give you are based on past performance, which is not necessarily indicative of future performance. Back testing will help you feel more confident about the ability of an EA, but it is important to remember that no amount of back testing can guarantee future profits.

Where can I back test?

MetaTrader 4 offers its users a Strategy Tester feature. This is simple to use and enables you to select the EA you installed from the Expert Advisor choices. For this you would need to have the MT4 platform. The most capable brokers offer their clients the MT4 platform. One such broker is Vantage FX, they are an award-winning forex ECN broker. Not only do they offer their clients MT4, but also some of the tightest spreads in the industry and unparalleled execution.

Filed Under: Uncategorized Tagged With: backtest

Working 8 days a week

December 6, 2016 by Shaun Overton 22 Comments

Reaching an all-time high in my equity curve means it’s time to buckle down and keep improving. My Dominari strategy has done very well over the past 7 months and especially this and last month.

Dominari Equity Curve December 6, 2016

Is the party going to continue?

I certainly expect so. Drawdowns are inevitable, but that’s part of trading. Short-term performance is exciting, but my ambitious goal is to turn my starting balance of €8,000 into €50,000 within the next 3 years. As of this writing, I’m at €9,323.

You’re probably wondering how a 16% profit leads me to extrapolate an annual return of nearly 100%. The answer is that I dramatically changed my leverage at the end of September… just in time for that ugly drawdown. If I was trading on my current leverage, the current live return would be around 40% (i.e., right on track to hit my goal).

What really counts is what I’ve really done. So far, I’m up €1,323 with another €40,677 to go by December 6, 2019.

The research for Dominari is effectively finished. It’s been slightly more than a year since I began researching the strategy. Although minor variations of Dominari popped up or came from traders copying my signals, none of them improved the long term outcomes.

One version that improved the risk profile was to trade with limit orders. The original blog post mentioned limit orders, but the variation placed them considerably further from the current market than what I tried previously. I also lacked a system for choosing settings appropriate to every pair, which I’ve more than likely resolved. The problem is that I have a million things on my to-do list and only 8 hours a day. You’ll see some of my top projects when you scroll down.

Pilum: The latest and greatest

Pilum is a strategy based on a statistical process that identifies momentum. One of the scary elements about most quantitative strategies is that most of them are mean-reverting. They buy when the price drops and sell when the price rises. The approach is favorable (i.e., profitable) in the long run, but it takes some psychological fortitude to trade.

Pilum is a major advancement because now I’ll have a strategy that should profit exactly when Dominari is most vulnerable to a drawdown.

dominari trade outcome histogramThe new strategy uses limit orders to enter the market. Something like 90% of these orders never execute. But when they do execute, I win 75% of the time. Additionally, my profile of winners to losers is very comfortable.

Most traders understand the ideas even if the statistical jargon is unfamiliar. Pilum’s biggest winner is larger than its biggest loss. The average winner is bigger than the average loser. And, it wins 77% of the time.

Pilum trade outcome histogram

So far, I’ve done a sort of piecemeal backtest using R. When I finish the Quantilator (see below), I’ll redo the backtest in a fully fledged trading platform. More than likely, I’ll use QuantConnect to test the strategy level approach.

Trading platforms drive me crazy! The biggest problem that I have as a trader is continuously reallocating capital across my portfolio. MetaTrader, NinjaTrader and the likes implicitly assume that I want to trade some percentage of my account balance on every trade. Either that, or that I trade fixed lots.

Trading that way is extremely inefficient. I’m trying to trade 40+ currencies, so I need to be able to decide which ones need the money for trading and which ones don’t have signals. Then, among the ones that do have signals, I need to dish out their allocations proportionately. The allocations aren’t the same for each instrument. If you know of any good FX platforms that meet this requirement, then let me know in the comments section.

Testing Pilum on its own is important. More important than the performance of Pilum is how that performance interacts with Dominari. That means taking the daily equity values of each currency. Does Dominari lose when Pilum wins and vice versa? Should I allocate capital 50-50 between the strategies or does one strategy deserve the lion’s share of the portfolio? Is one strategy so good that it should get all of the money?

The main concern with portfolio allocation is how it relates to leverage. Dominari historically make 96% annual returns, inclusive of trading costs. But, it’s also trading with leverage of roughly 19:1. It’s possible for markets to rip over stops and create significant losses.

USDCHF lost 40% of its value in one hour in January 2015. Say that the scenario was even more extreme and that nobody could place a trade during that time at any price. That 40% move is multiplied by the 19x leverage used. That’s a theoretical 800% loss; more than the money in the account.

Everyone loves leverage because they think of profits. Leveraging losses is a lot less exciting.

So, if you could earn 96% annual returns and only use 5:1 leverage, that is exponentially superior to earning 96% on 19:1 leverage. I need to compare the returns of Pilum to Dominari per unit of risk. That allows me to do cool things like

  • Minimize the negative variance of the returns
  • Increase absolute return
  • Dynamically increase/decrease strategy allocations if I find patterns in their interactions

It’s a lower tech way of averaging strategies, like the litte guy’s version of what Numerai is doing… except that I have to create all of the strategies myself.

Quantilator

I spent the last few months sending surveys to segments of my subscribers asking how I can better serve you. Articles about indicators are overwhelmingly my most popular content. The trouble with that content is that I can’t complete the research fast enough to keep up.

The most valuable thing I’ve learned from the developing algorithms for the past 11 years is my process of deciding whether or not an indicator offers predictive value.

Moving Scale

Say that you’re interested in gaps: do gaps predict future returns? What I normally do is code a gap indicator in R, implement my analysis methodology and give a verdict. My methodology is kind of like a system for building systems. Using my approach usually takes an hour for every new idea that comes along.

An hour is pretty short. An hour is REALLY short compared to when I didn’t have a research methodology. I used to waste months on junk strategies.

With Quantilator, I’ll be able to analyze anything in under 5 minutes. I’ll only have to follow 3 steps:

  1. Run a script in MT4 to export price data and indicator data
  2. Upload the exported data to Quantilator
  3. Analyze the results

This tool will be 100% free. I’m planning to go through the most popular indicators in MetaTrader to analyze whether or not they offer an edge. I’m building a library of small edges that can be combined into powerful strategies like Dominari and Pilum. And, in the spirit of open source, I plan to make that library available to you for free.

I’m writing this tool in Django, which is a Python framework for displaying web content. The initial version will do the analysis. I’m hoping to use this as an education tool. A bit of momentum can justify make it a fully fledged library with sample data, indicators and training videos and more.

Quantilator’s name comes from a key concept in my system analysis methodology; I break data into quantiles. These quantiles calculate average market returns for a given period of time. The quant in Quantilator refers to quantiles, but I really like the implied double entendre of making you a quant. After all, that is what I’m doing for you!

Update: The Quantilator is now freely available at http://q.onestepremoved.com/

Filed Under: Dominari, Indicators, Test your concepts historically Tagged With: backtest, metatrader, portfolio allocation, portfolio systems, python, quant, QuantConnect, quantile

Big change to Dominari

March 9, 2016 by Shaun Overton 24 Comments

I said it here and here and here. The biggest issue with my Dominari is trading costs. Things aren’t going to really take off until I do one of two things.

  1. Reduce the trading costs
  2. Make more money on each trade

I’ve been working on Dominari since around September or October of last year. After racking my brain for months, I more or less wrote off the idea of improving the trade profitability.

That suddenly changed last week on Friday after the market closed. The best reason to trade my own systems live is that the agony of underperforming forces creativity. The feeling reminds me a lot of Daymond John’s (the guy from Shark Tank) new book the Power of Broke. When life isn’t going your way, it’s the resourceful and creative who are best able to get to the top.

Nobody wants to feel broke or under extreme stress. As much as we hate those feelings, they’re often the strongest drivers of performance. That’s how I feel right now with Dominari. I’m so close to getting there and wasn’t sure how to fix that missing ingredient.

If it weren’t for that stress, I would not have had my simple but very powerful insight last Friday.

And please don’t laugh. The change is so dumb and obvious that you’re going to wonder what’s wrong with me. When you’re in the thick of designing a system, the ugly truth is that sometimes you get lost in the weeds. Or to use another botany metaphor, you only see the trees instead of the forest.

My key insight was to slightly modify the exit strategy to use limit orders, whereas previously I only exited based on the close of the bar. I noticed two repeated behaviors that finally beat me over the head enough that the point finally sank in.

The number of occasions where my trade closed in the optimal location seemed to be significantly outweighed by the amount of money left on the table. The key insight for me was realizing where to optimally place that limit order. And for those of you on my newsletter, it happens to be closely related to the Auto Take Profit that I’ve been talking about all week.

Backtest assumptions and results

My operating mantra when doing backtests is to minimize the number of assumptions. Spreads for retail traders have changed dramatically from 2008 to today. I remember working as a broker at FXCM when our typical spread on GBPCHF was something like 8-9 pips. I now routinely pay something like 2 pips. It’s impossible to model what happened in the middle without haphazardly guessing.

I find it far more convincing to analyze the raw signal, both on historical and recent market data, then to interpret whether trading costs are likely to be favorable in today’s markets. “Raw signal” is the ideal signal, one which assumes perfect execution, no slippage, no rollover, no spreads and no commissions. The natural result is that you’re overstating historical performance, but the benefit is that you have a very clear idea whether the core idea is a system capable of predicting the market with reasonable risks.

The total leverage employed in the portfolio is 7:1. If I have a $50,000 trading account and held a position in every currency pair in the portfolio, then the notional value of those trades would equal $350,000 (50k * 7).

Another key point is that I used a fixed position size of $12,500 per trade. The size of the trade never increases or decreases during the backtest, which allows me to isolate the impact of the raw signal without adding the variable of money management.

Here are my trade metrics with version 1 of Dominari. Click the images to view them in full size.

Version 1 backtest of Dominari

The first version of Dominari had a profit factor of 1.26.

After here’s the change with Dominari version 2.0.

My new version of Dominari increases the profit factor to 1.59 with a significantly lower drawdown.

My new version of Dominari increases the profit factor to 1.59 with a significantly lower drawdown.

My best case scenario was to hope that the profit factor would jump another 10 points or thereabouts, maybe stretching the profit factor to 1.35 or thereabouts. It’s incredibly exciting to see the edge over breakeven more than double (going from a $0.26 edge to a $0.59 cent edge).

What I’m most excited about is the skew in the returns. Most mean reversion systems look for an edge but are overwhelmed with the impact of losing trades. That was the case with version 1.

Skew of Dominari version 1

The largest losers outweighed the largest winners in version 1.

This new version of Dominari is the very first mean reversion strategy that I’ve ever developed where the winning tails (ie, the biggest winners) nearly equal the losing tails (the biggest losers). It’s almost always the opposite with mean reversion strategies. Said another way, the risk profile of the extreme outcomes significantly improved with version 2.

Fat tails in Dominari v2

The impact of the biggest winners is nearly identical to the biggest losers with version 2.

And the metric that most traders care about the most, drawdown, is wildly improved. Version 1 showed a drawdown of 5.72%. The new version is a fraction of that at 1.77%.

Out of sample backtest for Dominari version 2

The out of sample performance is nearly identical to the in sample performance, despite significantly different market conditions.

When I walked my test out of sample onto recent data, covering 2013-2015, the performance characteristics of version 2 are nearly identical to the in-sample test. The profit factor was identical at 1.59, and the max drawdown was 2.01% for 2013-2015.

Translating the theoretical into expected performance parameters

Again, those metrics above are in the ideal world of perfect execution and no trading costs. The real world performance will have lower returns and higher drawdowns. The advantage to having live trade data is that I can now make some kind of intelligent estimate of my expected trade accuracy and profit factor. Just how overstated are the idealized returns likely to be?

The process that I went through to calculate the expected profit factor in the real world is a 5 step process. I don’t think it’s going to make any sense if I try to write out the steps in conversational English. Instead, I’ve chosen to share a spreadsheet where you can view the step by step process for how extrapolating live trading data into expected performance with the new strategy. Click here to view the spreadsheet.

The expected profit factor for my live trading is expected to be between 1.29 to 1.39. The expected percent accuracy for live trades should jump from 62.55% to 70.8%.

The traders who will get first crack at the Total Access Apprenticeship are those are subscribed to the free newsletter. If you’re not signed up, make sure to fill in your email address in the orange box at the top right of this page.

Filed Under: Dominari, Test your concepts historically Tagged With: backtest, fat tails, GBPCHF, leverage, mean reversion, profit factor, skew

Monitoring my live trade execution

February 10, 2016 by Shaun Overton 29 Comments

Dominari’s biggest risk is its trading costs. In the midst of losing 6 days in a row, I found myself extremely concerned about Dominari’s performance. Did the signals go bad all of a sudden or is this a normal drawdown? Is Dominari losing because of trading costs?

I decided to start analyzing my FXCM account. Part of the nerves were driven by the fact that it took 2 weeks to setup the account. The compliance process took far longer than usual because I’m a former employee. Two weeks later, I turned on the account just in time to a) miss the biggest equity growth and b) to catch the biggest drawdown.

I felt more hostile to the FXCM account performance because I didn’t have any profits to pad the losses. This is all coming from my original risk capital. And I’m having my third child soon. Giving birth to kids in the US is incredibly expensive. I’ve got better uses for the money than to throw it away in the markets!

So, the real question is: am I losing because it’s just a rough patch or because FXCM is eating my lunch?

backtest-equity-fxcm

This image is a backtested equity curve over the same period of my live performance. I’ve traded live since January 28, but the trading didn’t begin until the afternoon. As you can see, I again missed another patch of strong performance.

The rest shows something of a fairy tale. The backtest shows a return of 19.13% over that period, whereas my live performance is down 10%. How much of that is due to commissions, spread, rollover and slippage?

The backtest shows a profit of $956.65 with no trading costs.

My real results, which 1) show a profit on the backtest but 2) are actually showing a loss in real life, can be used to estimate a floor for my trading costs. The formula for that is
( Total profit and loss + commissions + rollover) / total trades, which is currently $1.58 in costs per trade.

The commissions and rollover are easy to separate out using either Myfxbook or the FXCM account report. The grand total spent so far on commissions is -$239.80 and -$3.05 on rollover.

The hardest part to separate is the spread paid. I’m not recording the spread paid on every trade (maybe that’s a mistake and I need to add it). But I’m going to use the table below to estimate. I took a random sample of 30 trades from the 501 trades completed at the time of my analysis.

Spread PaidSlippage
0.0001985231.49E-05
0.000153951-5.13E-05
0.0004558230.000227912
9.98E-050
0.000161242-0.00313413
2.76E-05-9.19E-06
5.55E-056.94E-06
0.000110898-1.01E-05
9.24E-050
9.91E-05-1.57E-16
6.55E-051.31E-05
4.85E-052.08E-05
8.22E-05-1.67E-16
6.87E-050
6.95E-05-1.65E-16
0.00015173-2.17E-05
9.43E-05-2.36E-05
9.38E-05-0.00225922
7.61E-05-0.0024735
0.0001600381.00E-05
0.000135020
0.0035426254.52E-05
0.000222978-0.00376275
7.62E-050
0.0004327977.73E-06
2.61E-050

The average slippage (the right column) is a stunning -0.044%. I’m getting negative slippage on average with FXCM. That’s outstanding! FXCM is improving my fills even though my entries are requested at a worse price. Whatever misgivings I’ve had about FXCM in the past are alleviated. That’s impressive execution.

Estimating the spread paid is much more difficult. I’ve chosen to take my average trade profit on a $5,000 account as the starting point. The trouble is that the value of an average winner can depend on the account performance. If I use stagnant position sizing, then the drawdown doesn’t effect the value of the average winner. Under that assumption, the average winner is $3.48 per trade.

But if I use compound position sizing, the drawdown eats away most of the profits. That drops the average trade value down to $1.70.

I converted the spread paid from pips into percentages. Using EURUSD as an example, a 1 pip spread works out to 0.0001/1.12727 = 0.000089. The reason for doing this is so that I can compare the spread on EURUSD to something with a much wider spread like AUDNZD. The spread is wider on AUDNZD, but the value of a NZD pip isn’t the same as a USD pip. Percentages allow for an apples to apples comparison.

The average spread paid in my sample was 0.00026157605, which is 0.026%. Putting that back into terms relative to my account balance, I’m paying 0.026% * $5,000 = $1.31 per trade in spread. Across 420 trades, that’s -$550.20 in spreads.

Total costs are spread, commissions and rollover:
$550.20 + $239.80 + $3.05 = $793.05

On a per trade basis, that is $1.78 in costs per trade from my estimates.

The total profit on the backtest was $956.65, but I missed about $550 of it because trading didn’t start until 17:00 on the 28th of January. That leaves the backtest profit somewhere around $406.65.

That puts the re-estimated profit and loss at $406.65-$793.05 = -$386.40. The actual loss is -$469, which I feel is a reasonable discrepancy based on the fact that I’m estimating how much profit was contributed on January 28 instead of knowing for certain.

The conclusion is that I need to turn off this trading at FXCM. Even if I joined their active trader program and traded in the top tier, it would only save me half the commissions. Most of the trading costs are in the spread and not commissions. I’m seriously considering a move to a broker that will allow me to make a market by posting limit orders. But first, I’ll need to go over my Pepperstone account to review the trading costs for myself and clients.

Filed Under: Dominari, Test your concepts historically Tagged With: backtest, FXCM, Rollover, slippage, spread

Live demo testing a new strategy with limit orders

November 24, 2015 by Shaun Overton 17 Comments

I come up with amazing looking backtests all the time. This is the latest example using the SB score.

backtested equity curve

The equity curve of the new strategy without trading costs.

The free and hypothetical version of the strategy yielded $79,618.82 for an uncompounded return of 796.19% over a period of 3 years. The strategy trades all major FX crosses. As you can tell, the signal quality remains nearly constant across multiple market conditions. It looks great.

The problem is trading costs. It’s always trading costs that make life difficult.

Trading costs drop the profits by 98.22%

Trading costs drop the profits by 98.22%

I always take a heavily pessimistic view when it comes to assuming trading costs and slippage. It requires a lot of intellectual honesty, but making an effort to avoid rosy assumptions saves a lot of pain and disappointment down the road. The assumptions are really severe on cross currencies where we assume spreads and slippage north of 5 pips.

Performance with pessimistic trading cost assumptions drops to only making $1,000 in profit. The strategy doesn’t need to go in the rubbish bin, but it’s far from ready for prime time. There’s no scenario where it makes sense to trade with market orders.

General characteristics

Average trades per day: 39
Currency pairs traded: 27
Percent accuracy: 66.52%
Style: Mean reversion
Charts: Hourly

How to trade on the cheap

I’m notoriously frugal. One of my fraternity brothers in college still tells stories about me counting loose change and tracking it in MS Money.

That kind of mentality drives my wife crazy… but it’s a real asset for a trader! Traders make their money on the margins like every other business person.

I spent yesterday afternoon coding this new strategy with a slight twist. Instead of paying the spread on every single trade, what if I use limit orders to try and earn the spread?

The current raw spread on EURUSD is 0.3 pips, which is worth $0.03 per microlot. The trading commissions are $0.03 per microlot. If I earn an extra $0.03 per microlot, that at least covers the trading costs. On pairs like NZDCHF where the raw spread is 1 pip, that adds an extra $0.04 ($0.10 – $0.03) per side. I.e., the entry signal makes an extra $0.04 and the exit also makes an extra $0.04 on every single trade.

Even quiet pairs on NZDCHF still exhibit a degree of noise on every bar. I haven’t done any research to back it up, but my subjective experience says that the wicks of 90% or more of bars will be at least as long as the spread is wide.

Traders make their money on the margins like every other business person.

Said another way, if the spread on EURUSD is 0.3 pips, then the difference between the open and low price on 90% of bars should be at least 0.3 pips, too. That’s my assumption, anyway.

An example of twisting the strategy to use limit orders

Say that my signal to enter the market just popped up. The current price for EURUSD is 1.06457 x 1.06462, which is 0.5 pips. The backtests assume that I’ll hit the 1.06462 asking price and pay the spread.

The idea for my test is to set my limit order at 1.06457. Since I’m a retail trader, that means I’m asking the market to move down half a pip before I’ll get to have a position. Requiring a small move in my favor theoretically earns more than jumping into the market with both feet.

Live demo testing begins

I could theoretically model the idea in a backtest, but there are critical assumptions that make it pointless.

1) The average spreads available in my 2009-2011 backtest period were far wider than they are today
2) The spread varies significantly throughout the day. EURUSD is routinely as low as 0.2 pips in the European sesssion, but can easily hit over 1.0 pips in the dullest portions of Asian trading.

The second item could be completely detrimental in a backtest. It’s better to test the idea on a live demo and get something closer to real trading data.

Demo testing

The first 15 hours of live demo testing.

I’m only 15 hours into the test, but at least everything is off to a good start.

The goal for the test is simple: place at least 300 trades in the account. That should only take about 2 weeks since the strategy is so hyperactive.

The criterion for success is equally simple: does the real-time demo trading performance meet or exceed the backtesting performance over the same time period?

I started trading in the evening of November 23, which means that I should hit my 300 trade threshold around the 10th day of trading. The trading frequency does fluctuate, but that should occur sometime around December 4th.

Even though I have live demo data, I’m going to run a market entry backtest from November 23 to December 4. If the demo trading, which uses limit orders, exceeds the market entry backtest, then I have a reasonable basis for assuming that the strategy is ready to trade on a small live account.

comparison scale

I’m also ironing out bugs that appear during the live simulation. More than likely, these dates will be pushed back. I already found 2 issues that require investigation after only 22 trades. There’s no point in judging a strategy if it’s not performing exactly as specified.

Code the same strategy twice?

You probably noticed that the forward test equity curve is from MetaTrader. Why would I test in one platform but execute in another? All of my backtests were done in Seer.

If you have two people work on a problem and they both arrive at the same answer, then they probably answered the problem correctly. The same logic applies to programming. If I program a version of the strategy and Jingwei programs a version of the strategy, they’re supposed to place the exact same trades. Any discrepancies mean that someone’s programming is wrong.

I routinely use this method because the slightest errors in logic can lead to dramatically different trading outcomes. It’s the difference between making a lot of money and losing a lot of money. Yes, I’m sacrificing efficiency. The stakes for a strategy are so high that it’s better to make 2 people do the same work in exchange for the confidence of knowing that it was done properly.

MetaTrader is inferior to Seer by every measure. The only reason that I wrote my code in MetaTrader was that I’m anxious to test the idea. MQL4 is easy for me to code – programming for MetaTrader is one of our main services.

After Jingwei finishes programming the Seer version next week (she’s off for Thanksgiving), I’ll have the basis for comparing my MT4 version against hers. It’s terribly inefficient, but I also know how likely I am to waste weeks on analyzing trades placed according to rules that don’t exactly match my strategy. Better safe than sorry!!!

How to fatten the margins

One thing I hate about retail trading is that very few venues offer a true ECN. Trading on a traditional retail forex broker means that I have to wait for the spread come down to touch my order. In the example I gave using EURUSD, it requires that the market move 0.5 pips in my favor before I get a fill.

Trading on an ECN would significantly increase the probability of receiving a fill on the limit order. Using the EURUSD example where the current prices are 1.06457 x 1.06462, I would place a buy limit order on the bid at 1.06457. If anyone in the market sells at that time, it means that at least a portion of the order would be filled almost immediately.

In effect, trading on the retail spreads contains the worst case scenario for execution. The price has to adjust 0.5 pips in your favor in order to get filled. If you trade on an ECN and the price fell 0.5 pips, you would get filled every single time. But you also get the chance to get filled earlier and faster because if anyone comes in and goes short at market, the order sits on the book waiting for someone to hit it.

fat margin

Smart traders do everything in their power to fatten up the margins

I’m proceeding with the demo test now. If it meets or exceeds the backtest results, I’ll then know with the highest degree of confidence possible that the method is ready for live trading. I’ll probably start with a few thousand dollars for the first month. Then, if it succeeds, I’ll really start to scale it.

There’s no reason that all trades must occur on H1 charts. I can always shift the trading intervals by one minute, two minutes… fifty-nine minutes. And even there, it’s possible

My ideal scenario is to trade the strategy on an ECN venue, which requires a minimum balance of $250,000. That amount of money is far higher than I’m comfortable risking. The old rule of trading is that you never risk more than you’re comfortable losing.

That means I’ll likely be looking for a partner to make sure the strategy runs in the best environment possible (an ECN). Are you possibly that partner? If so, send an email to info@onestepremoved.com and introduce yourself. Nothing will happen for several months, but it always takes awhile to build relationships and feel comfortable with a project.

Filed Under: Dominari, Test your concepts historically, Trading strategy ideas Tagged With: backtest, limit, spread

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

Further Proof That Backtesting Results Don’t Guarantee Future Performance

November 18, 2013 by Andrew Selby Leave a Comment

In theory, it makes perfect sense that fundamental changes in markets over time could cause systems that had an edge to become unprofitable. However, because we generally backtest systems all the way up to the current time, encountering a system with a dramatic change like this is not common.

Matt from Don’t Fear The Bear recently came across a system that gave him the opportunity to test two different time periods. The system he discovered was written and backtested in 2009. At that point everything looked great, but as you will see that did not continue to be the case. Matt was able to replicate the previous backtesting results testing over the previous time period, but the results moving forward were drastically different.

Matt shows us a system that performed one way up through 2009 and then produced inverse results ever since.

Matt shows us a system that performed one way up through 2009 and has produced inverse results ever since.

Here is how Matt came across those posts:

I was browsing my twitter feed this week and saw a couple old Quantifiable Edges posts (hereand here) linked to by @PsychTrader.

The two posts were written in mid-2009 and detail a simple weekly strategy that uses the relative performance of the S&P 500 and Nasdaq indexes to time the market.

They showed how investing in the SP 500 or Nasdaq  when Nasdaq has been outperforming (based on 10 week relative performance) has generally beat out buy and hold.

Matt decided to test how a simple system that held either QQQ or cash depending on whether QQQ was either outperforming or underperforming the SPY would fare. He tested two different versions. The first version held QQQ when it was outperforming the SPY and cash when it was not. The second version held QQQ when it was underperforming the SPY and cash when it was not.

Here is what Matt found:

First let’s look at the period from 1999 (inception of QQQ) to the end of 2008.

The strategy to invest in QQQ when it underperformed SPY got crushed during the bear markets and just treaded water during the bull market.

The inverse strategy did much better and held its ground through bull and bear period alike.

Interestingly, the strategies flip-flopped starting in 2009:

The strategy that sucked big time before has been steadily rocketing higher while the formerly better strategy has been treading water.

I guess this is just another example of strategies being turned on their head at the market’s whim.  This is one I’ll be keeping tabs on going forward.

As you can see, this weekly QQQ strategy makes logical sense and would be  fairly easy to trade. The only problem is that you wouldn’t know which version to trade moving forward. This further stresses the point that backtesting results do not guarantee future performance!

Filed Under: Test your concepts historically Tagged With: backtest, qqq, simple system, SPY, weekly system

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

IQFeed Kinetick Trick

March 19, 2013 by Shaun Overton Leave a Comment

NinjaTrader is my favorite strategy backtesting platform. Kinetick works great and is an important part of why I use NinjaTrader – the historical data service makes it so easy to find reliable price history for many instruments.

Collecting good market data poses one of the biggest problems to a systems trader. As I always like to point out, GIGO: garbage in, garbage out. It doesn’t do any good to backtest a strategy on junk price histories.

The same company that owns NinjaTrader also owns Kinetick. It’s no coincidence that the only natively supported data provider is a sister company.

That relationship might lead one to believe that the downloading speed of Kinetick would run fastest inside of NinjaTrader. One would be wrong.

I heard a number of traders complain last week at the Trade Empowered summit about Kinetick’s download speeds. It takes a long time for Kinetick to load historical data, regardless of whether its forex or equities data. Jason, a trader that I befriended, jumped into the conversation with a nice trick that he learned. It’s worthy of sharing with everyone.

Use Kinetick with IQFeed

IQFeed accepts the user name and password for live Kinetick accounts. That in itself isn’t very noteworthy.

What’s important is that IQFeed runs many times faster than Kinetick. If you have a live Kinetick account, download IQFeed onto your computer. Complete the installation process by running the .exe file.

Create a new account connection in NinjaTrader. Instead of selecting Kinetick, select IQFeed. Push next.

IQFeed connection in NinjaTrader

Create a new IQFeed connection in NinjaTrader 7

The new screen asks for your IQFeed user details. You don’t have any because you subscribe to Kinetick. That’s ok! Enter in your Kinetick details anyway.

Enter your Kinetick account information into the IQFeed details screen

Enter your Kinetick account information into the IQFeed connection screen.

Name the connection something that you’ll remember. I called mine KinetickIQ.

Now go to the Control Center. Select File \ Connect \ KinetickIQ. When the connection loads, IQFeed will connect using the Kinetick account information.

The download speeds magically run several times faster than connecting directly to Kinetick. I have no idea why this is, but it’s a cool trick if you’re in a hurry to downloads reams of price data.

Did this help you out? Please leave comments in the section below.

Filed Under: NinjaTrader Tips Tagged With: backtest, IQFeed, Kinetick, price history

Annoying Backtest Surprise

January 22, 2013 by Shaun Overton 2 Comments

The first backtest results are in from segmenting my price-SMA cross forex strategy. Looking back, I really should have pre-researched this idea before publicly moving ahead. Look before you leap!

I rediscovered the same irritating problem that wasted 2 months of my life back in March 2012. I’m more irritated about finding the same results again than anything. If you were able to trade crosses over the SMA 200 without the spread, the strategy makes gobs and gobs of money.

The idea led to using SMA 200 price crosses to trade with limit orders for free using BBBO (Best Bid Best Offer). That fell flat after orders received an 80% fill rate at multiple brokers. It needed 95%+ fill rates in order to work.

Equity curve EURUSD

The strategy looks deceptively appealing. It’s completely useless.

Real world trading costs including the spread and slippage works out to something like 2 pips on EURUSD. The strategy traded 29,132 times on the M1 chart to earn a profit of $118,970. The problem is that the 2 pip spread cost would have cost $582,640. The pretty equity curve costs $4 for every $1 of profit. Not good.

Trade report for all sma price crosses

The price crossed the 200 period simple moving average more than 29,000 times in 2011.

The SMA distance curve analysis didn’t turn out as I expected. There were far fewer trading opportunities away from the moving average than what I predicted – the SMA is stickier than I previously thought. No matter where I looked, the strategy always spent more money on trading costs than it earned. I posted all of the images here for the sake of thoroughness.

I’ll be moving this up to the M5 chart in the next round of tests. Everyone can say a loud, “I told you so!”

Trades entering at ±0.1% away from the SMA 200.

Trades entering at ±0.1% away from the SMA 200.

M1 price crosses 0.2% over 200 SMA

Trades entering at ±0.2% away from the SMA 200.

M1 price crosses 0.3% over 200 SMA

Trades entering at ±0.3% away from the SMA 200.

M1 price crosses 0.4% over 200 SMA

Trades entering at ±0.4% away from the SMA 200.

M1 price crosses 0.5% over 200 SMA

Trades entering at ±0.5% away from the SMA 200.

M1 price crosses 0.6% over 200 SMA

Trades entering at ±0.6% away from the SMA 200.

The next step is to take a quick look at the M5 charts to see if I can make the basic idea viable there.

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: Test your concepts historically, Trading strategy ideas Tagged With: backtest, equity curve, SMA

  • 1
  • 2
  • Next Page »
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.