Wednesday, March 3, 2010

Reorganising the forward tests

I have been letting a number of forward tests run for some time without really paying much attention to them, so it's time to clean everything up.

Here's what will continue to run.  These will also have a link in the forward tests section on the right, and I have looked through old posts and updated links so I hope everything works.

MetaTrader 5
I am running two VOM EAs on the one demo account.
Past forward tests on MetaTrader 4
I was running a number of tests on MT4, in particular two versions of a News Trader, but I'm going to stop for the moment.  The best NewsTrader only broke even at best, and obviously needs work.  I'll be converting to MQL5 as some stage.




Thursday, February 4, 2010

Is the FrAMA Cross EA successful?

In a nutshell: no, and maybe.

No-one was more surprised than me when I plucked a simple strategy out of the air to develop my MQL5 coding skills, and it actually showed some promise. This is the FrAMA Cross EA, which simply uses a moving average cross on a 1H EURUSD chart with the Fractal Moving Average indicator that comes with MT5. The two MA periods are 6 and 12, with a fixed stoploss of 50 pips. Each cross event reverses the direction of the trade.  My original blogpost for this EA is here.

In the absence of a strategy tester for MT5 so far, and witnessing the promising equity curve in the forward tests, I decided to code the FrAMA indicator into MT4 and backtest it. The formula is well documented under the Analytics section of the MT5 terminal help file.

So here's an MT4 custom FrAMA indicator, which gave me the satisfaction of behaving exactly the same as its MT5 counterpart.

I wasn't particularly surprised to see that the backtest using the above parameters is rather poor.  The equity curve from 1/1/2004 to now is like this:


Maybe there's some tweaking that can be done - there is an extended profitable period from last August - but I'm not going to bother because it tends to reinforce my experience that H1 charts are very difficult to trend-trade.

Not to be deterred, I set about optimising the parameters using the MT4 strategy tester. There are lots of ways to trend-trade Daily charts - is this another one? The answer is, as is usually the case with optimisation of EAs on daily charts, "maybe". Here's an optimised backtest of a FrAMA Cross EA on a Daily EURUSD chart with Fractal MA periods set to 2 and 58, ending at 31/12/2008.



… and here is the out of sample 1/1/2009 to present.



In case anyone is wondering, this is a legitimate use of the open-prices-only model for backtesting, because the EA gets its entry and exit signals from events detected in the previous completed bar. If you want to wait for half an hour, a 90% modelling backtest of every tick will look the same, and an EA of this type will behave almost to the dollar the same in live trading as it does in backtests. But notice that I didn't say that it will necessarily be as profitable - optimisation of daily charts introduces a big fluke factor, caused by the fact that the total number of trades is statistically too small.

So where to from here? Before even considering trading them live, I usually mothball EAs of this type for at least a year, dust them off, and see how they would have performed. With the massive peak in volatility from the GFC well behind us, maybe it's time to get into long term trend trading again. In the meantime, you can watch grass grow (average 1 trade every 3 weeks!) with the VOM version of the EA.

Wednesday, January 27, 2010

Getting there with the VOM

I've made a number of significant changes to the VOM code, and things are looking better.

Here's a shot of six "Random Loser" EAs using the VOM.  At the beginning of each 1M candle, they toss a coin and either enter EURUSD long or short, up to a maximum of three open virtual orders.  I designed them to be a stringent test of the VOM because it has to handle six virtual order requests at once. 

Although 18 virtual orders in total are open, there is only the one position open at sell 0.2 lots, which is the sum of all the virtual orders.



The two real VOM EAs that I mentioned in a recent post have now started trading properly, with screen shots being updates, so that's more of a real-word test.

Saturday, January 16, 2010

VOM update

Well, it turned out to be a bit ambitious to put the VOM V0.2 out there for people to have a look at.  I've had hassles with MT5 build 238, which continually crashed (blew up, atomic bomb style - aka U238?).  That's now fixed I think with build 239.  Also I'm having to look very closely at resource locking, because multiple VOMs are becoming tangled when ticks arrive rapidly.  I could have sworn that I tested all of that before, and maybe I did and the new builds are behaving differently. 

Instead of trying to do something with real EA strategies, I've written a really simple EA that I call "Random_loser" to test the locking process.  5% of the time it buys; 5% it sells, and the rest it does nothing!  Interesting to watch two of them trading together.

Anyhow, with the market closed and no strategy tester yet, I'll be waiting until next week to take another look, which is probably a good thing.

Saturday, January 9, 2010

Testing the Virtual Order Manager with hedging orders from two EAs

I have written several times before about writing a Virtual Order Manager to enable hedged trades in MetaTrader 5.  Well, it's been "complete" for about three weeks, but what I underestimated was the amount of testing required.  Nonetheless, I feel it's getting close to release V0.1 time (even this will contain plenty of bugs, I'm sure), so for those who are interested I am publishing a forward test of two EAs re-written to run on it. 
  • The Support Resistance EA which I wrote about in August 2009 and which I have been forward testing for some time on MT4.  You can download the MQL5 VOM code for this here.
  • My first MT5 EA, the FrAMA Cross EA, which I wrote about in October 2009.  You can download the MQL5 VOM code for this here.
Here is a forward test of both EAs running on the one account.
True to my article published on MQL5.com about auto-generating documentation from MQL5 code, here is the draft VOM manual created using Doxygen.  Note that you will need to right-click / save this file on your PC (eg in the MetaTrader 5/Help folder) to view it.  Here are three pictures from the manual which set the scene - the manual discusses them in some detail:

 
Firstly, a diagram of how an EA interfaces to the VOM

 

Secondly, a diagram of the VOM modules

 


 
... and lastly a screenshot of the VOM tester EA that I have been using to put it through its paces

 


 

 
Here are all the Virtual Order Manager files in beta V0.2.
It's been a very interesting exercise in MQL5 programming and I welcome readers' comments.

Sunday, December 13, 2009

A crude "API" for MetaTrader 4

In response to Ludosm's request to publish this utility, here it is.  Using this API, any other software can drive trade functions in MT4 by generating simple one line CSV files in a similar format to the original MQL4 trade commands.

So where you would write the following in an EA ....
OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);

.... the CSV file looks like this
OrderSend, symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color

A price of Bid or Ask is interpreted correctly.

An important difference is that open orders are located using their Comment, meaning that comments should have a numerical sequence.

So OrderClose(ticket); becomes OrderClose,Comment

There are additional comments at the top of the script.  Hope it's useful.

Tuesday, December 8, 2009

1500 and counting; what's coming up

Very gratifying to see that I've passed the 1500 mark with hits to this blog - thanks everyone for the interest. So that's a very modest average of 10 hits a day, although it started very slow and has risen to about 50 per day recently. As an aside, it's fascinating to be a microscopic part of the Google machine. The blog has so far had 11 ad click-throughs to generate $18.11 revenue in five months!! Keep on clicking, guys - I'll give up my day job soon :)

In the meantime, I have lots of balls in the air with trading and coding ideas (happy as a pig in sh*t, as they say)
  1. First priority - finish off an article which expands on my auto-generated documentation for MQL5 post in this blog. The Metaquotes guys have showed an interest in it and it's likely to be published on the official MQL5 site. The last thing to finish off is a comment processor which trawls through the entire MQL5 folder and subfolders and slightly modifies the comments so that they can be read in by Doxygen and appear in the comiled help documentation.
  2. Finish off the MQL5 Virtual Order Manager so people can try it and comment. I've written the VOM itself, but need to polish up the EA I use to test it so it can be debugged more fully. This EA is a series of buttons in a chart window which allow real and virtual orders to be opened and closed. I'll probably release the whole lot then, but also need to follow up quickly with an indicator which reports open virtual orders in a table.
  3. The Neural Network EA has been grinding along. I hit a difficult snag with the retrieval of history - other people have also complained that they can't retrieve the full history with Close[xxxxx]. My testing seems to indicate a limit of 1000 bars in the past (or is it 1024?) or only 10 days of 15 minute bars, although some others talk about a gradually increasing value of Bars but they can't work out what triggers it. The EA and associated neural network dll works well functionally, but the neural network can't be trained on a sufficiently long dataset to prove the concept. I can see two ways forward: either write a history reader which reads history directly from the MT4 *.hst files. Or, write the whole damn thing in MQL5, which I have found doesn't have the limitation. The latter will take a lot more time, but I've always had a plan to write a learning neural network in MQL5 in preparation for the trading championships in 2010, so I'm leaning that way. I wish Metaquotes would let us know when the strategy tester will become available.
  4. Allow me some (OK, a lot of) misty speculation: if an MQL5 neural network EA proves to be profitable (or any MQL5 EA), then it would be quite easy to write a MetaTrader 5 to MetaTrader 4 messaging utility to enable any MQL5 EA on demo to trade live now using MetaTrader 4. Already sitting in my MT4 code archive somewhere is a crude MT4 API EA which accepts trading commands via *.csv files.