Saturday, May 15, 2010

An early stopping Neural Network strategy

I've written several times in this blog about a Neural Network idea that I've been working on for some time.  I wrote a NN dll for MQL4, but found that the treatment of history in MT4 makes the collection of sufficient data to train the NN very difficult.  However, in the process I did come up with a manual approach to training the NN which showed promise.  With the much faster speed of MQL5, and the very welcome ability to encapsulate code, it is now fully possible to write everything in MQL5, including coding the manual process, meaning that the whole concept can be backtested and optimised.

The broadest descripion of the idea is early stopping, which is not new in the slightest, and in fact most NN literature mentions it.  Early stopping attempts to address the problem with NNs that they are so good at learning that eventually they start to memorise individual data items, which is the familiar problem found in EA optimisation of curve fitting.  Early stopping terminates the learning process at a point where hopefully the NN has only learnt patterns, rather than data.

So this is the hypothesis: a profitable NN EA can be developed ...
  1. If a NN can be trained using an early stopping technique to recognise forex patterns
  2. If patterns repeat in forex trading, and more importantly, come in clusters
There is no doubt in my mind that item 1 is true, since I have achieved it with manual selection of NNs.  What is somewhat less certain is item 2, although the general technical analysis approach does tend to support it.  Terms such as trending market, or sideways market imply persistence of patterns,  and even a non-profitable EA can often show lengthy periods of profitability.

This last point is another key: rather than discarding all technical analysis in favour of a magical NN black box, why not look first for a basic EA strategy which seems to support item 2 above?  Its equity curve should show extended periods of profitability which could then be selected by a NN filter, in a similar way that the commonly used long term moving average is used to detect a trending market.

The whole idea is already in MQL5 code, with a number of coding errors which I need to find, which will take some time.

Here's the macro view


  1. Very interested to learn more about what you come up with. I have been toying around with Flood2 (C++ NN) but with little luck. Any good resources you would recommend for a NN rookie?

  2. Hi Skajake, take a look at my first NN blog post at, in pafticular the two links to and

  3. Eagerly awaiting your next post.. its been awhile!

  4. interesting idea.
    how much time do you think is necessary to "learn" something "profitable".

    I'm training my models using small models with collections of 300 bars, medium models with 1000 bars and big between 30.000 - 60.000 bars.

    What do you think about this?

  5. There seems to be a history limit, at least in the Metaquotes test MQL5 instance, of about 20,000 x 15 minute bars, and I'm not sure where the limitation is. Out of these I then aim for a factset to learn of between 300 and 1000 in size, which comes from a conventional technical strategy like breakout or MA cross.

    Neural networks work best when they are asked to learn something which is close to profitable already.

  6. Hey Everybody,

    Below is a list of the highest ranking forex brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 minimum deposit.

    Here is a list of the best forex instruments:
    1. ForexTrendy - Recommended Probability Software.
    2. EA Builder - Custom Indicators Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    Hopefully these lists are benificial to you.

  7. Forex Trendy is an innovative program capable of recognizing the safest continuation chart patterns. It scans through all the charts, on all time frames and analyzes every possible breakout.


    Professional trading signals sent to your cell phone daily.

    Follow our trades NOW and gain up to 270% daily.

  9. GPS robot tripled the $100k deposit [live proof authenticated by myfxbook and broker]

    I just finished a webinar with Mark and his partner, Antony, two days ago and it was AWESOME.

    During the webinar MARK and ANTONY shared their secrets to success and answered questions about their new release of the GPS Forex Robot that came out TODAY!