Stop wasting time. Scan!

How much time to do you spend every day looking for a trade setup?  If you have a good system, and you know your setups well, do you spend a long time looking through a dozen stocks or currency pairs, checking to see if your setup is there in each one?

I’m getting more and more excited about the idea of scanning.  With scanning, you only need to program in your setup criteria, which financial instruments to scan, and let the scanner tell you which stocks, futures or currency pairs look like they’re getting ready for your set up.

The trick is, of course, to write the scanner, but that’s what we’re here for, right?  A scanner is a lot like writing an indicator for a trading platform, but instead of drawing it on the screen for one chart, the scanner checks multiple charts, and just lets you know which chart might be the ones you should look at.

In John Person’s book Mastering the Stock Market, he spends a bit of time talking about scanning.  It’s in the section on Relative Strength, which I wrote about last week.

scanning-jpm-chartSo, a quick recap here.   On the chart, the top graph is the stock we want to trade; in this case, JPM.  The lower graph shows the relative strength of the JPM stock with the financials XLF Exchange Traded Fund.  Additionally, on the bottom graph, there’s a 9-period moving average that gives us some cross-over points.

Where ever the moving average and the Relative Strength lines cross, that’s a change.  If Relative Strength is above the moving average, that means our stock is doing better than the rest of its industry, and we want to be in that stock.  When the Relative Strength line falls below the moving average, that means it’s doing less well than the rest of the industry, and we want to be out of that stock.

So, how about scanning?  The scanner needs to do the following for each stock (let’s just stick with stocks for now, and let’s assume we’re using daily charts)

  1. Look up the associated ETF or index for the given stock
  2. Load the daily chart for the stock
  3. Load the Relative Strength indicator for the the stock and the paired ETF
  4. Apply a moving average to the Relative Strength buffer
  5. If the moving average has crossed the Relative Strength in the last few days (configurable), alert me.

It would be fairly simple to do this with a variety of platforms, and we looked at something like this from Howard Bandy in his Quantitative Trading Systems book.  We’ll look at that more closely in an upcoming blog post.

 

More JForex to like

I’ve found a few more features of JForex that I really like:

  • When you run a strategy on the JForex platform, you can choose to run it locally (on your own machine), or remotely.  Running it remotely appears to send it off to a server somewhere else to run.   Does this eliminate the need to to run it on a virtual private server?  I’m not sure.  I’m going to test this out and report back.
  • The API.  There is a whole JForex API that lets you develop completely offline using Eclipse or your favorite IDE, and you just link into the Java class files from the API.  Do you know what else this means?  I can use a debugger to step through my code! So much better than primitive print statements we are using now!
  • There’s some interesting methods we can use to make a strategy display in visual mode for back testing.  Sometimes it’s helpful to see just exactly what the strategy is doing, and by calling chart routines in the code you can optionally display the indicators and other text on the charts while the system trades.

More good things to come…

 

What is curve fitting and why is it bad?

I’ve received a few questions from readers on the topic of curve fitting, so I thought I’d talk about that a bit here.

What’s curve fitting?  Well, it’s bad.  When we back-test a trading system, we are trying to see if the trading rules we have written in our program successfully make a profit on historical data.  One of the things we do in back testing is we optimize parameters.  That means we find the best possible value for a parameter that controls something in our program.  But sometimes, we find the perfect value for historical data, but that value doesn’t work in a real trading situation.  Why not?  Well, it is possible we have fit our parameter too closely to the exact historical data, making it not flexible enough to work in new unseen data.  That’s curve fitting.  And it’s bad because it creates a trading system that seems good, but really isn’t.

One way to look at it is to think of the the signal and the noise.  Our trading system is looking for the signal (our rules for entries and exits based on indicators or patterns), and trying to ignore the noise (spikes, gaps, volatility, general market randomness).  If we tune our parameters to listen to everything, both the signal and the noise, then when we trade in a live account, it won’t work.  In the new market data, the signal is still there, but the noise is different.

How do we prevent curve fitting? There are a number of things we can do to prevent curve fitting when we are back testing.  One of the best techniques is to split up your testing data into two sections: an in-sample set, and an out-of-sample set.  You will spend time tuning parameters, optimizing your software, and getting everything perfect on the in-sample data set.  You will run your program dozens of times with this data and get it profitable, and working very well.

Then, once you have your perfect parameters, you run your program on the out-of-sample data set, and you see how it does.  The key here is that you may run the program one time on the out-of-sample set, and you may not use the out of sample results to tweak your program’s parameters.  If you do, that data set now becomes part of the in-sample set!

If the results of your out-of-sample set look good, then congratulations!  You may move onto the next phase of testing.  But if the results of the out-of-sample test do not look good, you have probably been guilty of curve-fitting during your back testing, and you need to go back and find more general parameters.  We’ll go over that in a future blog post.

Let’s assume you were successful in your out-of-sample testing.  What’s the next step?  That would be walk forward optimization.  Walk Forward Optimization is neat.  The concept is this: if you take January to Feburary of 2011 as your in-sample set, and then use March of 2011 as your out of sample set, you’ll find some good parameters to use. Save them off somewhere.  Now run the back-test again, but use February to March as the in-sample set, and use April of 2011 as the out-of-sample set.  Find your best parameters and save them off.  Keep moving the “window” of sample sets forward, and keep saving off your results.  At the end of all of the back-test runs, compare all the results you have saved off.  If they are similar, you have a great set of parameters for your system.  If not, then you have some work to do (more on that in a future post).

If this walk-forward test is automated, then this process is somewhat enjoyable.  If you have to manually run all of these tests, then it’s a bit tedious, and you have to keep really accurate notes on each run.  Unfortunately for us, the walk-forward analysis in Metatrader is a manual process, and it’s tedious.  (There is an MT4 add-on that makes it easier, but it’s not perfect.)

The AmiBroker trading platform that I have mentioned in the past does do walk forward analysis, and that is one of its features that makes it attractive to trading system developers.

But, as long as you can keep a spreadsheet of dates, parameters and profitability, you can run the walk-forward analysis manually, and your system will be much better in the long run.

So, curve fitting is bad; we want to make sure our optimized parameters are great, but general enough for new unseen data.

I mentioned a book a few weeks ago called “Trading Systems” by Emilio Tomasini; he spends a lot of time discussing curve fitting, how to avoid it, and how to properly test a trading system.  If are working on back testing, and you haven’t picked up that book yet, you’d do well to get a copy.

 

What can JForex do for me?

I’ve spent a few days working with JForex in an FXDD demo account.  It’s an interesting programming environment.  I’m liking it.

What’s JForex?  JForex is a Java implementation of a programming language for trading systems, similar to the way MQL is the programming language for MetaTrader.  Hundreds of brokerages support MetaTrader/MQL, and a lesser number support JForex.

There are a number of things I like about JForex, and a few things I do not.

Things I like:

  • The whole environment launches from a web browser; once you have your demo account user id and password, you click on a link to the JForex demo site, and Java launches a separate window where you have your whole trading platform; both manual trading and trading programs are done from this window.
  • Programs you create in Java are stored locally on your computer; only when you compile them are they uploaded to the JForex server
  • It’s Java!  I mean, it’s one of the most well supported programming languages in the world.  There are so many resources for Java.  It’s an excellent choice for a trading system programming language.
  • Java is stable.  You won’t find bugs in Java itself (but you could run into issues with the JForex platform).
  • You could use Eclipse to write the Java code, and then upload it to the JForex server; if you like your Eclipse developers environment, use that to write, then upload, compile and test in JForex.

Things I don’t like:

  • The whole platform launches in Java from a browser.  Eeek.  That means your browser must be error-free, you need to have Java installed correctly, and a host of other things that could go wrong.  Well, to be fair, MetaTrader gets goofed up often too, so maybe it won’t be any worse than that, but I have seen a number of browser problems that could impact a Java setup.
  • It isn’t clear how you use the Eclipse debugger or any of the other debugging tools when using JForex.  My serious problem with MetaTrader 4 is that there’s no debugger, and debugging code amounts to printing your own trace statements to the screen or the log.  I hope JForex gives us better tools than that.

There’s a lot I haven’t done yet with JForex, so this is just an introduction.  Stay tuned, I’ll be working with this quite a bit more, and letting you know what I find.

I have one book on my reading list that explains trading system development from the JForex perspective.  I haven’t purchased this book yet, but it looks like it’s the only one out there right now.

Will JForex become a dominant player in the currency trading world?  We’ll see.  For now it’s one of several options for automated trading system developers.

[AMAZONPRODUCTS asin=”1479247138″]

Visual programming for Automated Trading Systems?

The EquaMetrics company has announced a new product called RIZM which is a “visual programming” platform for trading systems (or algos, as they are known). This looks really cool, but I am skeptical. The idea is that you can “visually design complex trading strategies without a single line of code” according to the product literature.

We know how complex trading algorithms can be, and that a huge amount of testing and parameter tuning is required to make a system backtest well enough to trade with in a live account.  Can that be done without code?

When Microsoft first released Visual Basic, there was a big concern among programmers that they (we) were becoming obsolete.  I mean, if anyone could create a program by moving blocks around on the screen, who needs programmers?  It turned out that the best Visual programmers were exactly that — programmers.  The developers who already understood program structure, logical organized thinking, how to connect program modules together, and how to properly test software.  Many things you couldn’t do with just visual blocks on the screen; you had to get behind the blocks and get into the code.

I suspect the same might be true about RIZM. It might be a way to get into algo programming, but the best visual algo programmers will be the algo programmers who already understand coding for trading systems, and the same programmers would probably just prefer to write code.

We’ll see.  I may sign up for an account to get a first-hand view of the platform.