You are on page 1of 84

Genetic Builder

User's Guide

Version 2.1.0

Last updated: 19.6.2012

Genetic Builder User's Guide

Support
If you'll have trouble understanding anything, you need help, or you simply have some question to ask (related to the system), remember your purchase includes also a support. We are here for you, contact us at:

www.GeneticBuilder.com/web/contactus/

Copyright
All rights reserved. The Genetic Builder software, bonus strategies and content of this Manual is copyrighted. You can use them only with valid license. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means - including electronic, mechanical, photocopy, recording, scanning or otherwise - without the prior written permission of the author. 2012 Mark Fric, SonarBytes Ltd

Genetic Builder User's Guide

Risk Disclosure
Risk Disclosure Statement
Trading any financial market involves risk. This Manual is neither a solicitation nor an offer to Buy/Sell any financial product. The contents of this Manual are for general informational purposes only. Although every attempt has been made to ensure accuracy, the author does not give any expressed or implied warranty as to its accuracy. The author does not accept any liability for error or omission. All examples are provided for illustrative purposes only and should not be construed as investment advice. No representation is being made that any account, or trader will, or is likely to achieve profits or loses similar to those discussed in this Manual. Past performance cannot be relied upon as being indicative of future performance. The information provided in this Manual is not intended for distribution to, or use by any person or entity in any jurisdiction or country where such distribution or use would be contrary to law or regulation or which would subject the author to any registration requirement within such jurisdiction or country. Hypothetical performance results have many inherent limitations, some of which are mentioned below. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. In fact, there are frequently sharp differences between hypothetical performance results and actual results subsequently achieved by any particular trading system. One of the limitations of hypothetical performance results is that they are generally prepared with the benefit of hindsight. In addition, hypothetical trading does not involve financial risk and no hypothetical trading record can completely account for the impact of financial risk in actual trading. For example the ability to withstand losses or to adhere to a particular trading program in spite of the trading losses are material points, which can also adversely affect trading results. There are numerous other factors related to the market in general or to the implementation of any specific trading program, which cannot be fully accounted for in the preparation of hypothetical performance results. All of which can adversely affect actual trading results. U.S. Government Required Disclaimer - Commodity Futures Trading Commission Futures, Currency and Options trading has large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. Don't trade with money you can't afford to lose. This is neither a solicitation nor an offer to Buy/Sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this web site. The past performance of any trading system or methodology is not necessarily indicative of future results. CFTC RULE 4.41 - HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.

Genetic Builder User's Guide

Software License Agreement


This legal document is an agreement between you, the end user ('User'), and Sonarbytes ('Author'). AGREEMENT - By installing Genetic Builder ('Software'), copying the Software and/or clicking on the 'I Agree' button during installation, you agree to all of the terms of this software license agreement ('Agreement'). If you do not agree with all of the terms of this agreement, click on the 'I Do Not Agree' button and/or do not install, copy or otherwise use the software. INTELLECTUAL PROPERTY. The Software and any associated materials are protected by copyright law. The package is a proprietary product of the Author. The Author retains title to and ownership in the copyright of the software program and the associated materials. You acknowledge that the Author owns all rights, title and interest in and to the Software, including without limitation all Intellectual Property Rights. 'Intellectual Property Rights' means any and all rights existing from time to time under patent law, copyright law, trade secret law, trademark law, unfair competition law, and any and all other proprietary rights, and any and all applications, renewals, extensions and restorations thereof, now or hereafter in force and effect worldwide. You agree not to modify, adapt, translate, decompile, reverse engineer, disassemble or otherwise attempt to derive source code from the Software. REGISTRATION. This program is neither freeware nor public domain. Use requires valid license. Contact us at http://www.geneticbuilder.com/contactus/ for bulk licenses or discounted prices. GRANT. Author hereby grants you a non-exclusive, non-transferable license to use the Software upon payment of the License Fee until the expiry date of the license (if any). Author makes no guarantee of the frequency, value, applicability or content of future updates or modifications to the Software. The Software will only be made available to you in electronic form for download. The requirement to pay a license fee does not apply to evaluation copies for which Author does not charge a license fee. Evaluation licenses expire 14 calendar days from the date of this agreement, unless otherwise agreed to in writing by Author. On the date of expiry of the license, User agrees to either purchase the Software at the list price in force at that time or to destroy all copies of the Software in electronic or other form, including any copies on backup tapes or other media. User's use of the Software shall be limited to use on a single hardware chassis, on a single central processing unit, as applicable, or use on such greater number of chassis or central processing units as User may have paid the required license fee. You may not: permit other individuals to use the Software except under the terms listed above; translate, reverse engineer, decompile, decrypt, reverse engineer, disassemble (except to the extent applicable laws specifically prohibit such restriction), or create derivative works based on the Software; copy the Software (except for back-up purposes); rent, lease, transfer, assign, sub-license or otherwise transfer rights to the Software; or remove any proprietary notices or labels on the Software. DISCLAIMER OF WARRANTY. THE SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS BORNE BY YOU. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, OR OTHERWISE, SHALL AUTHOR OR ITS SUPPLIERS OR RESELLERS BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL OR PUNITIVE DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES. IN NO EVENT WILL AUTHOR BE LIABLE FOR ANY DAMAGES IN EXCESS OF AUTHOR'S LIST PRICE FOR A LICENSE TO THE SOFTWARE, EVEN IF AUTHOR SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY

Genetic Builder User's Guide


ANY OTHER PARTY. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. FURTHERMORE, SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT APPLY TO YOU. TERMINATION. This license will terminate automatically if you fail to comply with the limitations described above. On termination, you must destroy all copies of the Software in electronic or other form, including any copies on backup tapes or other media. Upon termination of this License for any reason, you shall have no right to refund of the whole or part of any License Fee paid.

Genetic Builder User's Guide

Table of Contents
1 Introduction ..................................................................................................................................... 8 1.1 What is Genetic Builder? ......................................................................................................... 8 1.2 Is Genetic Builder Right for You? ............................................................................................. 8 1.3 What to Expect ........................................................................................................................ 9 1.4 Evaluating Generated Strategies ........................................................................................... 10 1.5 Backtesting issues.................................................................................................................. 13 1.6 Requirements ........................................................................................................................ 15 1.6.1 Installation ..................................................................................................................... 15 1.7 New Features......................................................................................................................... 16 How does it work? ......................................................................................................................... 18 2.1 Random generation of trading strategies ............................................................................. 18 2.2 Genetic Evolution .................................................................................................................. 19 2.3 Supported building blocks ..................................................................................................... 20 2.4 Custom Indicators.................................................................................................................. 21 2.5 Modes of operation ............................................................................................................... 22 2.5.1 Genetic Evolution .......................................................................................................... 22 2.5.2 Random Generation ...................................................................................................... 22 2.5.3 "Mixed" mode ............................................................................................................... 23 2.5.4 Strategy Testing ............................................................................................................. 23 Quick start with the program ........................................................................................................ 24 3.1 Main concepts ....................................................................................................................... 24 3.2 Flow of work .......................................................................................................................... 26 3.3 Random Generation in step-by-step examples ..................................................................... 27 3.3.1 Step 1: Obtaining history data for backtest .................................................................. 27 3.3.2 Step 2: Configuring the build process............................................................................ 27 3.3.3 Step 3: Starting the generation ..................................................................................... 32 3.3.4 Step 4: Stopping the generation and reviewing the results ......................................... 33 3.3.5 Summing it up................................................................................................................ 35 Detailed Description ...................................................................................................................... 36 4.1 Data tab ................................................................................................................................. 36 4.1.1 Data for backtest ........................................................................................................... 36 4.1.2 Manage History Data ..................................................................................................... 36 4.1.3 Manage Custom Indicators ........................................................................................... 37 4.2 Build tab ................................................................................................................................ 38 4.3 Settings tab ............................................................................................................................ 39 4.3.1 Build Goals ..................................................................................................................... 39 4.3.2 Strategy Options Screen ................................................................................................ 41 4.3.3 Building Blocks Screen ................................................................................................... 43 4.3.4 Genetic Options Screen ................................................................................................. 47 4.3.5 Strategy Ranking Options Screen .................................................................................. 51 4.4 Results tab ............................................................................................................................. 55 4.4.1 Databank ....................................................................................................................... 56 4.4.2 Result Details ................................................................................................................. 59 4.5 Strategy Editor ....................................................................................................................... 63 How To........................................................................................................................................... 64 5.1 Export strategy from Genetic Builder and test it in MetaTrader .......................................... 64

Genetic Builder User's Guide


5.2 Import history data from Metatrader ................................................................................... 68 5.3 Importing tick data from MetaTrader ................................................................................... 71 5.4 Importing custom indicator from MetaTrader to GB ............................................................ 73 5.4.1 Step 1 - Getting the indicator values from MetaTrader ................................................ 73 5.4.2 Step 2 - Exporting the indicator values from MetaTrader ............................................ 76 5.4.3 Step 3 - Create new custom indicator in Genetic Builder ............................................. 77 5.4.4 Step 4 - Import indicator values to Genetic Builder ...................................................... 78 5.4.5 Step 5 - Use the custom indicators................................................................................ 79 5.5 Running reliable backtests in MetaTrader 4 ......................................................................... 81 6 Final Words.................................................................................................................................... 84

Genetic Builder User's Guide

1 Introduction
1.1 What is Genetic Builder?
Genetic Builder is a program that automatically generates new unique trading strategies for forex, stocks or ETFs. Using Genetic Builder, you can easily find profitable trading strategies for virtually any market, any timeframe and any chart type. No programming or trading knowledge is required. The resulting strategies can be saved as a MetaTrader 4 Expert Advisor with complete source code. With Genetic Builder you can:

Build an unlimited number of unique trading strategies Test them with maximum possible reliability on tick data Develop strategies for virtually any market or timeframe Save your strategies as a MetaTrader Expert Advisor with full source code! Eliminate the manual labor previously required when developing a trading strategy Find new trading strategies that are not only unique, but also non-obvious Reduce the time required to build a strategy from weeks and months to minutes!

1.2 Is Genetic Builder Right for You?


If you trade using automatic trading system (called also robots or Expert Advisors) or you plan to develop your own trading strategies then Genetic Builder can save you money and hundreds of hours of your time. Some traders prefer to purchase an existing trading robot, there is a multitude of offers especially for Forex. While this can be an effective way, by purchasing someone's forex robot you are usually purchasing a black box - you don't know how it works, what are the exact rules and you are at mercy of its creator with potential adaptations to changed market conditions. Genetic Builder allows you to create your own trading strategies, exportable to a plain Expert Advisor source code, so you have full control over your strategy.

What If You Are a Manual Trader?


You can still use for Genetic Builder to generate the trading ideas. You'll be surprised to find many profitable strategies based on relatively simple rules that you wouldn't think of. Every strategy that is created by Genetic Builder can be exported to readable pseudo code with full description of the trading rules and can be traded also manually.

Genetic Builder User's Guide

1.3 What to Expect


Please keep in mind that Genetic Builder is a powerful tool, but it is not a magic box that will start making you money with a click on a button. It has to be used in the right way to get the results. Few things to realize:

Generating new strategies in Genetic Builder is only about 50% of the work.
The rest 50% of the work is evaluating the generated strategies to filter out the ones that are curve fitted or not robust enough. It is up to you to evaluate your new strategies properly and know their strengths, weaknesses and limitations before you put them to live trading. It can easily happen that from all the profitable strategies generated by Genetic Builder only 1 out of 10 passes the evaluation and we can consider using it for live trading. But - the number of strategies we can generate is almost endless, so even 5-10% from infinity is a pretty big number :-) There are few steps to evaluate the strategies quality and measure how good they will be in real live trading. Please read the Evaluating Generated Strategies section for more information.

Genetic Builder User's Guide

1.4 Evaluating Generated Strategies


As we said before, generating new strategy is only 50%of the work; the rest is evaluating it to ensure it is a real strategy with a real edge. Be prepared that there will be a lot of waste - only a small portion of the strategies will pass the evaluation. The main dangers with the new strategies generated by Genetic Builder are: Curve Fitting The most serious risk of strategies generated by Genetic Builder is curve fitting - there is a danger that a strategy with good backtest was simply curve fitted to the particular history data, and in reality it has no real trading edge. Fortunately, this is easy to detect, simply by testing the same strategy on a different symbol, timeframe or different date period.

Differences in backtest results A small difference in backtest results between Genetic Builder and Metatrader is normal. If the difference is very big (and the equity curve looks totally different), it means the backtest in both GB and MT4 is only a guess and the results are NOT RELIABLE in both programs. The best thing we can do is avoid these strategies.

Further evaluation of generated strategies should address these dangers and rule out strategies that are not good enough. The next steps after generating new fresh profitable strategy are: 1. Look at the equity curve The easiest test - the equity curve of a strategy should look almost linear, it should be continually growing without big drawdowns.

Even if the strategies ended up with the same results, the right strategy goes up and down with big drawdowns and is not tradable. The strategies with bad equity curve should be ruled out immediately.

10

Genetic Builder User's Guide


2. Check the Risk Reward Ratio You should check how big the average winning trade as opposed to the losing trade is. The ideal is if the winning trade is bigger or at least the same as the losing one. Good strategy - if you make on average $100 on the winning trade and lose only $40 on the losing one, then you need to win only 1 out of 3 trades to make money. Bad strategy - if your strategy makes $5 on a winning trade but loses $100 on a losing trade, it is very bad strategy. You will usually have a big winning percentage, but one loss will take profits from many days or weeks.

3. Test for robustness and curve fitting The best is to test the strategy on a different part of data. You can develop your strategy on 50-60% of available history data, and then test it on the rest of data. If the strategy is robust, it should behave the same also on an "unknown" period. Higher level of robustness is if the strategy works also on a different symbol or timeframe. For example, if you generated your strategy on GBPUSD, you can retest it on EURUSD. Or if you generated it using 1H timeframe, try running the test on 30 Minutes or 4H timeframe. The result of a retest doesnt need to be as good as the initial test, and many profitable strategies will not work on a different symbol. But if you'll find a strategy that works on multiple symbols you found a really robust strategy. Good strategy - will be profitable on both initial test and retest and the equity curves will look "normal" in both of them. Bad strategy - will have a good results and good equity curve on the initial test (first part of data), but when you retest it (second , the "unknown" part of data) it will be either not profitable, or the equity curve will be bad and random.

4. Test for backtest reliability


When the strategy passed the previous steps we can test it on MetaTrader. Simply export the strategy (in Results -> Source code) and save it as the MetaTrader EA. Then retest the strategy in Metatrader again using the same settings as in Genetic Builder and check the results of the test. Good strategy - the results in both Genetic Builder and MetaTrader are the same, or almost the same, and the equity curve looks the same. This means the strategy is robust and the backtest was very accurate, so we can expect the strategy will behave the same also in the live trading. Bad strategy - the results in MetaTrader are totally different from Genetic Builder (for example strategy is losing on MT4 while it was profitable in GB). This means the strategy cannot be reliably tested and we have to avoid it.

11

Genetic Builder User's Guide

Note
If you have different result of tests between Genetic Builder and MetaTrader, it is possible that you are simply not testing it correctly. Please check the next chapter - Backtesting issues - for possible reasons of a different results.

5. Did your strategy pass all the above steps?


Congratulations, you've probably found a gem, and very likely a strategy that nobody else knows about.

12

Genetic Builder User's Guide

1.5 Backtesting issues


Genetic Builder has its own very fast backtester that can test the performance of a strategy on a historical data in a matter of seconds (depending on the length of the input price data file). The backtested uses its own testing algorithm, which produces reliable results, but the backtest results in some specific cases might be not 100% the same as running the same backtest in MetaTrader 4. This can have few reasons: 1. Incorrect use of MetaTrader Strategy Tester it seems that backtesting in MetaTrader is simple, but we should use some techniques in order to run really reliable backtests in MetaTrader Strategy Tester. They are described at the end of this book in the chapter How to - Running reliable backtests in MetaTrader 4. 2. Different data, timeframe or period To obtain comparable results you should use the same data, timeframe and period in both Genetic Builder and Metatrader. Note that every broker has slightly different data feed, so there will be always some difference if you test your strategy on the same symbol (for example EURUSD) but with data from different sources.

Different spread or Min distance from order price


Genetic Builder allows you to configure spread and min distance from order price. Make sure you use exactly the same values as you have in your Metatrader. If your Metatrader is connected live, its spreads can change with every tick, so it is impossible to get a fixed spread. Different spread can have very big influence on test results, especially on strategies that trade frequently. The strategy source code contains control for this, and if it finds a difference it will display the warnings visible in the Journal tab of the MetaTrader Strategy Tester.

3. Bad Test precision Please check that you use Test precision: Tick simulation in Genetic Builder and Model: Every tick in Metatrader. This will produce the most accurate results.

13

Genetic Builder User's Guide


If you don't get the same results in MetaTrader as in Genetic Builder, make sure you checked all the steps above. They have to be handled so that we can have comparable backtests between Genetic Builder and MetaTrader. However, there's one more possible reason for the difference in results: 4. Bad backtest reliability of a strategy There is a certain type of strategies that will always have different backtest results in Genetic Builder and MetaTrader - those are strategies that often use consecutive orders (one order is closed for example at 18:30 and immediately a new order is opened). The main cause of these differences is a different tick simulation algorithm. Since both Genetic Builder and MetaTrader test the strategies on 1 minute data, the price changes within this 1 minute have to be simulated. Different tick simulation leads to trades that are missed or added in GB compared to MT4, which could have big effect on the test results. The main point to understand is that it is impossible to test this kind of strategy reliably. The test results in both GB and MT4 are only a guess and the results are NOT RELIABLE AT ALL in both programs. Don't get confused if MetaTrader gives you 90% modeling quality, it doesn't mean that its backtest is 90% reliable. In this case it is the missing 10% that can make a huge difference in results. If we'll look at it from a different angle - the different backtesting results between MetaTrader and Genetic Builder is actually a GOOD THING - it allows us to filter out strategies that are too sensitive to a price changes on a tick level, which means they are not robust enough and impossible to backtest reliably.

Note
Since version 2.0 and support for tick data we can use a little trick to achieve the same backtest results in GB as in MT4. Please read more in the section How To Importing tick data from MetaTrader

14

Genetic Builder User's Guide

1.6 Requirements
Genetic Builder is not an EA, it is a normal program (EXE file) for Microsoft Windows and it will run on all standard computers with Internet connection. Strategy generation and backtesting are very time consuming, so the faster computer you have, the faster you'll get the results.

1.6.1

Installation

Genetic Builder comes with standard setup wizard, you just download and run the installation EXE file and follow the steps in the installation wizard.

Important !!! Please DON'T install Genetic Builder to standard C:\Program Files directory !
It might not work correctly because Windows security settings don't allow the program to write to its data files. Instead install it to any normal drive or directory on the disk, like C:\Genetic Builder or C:\Trading\GeneticBuilder

15

Genetic Builder User's Guide

1.7 New Features


There is a number of new features in version 2 that bring the functionality of the program to a whole new level. The main improvements are:

Greatly improved testing speed and support for multi-core processors


the backtesting speed has been improved by nearly 50% and the new version now also supports multiple cores. Read more here: Using multiple cores

Support for tick data


perhaps the most important feature in the new version. It enables you to test your strategies in a biggest possible precision. Quality tick data can be obtained for free for example from Dukascopy here: http://www.dukascopy.com/swiss/english/marketwatch/historical/ Genetic Builder now supports configurable input format, so you can import virtually any data into GB without making any conversion.

100% compatibility of test results with MetaTrader4


this is a nice positive side effect of tick data support. We can now export simulated tick data from MetaTrader and run our GB backtests on this MetaTrader tick data, achieving almost 100% comparability of the results. There will be only very small differences resulting from rounding numbers and the way MT4 computes profit/loss.

Support for Custom Indicators


another important feature enabling you to use your favorite indicators in your strategies without the need for them to be build-in Genetic Builder. You can read more about custom indicators in these sections:

Custom Indicators Importing custom indicator from MetaTrader to GB Manage Custom Indicators

Custom Dismiss Options


a small but important feature that allows us to specify the exact conditions for strategies to be dismissed. This enables us to effectively filter out the strategies that dont fulfill our performance criteria.

Strategy Editor
a new feature that allows you to edit or create a new strategy. More here: Strategy Editor

16

Genetic Builder User's Guide

Configurable RRR for SL/PT


the Strategy Options settings was enhanced with the possibility to define the boundaries for desired Risk Reward Ratio. More here: Stop Loss and Profit Target Options

Candle Patterns
new candle patterns building blocks, such as Doji, Hammer, Shooting Star, Engulfing, etc. Genetic Builder also comes with a custom indicator located in {GB directory}/custom_indicators/mt4/indicators/GenBuilder_Pattern_Recognition.mq4 that displays these candle patterns on the chart. You only need to copy the indicator to your MetaTrader /expert/indicators directory and apply it on the chart.

Number of smaller enhancements


such as improved speed, improved ranking and elimination criteria, new building blocks, more exports, better source code generation and so on.

17

Genetic Builder User's Guide

2 How does it work?


Genetic Builder is a program, it doesn't have the brain or experience of a trader, and it doesnt know how to create a profitable strategy. What it does is that it randomly combines available building blocks (indicators, prices, etc.) to create new trading rules. The resulting strategy is then tested on a history data to see if it is profitable. Random generation is the foundation of Genetic Builder. Strategies generated this way can be further improved (evolved) using Genetic evolution.

2.1 Random generation of trading strategies


A trading strategy in the initial population is constructed using a combination of price patterns, technical indicators, order types, and other parts to form the entry and exit rules. Genetic Builder can use all standard technical indicators and oscillators (like CCI, RSI, Stochastic, etc.), time values (like time of day, day of week) and price patterns. These building blocks are then combined using logical and equality operators (and, or, >, <, etc.) to form an entry or exit rule. In addition, it supports different entry and exit order types (market order, limit order, fixed profit target, exit after X bars, etc.). With all the possible combinations of rules and orders, Genetic Builder is capable of generating literally trillions of different possible trading strategies.

The building process itself is completely random - builder randomly picks different building blocks from the available pool and combines them to create entry rule, order type and exit rule. There are some validity constraints that ensure that, for example price is not compared to time value, etc. The result is a completely new random trading strategy. Of course, not every randomly created

18

Genetic Builder User's Guide


strategy is profitable, but Genetic Builder can produce and test thousands of new strategies per hour, and there are many profitable ones in this amount.

2.2 Genetic Evolution


Genetic Evolution takes the process of finding a suitable trading strategies even further. In this mode Genetic Builder first creates a number of random strategies, which are used as the initial population in the evolution. This initial generation of strategies is then "evolved" over successive generations using genetic programming technology. This process imitates the evolution - the algorithm chooses the fittest strategies (using selected performance criteria) in every generation, and the group of fittest candidates is then used to produce new generation of trading strategies. As in evolution, this should result in better and better candidates, in our case in strategies that are more profitable, more stable, or generally better in the selected performance criteria.

19

Genetic Builder User's Guide

2.3 Supported building blocks


Genetic Builder currently supports the following components to build entry and exit rules:

Indicators Simple Moving Average Exponential Moving Average Weighted Moving Average Commodity Channel Index (CCI) Relative Strength Index (RSI) Stochastic MACD Bollinger Bands Qualitative Quantitative Estimation (QQE) Triple Exponential Moving Average Custom Indicators ***

Average Directional Movement Index (ADX) Average True Range (ATR) Momentum Williams % Range True Range Price Difference Highest, Lowest Keltner Channel Parabolic SAR Ichimoku

Price Values Open High Open Daily High Daily Heiken Ashi Open Heiken Ashi High

Low Close Low Daily Close Daily Heiken Ashi Low Heiken Ashi Close

Candle Patterns Doji Hammer Bullish Engulfing

Shooting Star Dark Cloud Cover Piercing Line Bearish Engulfing

Operators Greater Lower Crosses Above Crosses Below And Or Time Values Hour Minute

Addition (+) Subtraction (-) Multiplication (*) Equals Not Equals

Day of Week

20

Genetic Builder User's Guide


Order Types Enter at Market Enter at Limit Exit Types Stop Loss Exit After X Bars Exit Rule (Price + Operators + Indicators, ...)

Enter at Stop

Profit Target Move Stop Loss to Break-even Trailing Stop

We will be continually adding new technical indicators and other features to the Builder. If you have your favorite indicator you'd like to see in Genetic Builder, just let us know.

2.4 Custom Indicators


Since version 2.0 the Builder offers almost infinite flexibility of building blocks with custom indicators. In contrast with build-in indicators, Genetic Builder doesnt know how to compute custom indicators; they are defined by their data. This will enable you to use virtually any of your favorite indicators in Genetic Builder. There are no real limits you can use multi-timeframe or multi-symbol indicators, generally every indicator that works in MetaTrader can be The way it works is that you have to export the values of the indicator computed on a specific symbol and timeframe to a file, and then import this file as a custom indicator to the Builder. This way youll create new custom indicator (with values computed in another program, such as MT4) for this specific symbol and timeframe also in GB. Remember, every custom indicator is defined for a specific combination of symbol and timeframe (on which it was computed). To use the same indicator on another symbol or timeframe, you have to recomputed its data in MT4, export it and create a new custom indicator for this symbol/timeframe combination.

21

Genetic Builder User's Guide

2.5 Modes of operation


The program has two main modes (Genetic Evolution and Random Generation) that allow you to generate new unique trading strategies. Each of these modes has its own pros and cons. The third complementary mode (Strategies Testing) can be used during the evaluation phase to test the already generated strategies on a different symbols, timeframes or time periods.

2.5.1

Genetic Evolution

The "full" mode. Genetic Builder first generates initial population of random candidates (using the Random Generation mode) and then uses genetic evolution process to evolve the population and produce better and better candidates with each generation. The process ends when predefined number of generations is reached or when there's no further improvement. Pros:

in theory it should lead to strategies better than the initial random generation this means that the already good strategies in the first generation can be further improved search for profitable strategy in the trillions of possible combinations can be more effective with the power of evolution

Cons: evolution is slow sometimes the evolution can lead to the dead end, so the generation should be watched the group of generated strategies is limited by population size

2.5.2

Random Generation

In this mode Genetic Builder continually generates and tests new random strategies, one after another, until it is stopped. The top candidates (based on predefined criteria) are stored into Databank so you can review them later. Pros:

faster and simpler than genetic evolution it will run until it is stopped, so if you let it run for a few days it can generate and evaluate millions of strategies

Cons: once the strategies are generated they are not further improved

22

Genetic Builder User's Guide


2.5.3 "Mixed" mode

It is possible to "mix" these two generation modes to get the best from both. For example, you can first use Random Generation to generate a number of good strategies, evaluate them and choose only the best. Then, in the next step, you can use these existing saved strategies as an initial population for Genetic Evolution mode. This means that the Genetic Builder will not create new random initial generation, but it will use already existing strategies as the first generation. This first generation of already good strategies is then further evolved to produce potentially better strategies.

2.5.4 Strategy Testing An additional mode that allows to test already generated strategies on different data and timeframes. It allows you to test the strategies that are in Databank on a different symbol, timeframe, date period, or using a different spread or trade settings. Strategy Testing mode is necessary for evaluation of robustness of generated strategies.

23

Genetic Builder User's Guide

3 Quick start with the program


3.1 Main concepts
When we first start the program we'll see the main screen as in the picture below.

The program functionality is divided into tabs on the left side. These tabs are: Home - starting screen of the program, it contains the sample settings, news and helpful links Data - here you can configure which data to use for tests and manage history data Build - screen to start, pause and stop the building process Settings - configuration of building and strategy options Results - new generated strategies

Databank
Databank (in the Results tab) is the most important concept you should understand when using Genetic Builder. Doesn't matter which mode you use, the best resulting strategies are always stored in the Databank.

24

Genetic Builder User's Guide


There you can sort the strategies by its properties, load and save them, and when you double click on a row, it will open the strategy test details in the results window above. You can configure how many top strategies (10, 100 or 500) will be stored in Databank, what comparison criterion to use which strategies to dismiss automatically (for example those with negative P/L).

Working with files


Strategies in Genetic Builder are saved in its own proprietary file format (with .str extension) that can be opened only by Genetic Builder. If you find potentially good strategies you should always save them so that you can work with them later.

Running strategies in MetaTrader MetaTrader cannot read the strategy .str files. If you want to test or run your new strategies in MetaTrader you have to export the strategy to MQL source code. Please check the section How to - Export strategy from Genetic Builder and test it in MetaTrader. Please note that exported (*.MQ4) files are not readable by Genetic Builder, so make sure you always save your strategy also as a normal strategy file (*.str).

Using multiple cores


Since version 2.0 Genetic Builder can now use all cores of your processor to run tasks in parallel, which greatly improves generation speed. You can define how many cores the program should use in the program options in menu Tools -> Options

The program options dialog has a slider containing all available processor cores. By moving the slider you can increase or decrease number of threads / processor cores used by the program.

25

Genetic Builder User's Guide

3.2 Flow of work


The general flow of work when generating new strategies can be described as follows: Step 1: Configure data for backtest You can use the history data that come with the program or optionally import your own data in Metatrader format. Then set up the tie period and timeframe you want to use. If you'll use genetic evolution mode you have to select the In Sample and Out of Sample periods.

Step 2: Choose mode of operation Choose between Genetic Evolution or Random Generation mode to create new strategies, or Strategies Testing if you want to retest existing strategies.

Step 3: Configure settings Go through all the settings and configure strategy type, indicators and order types to be used for trading rules. Optionally use time constraints to limit trading to a certain time range. Set up the strategy ranking rules and how the strategies will be stored into Databank.

Step 4: Build Click on Build button to start building the strategies.

Step 5: Evaluate the generated strategies Go through the generated strategies and evaluate them. Choose the best ones to consider in the next step.

Step 6: Save the strategies and export them to MetaTrader code This is actually the last step of evaluation, we should export the strategies to MetaTrader EA to test them in MetaTrader. These that pass all the tests can be used for demo or live trading.

26

Genetic Builder User's Guide

3.3 Random Generation in step-by-step examples


The goal: generate new unique trading strategies for forex. In this quick start you'll get a quick overview of all the main screens of the program and you'll see how easy it is to generate new trading strategies in Genetic Builder. 3.3.1 Step 1: Obtaining history data for backtest

Genetic Builder already comes with more than 4 years of real history data for major forex pairs (history data provided by www.ForexHistoryDatabase.com), so you can build your strategies right away. Or, optionally, you can export the history data from your MetaTrader 4 installation and import them to Genetic Builder.

3.3.2

Step 2: Configuring the build process

When we first start the program we'll see the main screen as in the picture below.

The program uses tabs on the left to switch between the screens. The first screen is Home. It provides quick navigation and contains some sample settings. You can use one of the four sample settings to test various build configurations, or start from scratch as in this example.

27

Genetic Builder User's Guide Choosing the data


Switch to Data tab and choose GBPUSD_fhdb. This way we'll choose that the strategy backtests should be made on GBPUSD data on given period and timeframe. We can leave everything else at the default values.

28

Genetic Builder User's Guide Choosing mode of operation


On the Build tab there is a possibility to choose the mode of operation. We can choose from three modes, in this example we'll choose Random Generation mode, which means the Builder will continually generate and test new random strategies, without using genetic evolution. You can read more about the operation modes here.

We'll not start build process yet, we have to review the settings before that.

Reviewing the settings


Switch to Settings tab now. There are three settings screens for the Random Generation mode, we'll go through each of them. More detailed description of all the settings can be found in the User's Guide, in this sample we can leave most of it at the default values. When we switch to Strategy Options tab (on the bottom of the right Settings screen), we can configure the properties of strategies we want to generate. It is possible to generate only strategies that take only Long or only Short orders, but in this case we want strategies with both Long & Short orders.

29

Genetic Builder User's Guide

The next settings tab is Building Blocks. It is generally a list of all the elements - technical indicators, price and time values, operators, etc. that can be used in generated strategies. So here we are able to specify which of the building blocks we want to use.

30

Genetic Builder User's Guide


Strategies are generated randomly, using only the blocks that are checked, so you can choose your own combination of indicators and operators. We can keep all entry building blocks checked. For Order Types & Exit Blocks, we'll choose only Enter at Market, Stop Loss and Profit Target for simplicity. This means that Genetic Builder can use all available building blocks for generating the entry rules (for entering the trade), but it will generate only strategies that enter at market price and have exit target defined as fixed or ATR based number of pips. The last tab in the settings is Strategy Ranking Options. Here we can configure the strategy ranking criteria - every strategy is tested on historical data and the performance (using the chosen criteria) is then computed into the strategy rank number, also called Fitness. The program uses this strategy fitness to compare one strategy to another and to determine best strategies. To make it simple, we'll configure it to use only Net Profit and Profit Factor criteria for Fitness computation.

We can also specify which strategies should be saved in the Databank for later review. In Random Generation, the program generates and tests one random strategy after another until it is stopped, so it can effectively create tens of thousands of strategies in a matter of minutes. It is not possible to save or remember every generated strategy, and also, not every strategy is profitable. The Databank is used to keep the given number (100 in our example) of best strategies. We are done with our settings with these four screens. The next step is to start the building process and just wait for the results.

31

Genetic Builder User's Guide


3.3.3 Step 3: Starting the generation

We'll start the random generation by simply clicking on the Start button in the Build screen.

The program begins generating strategies and shows its progress in the log in the Build screen.

You can see it usually takes a less than a second (depending on a precision mode) to generate and backtest the new strategy on the historical data.

32

Genetic Builder User's Guide


The generated strategies are continually compared and sorted and the top 100 of them are stored into the Databank in the Results tab.

3.3.4

Step 4: Stopping the generation and reviewing the results

Genetic Builder will continue to work and generate new strategies until you stop it, which you can do by hitting the Stop button in the Build screen. Depending on how powerful your computer is, it can take 10-30 minutes to generate and test few hundreds of different strategies. By now you should have full Databank (100 best strategies were stored there), so you can sort the strategies in the databank for example by Fitness (our rank criterion computed using Net profit and Profit factor).

If you want to see the details of the strategy, simply double click on its row.

33

Genetic Builder User's Guide


This will open the strategy results in the Results details window (above the Databank).

The first screen in the results is Overview - it gives you all the summary results of this strategy backtest on one screen. The next screen is List of trades - pretty self explanatory - it shows the complete list of trades of this strategy in the backtest.

Equity chart displays the development of equity during the backtested period. We can see that the generated strategy is quite stable, it grows almost linearly without very big oscillations.

34

Genetic Builder User's Guide

The last tab for this strategy is Source code. Here you can get the complete MetaTrader Expert Advisor source code for this strategy.

You can just save the source to a MQ4 file, copy it to MetaTrader 4 and run an independent backtest or (after more testing) start this new strategy as an automatic robot on your demo or live account. It really can't be more simple than that. 3.3.5 Summing it up

In a few simple steps and in a few minutes we quickly generated tens of new profitable trading strategies. The features of the program are more richer than this basic example, there are almost endless possibilities of how you can play with the configuration to generate strategies with different properties.

35

Genetic Builder User's Guide

4 Detailed Description
4.1 Data tab
4.1.1 Data for backtest

Genetic Builder tests all the generated strategies on a given history data and this screen allows you to choose the symbol and timeframe to be used for backtests. There is an option to choose also the testing period (Date From, Date To). Out of Sample Period allows you to split the history data to two parts: In Sample - it is used during genetic evolution to compute the rank of the strategies, so that the program is able to compare them Out of Sample - this part of the data is used to verify if strategy really works as expected also on data that it was not evolved

Note
Setting the Out of Sample period makes sense for Genetic Evolution mode, because only in this mode the fitness results computed in the In Sample data are used to rank the strategies to find the "fittest" strategies. The other modes (Random Generation, Strategy Testing) don't use evolution, so you don't need to split the data to two periods. F or these two modes you can move the Out of Sample splitter to the far right, leaving Out f Sample period empty.

4.1.2

Manage History Data

This screen is where you can manage (create, import, modify) the history data that are used for backtesting.

36

Genetic Builder User's Guide


Genetic Builder already comes with 4 years history data for the major pairs, but if you have your own history data in Metatrader, you can easily import them. Check the section How to import data from Metatrader for more description.

4.1.3

Manage Custom Indicators

Here you can manage custom indicators that are used in strategies generation and in backtesting. Custom indicators are a new feature in GB version 2.0. To say it simply, they allow GB to use indicators that are not build-in the program. This allows you to use virtually any of your favorite indicators inside Genetic Builder as standard building blocks, including complicated ones that use multi-timeframe or multi-symbol analysis.

37

Genetic Builder User's Guide

4.2 Build tab


Build tab is a place where you can choose the mode of the program and where you can start, pause or stop the generation process.

Before starting the build you should have the data and settings configured. The results (generated top strategies) will be continually stored in the Databank in the Results tab.

38

Genetic Builder User's Guide

4.3 Settings tab


The available settings are dependent on the chosen mode of operation, for Genetic Evolution there are four setting screens, for Random Generation only three, and for Strategies Testing there is no setting required other than specifying data for backtest.

4.3.1

Build Goals

4.3.1.1 Market Sides You can choose to generate strategies that trade only to one direction (Long or Short) or to both directions (which is standard). You can also select that you want the entry or exit rules to be symmetrical. If they are symmetrical, then the rules for both directions are the same, only reversed. An example of symmetrical rule s: Go Long if CCI > 0 Go Short if CCI < 0 As an alternative, you can choose to use non-symmetrical rules, in this case the rules for Long and Short sides will be generated independently. An example of non-symmetrical rules: Go Long if CCI > 0 Go Short if RSI < 0 and Momentum < 100

This settings can be used for both entry and exit rules, for example you can have symmetrical entry rules, but non-symmetrical exit rules, so the strategy will effectively use (for example) different stop loss and profit target for Long and Short orders.

4.3.1.2 Choose Build Goal This is a new advanced feature available from version 1.1. Build a complete strategy is a default mode - as expected it generates new random strategies using either random generation or genetic evolution. Optimize strategy parts is a new mode that allows you to take existing strategy generated by Genetic Builder and re-generate only a part of it. This way you can for example look for better exit rules, or generate a new rule for long entry while keeping the short entry rule from original strategy. When you run random generation or Genetic Evolution with this goal, it will produce new strategies

39

Genetic Builder User's Guide


as usual, but instead of generating totally random strategies it will generate strategies based on the source strategy (see below) with only selected parts generated randomly.

4.3.1.3 Choose parts to optimize This is a setting that is valid only in parts optimization mode. It allows you to choose which parts of the strategy should be re-generated and which will be fixed. Check an example below. In this configuration we would like to improve the bonus EURUSD strategy number 0.22952. We are satisfied with trades into short direction, so we'll choose to generate new rules for long direction. To do this, we had to check LONG Entry Rules and LONG Exit Rules. The text next to the checkbox has changed to Generated Randomly. This means that this part of the strategy will be generated randomly using available building blocks. When we'll start Random Generation or Genetic Evolution, it will not create new strategies from the scratch, but it will generate new strategies with Short rules taken from our EURUSD strategy 0.22952 and randomly generated new Long rules (entry and exit).

As usual, new strategies generated this way will be stored into Databank.

40

Genetic Builder User's Guide


4.3.2 Strategy Options Screen

Here you can define the desired properties of the generated strategies.

4.3.2.1 Trading Logic Trading logic defines the behavior of the strategy during the day. Exit at end of day/end of range if selected, the strategy will close all position at the end of the day or end of the trading range (if defined). This way you'll have no position open overnight. Limit max trades per day to you can limit maximum trades the strategy takes per day to a given number Limit maximum total trades to you can limit maximum total trades to a given number. It is usually good to use this limit and set it to some big number (1000-5000, depending on how many trades you expect normally). It can help GB to filter out strategies with incorrect rules that generate many very small trades, or scalping strategies that cannot be accurately tested using GB. Limit trading to hours this limits the hours the strategy is checking for entry signal to a given time range. If used in combination with Exit at end of day/end of range then all open positions are closed at the end of the range. If you don't check the Exit at end of day/end of range then the strategy will not open new trades outside the trading range, but the already opened positions will be not closed.

4.3.2.2 Stop Loss and Profit Target Options This panel allows you to configure various parameters of Stop Loss and Profit Target. You can specify that settings allow you to specify of the Stop Loss and Profit Target are mandatory in the strategy, and what is the minimum and maximum of the SL/PT values in pips. Having defined SL/PT in the strategy is the simplest and many times the most effective approach. If you unselect the mandatory SL/PT then the randomly generated strategy can (but doesn't have to) have fixed SL/PT. It is advisable to use different exit rule, for example exit after X bars or exit rule if you uncheck this setting, otherwise the strategy will have no way to exit the trade. You can also choose if SL/PT should be generated as a fixed value in pips, or using ATR.

41

Genetic Builder User's Guide

Then you can limit the ration between Stop Loss and Profit Target to a certain range. For example if the ratio is 1:3 then Profit Target will be 3x bigger than Stop Loss.

4.3.2.3 Lookback Periods Here you can set up the periods and coefficients used by the GB when generating the trading rules. Maximum Period for Indicators sets the maximum period that will be used for indicators. Usually we don't use periods bigger than 100-300 in the trading system (depending on the type of trading strategy), so it is advisable to set the desired maximum period value. Maximum Period for Price Patterns this is the maximum lookback period for price patterns (Open, High, Low, Close prices). It doesn't really make sense to set it to more than 10-20, because the older price usually has no relation with the current market movement. Minimum and Maximum ATR Multiple these are coefficients that are used in adaptive Stop Loss or Profit Target, if it is based on Average True Range value. For example, setting Minimum to 0.5 and Maximum to 5 tells GB that it can use minimum 0.5 * ATR as the SL or PT value and maximum 5 * ATR as the SL or PT value.

42

Genetic Builder User's Guide


4.3.3 Building Blocks Screen

Building blocks are the core components that are put together to create rules for every trading strategy.

4.3.3.1 Entry Rules Building Blocks Entry building blocks can be divided into four main parts: price data - Open, High, Low, Close technical indicators -RSI, CCI, Momentum, etc. operators that are used for comparison and to combine the rules - <, >, and, or, etc. time constants - Hour, Minute of day, Day of week simple predefined rules - CCI > 0, Stochastic < 50 etc.

You have to check the components that you want to use in the strategy, so you can choose your favorite indicators, or choose for example only price data + operators if you want to generate strategies based only on price.

Good practice
According to our experience, you can sometimes get better results if you don't check all the available components, but narrow your choice to a smaller group of indicators or price values.

NOTE Non-standard Indicators !


Some of the indicators supported by Genetic Builder are not standard indicators of MetaTrader. To be able to test the generated EAs in MetaTrader you have to add these indicators to your MetaTrader4 installation. It is simple, just copy all the *.mq4 files from the {Genetic Builder installation folder}/custom_indicators/mt4 to your MetaTrader installation to path {Your Metatrader installation directory}/experts/indicators If you use more than one MetaTrader installations, you have to repeat this step for every MT4 installation where you want to run EAs from Genetic Builder.

43

Genetic Builder User's Guide


4.3.3.2 Order Types Enter at Market the simplest order type, opens the trade at the current market price (Long order at Ask price, Short order at Bid price).

Enter at Stop/Limit sets up stop or limit order, so that the trade is opened only if the price reaches the given level. The decision if to use stop or limit type of order is made based on the desired price level, and current market price. Going Long: if price level is above current market price, use stop order, otherwise use limit order Going Short: if price level is below current market price, use stop order, otherwise use limit order

Order types explained


Stop Order A stop order is an order to buy or sell once the price reaches a specified price level, known as the stop price. When the stop price is reached, a stop order becomes a market order. A buy stop order is entered at a stop price above the current market price. A sell stop order is entered at a stop price below the current market price. Limit Order A limit order is an order to buy or sell at a specific price or better. A buy limit order can only be executed at the limit price or lower, and a sell limit order can only be executed at the limit price or higher. A stop or limit order is not guaranteed to execute This kind of order can only be filled if the market price reaches the stop or limit price. While they do not guarantee execution, they help ensure that an investor does not pay more than a pre-determined price. If the order is not executed within preset time, it will expire.

44

Genetic Builder User's Guide


4.3.3.3 Exit Building Blocks Exit building blocks are used to determine when (at which conditions) the open trades should be closed. Every strategy can use a combination of all the allowed exit types, so it can use for example fixed Stop Loss and Profit Target plus Exit After X Bars as well as active Exit rule.

Stop Loss (SL) stop loss is a special type of exit order that is normally used to protect us from unlimited loss. Let's say you are in the long position, you can place the stop loss order that will close your position if the price moves for example 100 pips against you. This way, you are effectively protecting yourself to lose maximum these 100 pips, and not more. We should never trade without stop order, otherwise our losses have no limit!

Profit Target (PT) is the opposite of the Stop Loss, it can be used to take the profit once the price moves in your favor. As in the example above, you can set up a profit target to close the position once it makes for example 100 pips.

Note on Stop Loss / Profit Target


Both Stop Loss and Profit Target can have either fixed value in pips (like 30, 50 or 100 pips), or they can be based on ATR (Average True Range), for example 2*ATR. This means that the actual value of the SL/PT will be 2 times the value of average true range at the time the trade was opened. ATR based SL/PT have the advantage that they "adapt" to changed market conditions and changes of volatility. Some strategies (but not all of them) can be more profitable when they use ATR based SL/PT instead of fixed one. To enable/disable ATR for SL/PT, you can enable/disable the Average True Range indicator in the Entry Building Blocks.

Exit After X Bars this is very simple exit condition. If used, the strategy will close the trade after given number of bars (time periods on a given timeframe). This is many times a simple, but effective way to close the trade when the market moves sideways or when we want to lock in the profit.

45

Genetic Builder User's Guide


Move Stop Loss to Break-Even another simple but quite powerful condition. It tells the strategy to move protective Stop Loss to the entry price (break even) when the given profit is reached. This will not close the trade, so the strategy will be still in position, but there is zero risk after this move. Because SL is at the entry price we'll not lose anything even if the trade reverses and goes against us.

Exit Rule (Price + Operators + Indicators, ...) it is a special type of exit where strategy has not only rules for entering the trade (Entry rules) but also rules for exiting it (Exit rules). Exit rules look as same as entry rules - it is a combination of all the selected building blocks( indicators, operators, price values). Example of entry and exit rule pair: Entry Rule - if CCI > 0 Enter at Market Exit Rule - if RSI crosses above 100 and we are in long position then Close Trade

46

Genetic Builder User's Guide


4.3.4 Genetic Options Screen

These are the options that control genetic evolution from the creation of the initial population, to coefficients used for mutation and crossover.

4.3.4.1 Initial Population Generation There are two options for initial generation: Generate random population with this option Genetic Builder randomly generates new fresh initial population of trading strategies using the selected entry and exit building blocks. This is the default setting.

Use systems in Databank as initial population if you already have some generated strategies, you can select this option to use them as the initial population. In this mode the existing strategies (loaded into Databank) are used as the first generation and they are evolved using the genetic evolution. This has the advantage that you have more control over the initial population, because you can pick only the strategies you want. This mode can be used also if you used Random Generation previously to generate the random strategies - by applying evolution to the result strategies we can improve their profitability.

Decimation coefficient if you generate the strategies randomly, the "quality" or the strategies in the initial population may be skewed so that very large percentage of the population has in fact very poor quality (in terms of profitability, stability, etc.) Decimation Coefficient allows us to deal with this problem by generating more strategies than required and selecting only the top ones to the initial population and decimating (deleting) the rest. Let's say the population size is set to 50 strategies. If decimation coefficient is 1 then there's no decimation, and only 50 strategies are generated for the initial population. If you set the decimation coefficient to 2, then 2 * 50 = 100 strategies are generated, and from them the top 50 is chosen for the initial population. If you set the decimation coefficient to 3, then 3 * 50 = 150 strategies are generated, and from them the top 50 is chosen for the initial population and so on.. Of course, decimation comes at the price. Generating 3 times more strategies is also 3 times more time consuming.

47

Genetic Builder User's Guide


4.3.4.2 Initial Population Conditions These conditions give us more control over the quality of the initial population. We can choose to not use strategies that: have negative P/L - which means they are losing made no trades in the backtest - which means that most probably the entry rules are not good contain warnings - warning is a possible flaw in the strategy design recognized by Genetic Builder As with decimation, using this additional filtering has its price - when you'll start the build process you'll see that many (sometimes majority) of the strategies don't satisfy these conditions, so the Genetic Builder has to generate a large number of strategies (which takes time) in order to find these that fulfill all the quality conditions.

4.3.4.3 Main Parameters The main parameters for genetic evolution control how many strategies we want to generate, how many generations of evolution will be evolved, etc. Population size simply how many strategies we want to generate, it is also the number of strategies we want in the initial population.

Elitism in genetic evolution, the strategies with better fitness have better chance to reproduce into the next generations than the strategies with lower fitness, and this chance is proportional to the fitness. However, there's no guarantee that the best strategies survive to the next evolution step, they can be ruled out by the random selection algorithm. Elitism allows us to specify a number of top strategies that will be automatically copied to the next generation on every step, so there's a guarantee that they will be never lost. As everything, this has also the weak side. If you set elitism too high, you are risking that just one or very few top strategies will force out the rest of the strategies and in the few steps you'll have population consisting only of one strategy and its slight variants. This can be a dead end, because the evolution cannot work without diversity. If you want to use evolution, you can experiment with the value, but it is recommended to not set it higher than 5-10 % of the population size.

48

Genetic Builder User's Guide


Max # of Generations how many generations of evolution should be processed. In Genetic Evolution mode the program will stop at the given number of generations.

Max Tree Depth maximum depth of a tree when generating entry or exit rule. It says how complicated could be the entry condition. It usually makes no sense to set the depth higher than 5-7. Sometimes it could be interesting to experiment with depth as low as 1-2, which generates very simple entry conditions.

4.3.4.4 Genetic Options Genetic options are parameters of the genetic evolution algorithms. Selection Type it allows you to choose the selection strategy that is used to pick the best strategies from the population. There are several types of selection, each with its strengths and weaknesses. Roulette Wheel Selection Implements selection of n candidates from a population by selecting n candidates at random where the probability of each candidate getting selected is proportional to its fitness score. This is analogous to each candidate being assigned an area on a roulette wheel proportionate to its fitness and the wheel being spun i times. Candidates may be selected more than once. In some instances, particularly with small population sizes, the randomness of selection may result in excessively high occurrences of particular candidates. If this is a problem, Stochastic Universal Sampling provides an alternative fitness-proportionate strategy for selection. Sigma Scaling An alternative to straightforward fitness-proportionate selection such as that offered by Roulette Wheel Selection and Stochastic Universal Sampling. Uses the mean population fitness and fitness standard deviation to adjust individual fitness scores. Early on in an evolutionary algorithm this helps to avoid premature convergence caused by the dominance of one or two relatively fit candidates in a population of mostly unfit individuals. It also helps to amplify minor fitness differences in a more mature population where the rate of improvement has slowed. Stochastic Universal Sampling An alternative to Roulette Wheel Selection as a fitness-proportionate selection strategy. Ensures that the frequency of selection for each candidate is consistent with its expected frequency of selection.

49

Genetic Builder User's Guide


Truncation Selection Implements selection of n candidates from a population by simply selecting the n candidates with the highest fitness scores (the rest are discarded). A candidate is never selected more than once.

Note on Selection Type


Selection type is an advanced setting for users who want to experiment and are interested in genetics. For most of the users Roulette Wheel Selection or Stochastic Universal Sampling is a good choice.

Crossover Probability percentage probability that selected candidates will be mated and generate children. Crossover probability should be high (over 90%) because mating between different candidates is fundamental in the evolution.

Crossover Points number of points that will be exchanged during the mating.

Mutation Probability percentage probability that any of the strategies mutates. Mutation is important, because it can create new conditions that were not a part of the original population. The mutation percentage should be small - 5-10% maximum. If we set mutation too high, it will affect the evolution in a bad way and can go against strategy improvement.

50

Genetic Builder User's Guide


4.3.5 Strategy Ranking Options Screen

When the strategies are generated, every new strategy is backtested on a history data and the results of the backtest are then used to compute the Fitness (rank) of the strategy. Fitness is number from 0 to 1 and it should reflect the "quality" of the strategy according to the given criteria. In the Strategy Ranking Options screen you can configure how this Fitness value is computed (Computation criteria). You can also configure how many strategies to store into Databank, capital size for percentage drawdown calculation and you can define custom conditions to dismiss (filter out) bad strategies.

4.3.5.1 Databank Options The best strategies found are continually stored into the Databank. It is not possible to store every strategy (remember that Genetic Builder can create thousands of new strategies every hour) so we have to specify how many strategies should be stored in the Databank, how they should be sorted to find out the best ones and which strategies should be thrown away. You can use the options here to throw away strategies with bad properties. Throw away strategies with negative IS/OOS P/L checking these two options will throw away strategies that have negative results in In Sample or Out

51

Genetic Builder User's Guide


of Sample backtest. This makes sense, because we want profitable strategies, not the ones that create loss. Throw away strategies where # of trades equals max allowed trades if the strategy reached maximum allowed number of trades, it is usually a sign that something is wrong. It could be an always-in-position strategy with extremely small SL or PT. It is best to avoid this kind of strategies. Throw away strategies with zero IS/OOS trades these two options will throw away strategies with zero trades in In Sample or Out of Sample periods. It can also make sense, if the strategy doesn't produce any trades, it is probably not a good one. Throw away strategies with warnings Some of the strategies can contain possible flaws in their rules and this can be recognized by Genetic Builder. Such strategy then contains a warning message. With this setting you can decide to throw away strategies with warnings. Throw away strategies with zero symmetry Symmetry is a ratio how similar are the results between the Long and Short direction. Normally we would like the strategy to be as symmetrical as possible, meaning that it would have very similar profit both to Long and Short side. If symmetry is zero, it means that one of the sides ended up with no trades or negative profit. You can choose to throw away this kind of strategy.

4.3.5.2 Strategy Fitness Computation Criteria this table is used to choose the criteria you want to use to compute the total Fitness of the strategy. Only the checked criteria will be used, and you can choose one or multiple criteria, each with a different weight. Note that if you choose to combine too many criteria, they might "fight" against each other without achieving what you expected.

Profit Factor criterion to maximize Profit Factor of a strategy.

Net Profit criterion to maximize Net Profit. Net Profit is a total profit/loss the strategy produced.

Drawdown, % Drawdown criterion to minimize Drawdown or Percentage Drawdown of a strategy. Drawdown is the measure of the decline from a historical peak in running cumulative profit of the strategy.

Number of trades simply a number of trades of this strategy in the backtest. You can use this criterion to approximate

52

Genetic Builder User's Guide


some preset value you would like to achieve (for example total 100 trades ). The value of this criterion will be bigger for strategies closer to the desired number of trades. Stability a special value in range from 0 (worst) to 1 (best) that measures how stabile is growth of the equity chart.

You can see three sample strategies on the picture above. All of them finished with the same profit, but Strategy 1 was growing almost linearly (very stabile), Strategy 2 was growing with occasional big drawdowns (less stabile) and Strategy 3 was moving up and down (very little stability of growth). Stability is a value that is quite good in representing a "quality" of the trading strategy and it can be used as the only one or the main criterion to compute the total strategy Fitness.

Symmetry criterion to maximize strategy symmetry. Symmetry value is in %, and it is measuring how much is the Profit/Loss for Long direction similar to Short direction. For example, if strategy makes $600 on Long trades, and $400 on Short trades, symmetry in this case is 66%. ($400 is 66% from $600). If the strategy makes the same profit on both directions, the symmetry will be 100%. If one of the directions produces loss or 0 profit, the symmetry will be 0%.

Win/Loss Ratio criterion to maximize the ratio of winning trades vs. losing ones

Return/DD Ratio criterion to maximize the ratio of Net Profit vs. Drawdown

Average Win, Average Loss criterion to maximize average win or minimize average loss per trade

Average Bars in Trade criterion to minimize the average number of bars the trade is open

53

Genetic Builder User's Guide

Average Bars Win, Average Bars Loss criterion to minimize the average number of bars for the winning/losing trade

4.3.5.3 Fitness Computation Options Sometimes one strategy can have its Fitness value much bigger than Fitness values of the rest of the strategies in the population. This strategy would get an unfairly high abundance in the population - because strategy with better fitness has bigger probability to get to the next generation, and the its chance is proportional to the fitness. With too big difference in fitness values, also the chance of selecting this one particular strategy is too high. In extreme case this could lead to a population consisting of on only clones of one strategy. Normalization can protect us from this, it acts as a "brake" for the evolution pressure. It can recompute the fitness values in the population with given coefficient and reduce the range between best and worst fitness. With smaller difference between best and worst candidates, no candidate would get too high abundance in the new generation. The higher Normalization coefficient is, the smaller is the evolution pressure and the strategies will be selected to the next generation less aggressively.

54

Genetic Builder User's Guide

4.4 Results tab


Results tab is the place where you can see and review the generated strategies.

The screen is divided into two separate areas. On the bottom there is a Databank, above is the Result Details window.

55

Genetic Builder User's Guide


4.4.1 Databank

Databank is a storage place where the generated strategies are stored in all the program modes.

4.4.1.1 Databank tab

Each row in the table represents one strategy, the results of the strategy backtest - number of trades, total profit/loss, Fitness score, etc. are visible in the table columns. Results are divided into In Sample and Out of Sample parts. For memory reasons Databank cannot keep unlimited number of strategies, instead it stores the selected number of top strategies, for example top 100 or top 1000 strategies. Every strategy result in the Databank can be viewed in the Details screen above by using double-click. You can also export the whole table content to a CSV file or edit the strategy trading rules using Strategy Editor. The configuration how many strategies to store in the Databank and how to sort them can be set in the Settings tab -> Strategy Ranking Options Screen -> Databank Options.

4.4.1.2 Last generation tab It is a special tab that is visible only if you switch to Genetic Evolution mode.

This new tab contains the last generation of strategies made by the genetic evolution. In evolution our goal is to produce new strategies that are also better than the initial population. We can say genetic evolution can have two results (groups of generated strategies):

56

Genetic Builder User's Guide


1. the latest generation of strategies - they are the product of the evolution. Theoretically every generation should be better than the previous one, so the latest generation should be the "best". These last generation strategies are stored into Last generation tab. 2. the best strategies across all the generations - in practice, evolution process is random and it can sometimes throw away very good strategies. Databank tab is used to store the top strategies across all the generations created during the genetic evolution.

Note
It is possible for strategy from the Last generation to be also in the Databank tab, if it belongs to the top strategies overall. The Last generation tab is not visible in Random Generation or Strategies Testing mode because they don't work with evolution.

4.4.1.3 Working with Databank results The strategies stored in the Databank are stored only in the program memory and they will be lost when the program is closed. To avoid this you can save them to files.

There are several actions you can do with the strategies stored in Databank. Double-clicking on a strategy will open it in the Result Details window, which will be described in the next chapter. Load button - loads existing strategies (*.str files) that were previously saved. This allows you to review their backtest results again, or retest them on a different symbol, timeframe or period using the Strategies Testing mode. Save button - saves selected strategies into the files Edit button opens the strategy in a Strategy Editor so you can edit its trading rules Delete button - removes the selected strategies from the table Clear all - removes all strategies from the table, leaving it empty

57

Genetic Builder User's Guide

Strategies File Format


Strategies saved from Databank using the Save button are stored in a proprietary file format (.str extension) used by Genetic Builder. This kind of file can be opened only by the Genetic Builder. If you want to save your strategy as a MetaTrader source code you can do it in the Result Details window described in the next chapter.

58

Genetic Builder User's Guide


4.4.2 Result Details

To review any strategy simply double-click on it, it will load the strategy results into the Result details window.

4.4.2.1 Overview tab Overview is the first tab in the results. It gives us an overview of the strategy performance, note that the results can be switched between Long and Short sides, and In Sample and Out of Sample periods.

On the bottom there is an area for warnings. Some of the strategies can contain possible flaws in the strategy design recognized by Genetic Builder and a warning is displayed for such strategy.

59

Genetic Builder User's Guide


4.4.2.2 List of trades tab This tab contains list of all the trades made by the strategy, including expired Limit and Stop orders. You can see the exact time & price of entry and exit and type of the order.

4.4.2.3 Equity chart Equity chart is simply a line chart of equity displaying the profit / loss of the actual strategy. Again, it can be switched between Long and Short sides.

60

Genetic Builder User's Guide


4.4.2.4 Source code In Source code tab you can view the actual rules of the strategy. There are currently two Source code types: Pseudo Source Code displays the trading rules in a simple text description. It can be used to review the details of the strategy or to trade the strategy manually.

MetaTrader 4 Expert Advisor (*.MQ4) displays the full source code of the trading strategy in the MQL (MetaTrader 4) programming language.

61

Genetic Builder User's Guide


This MetaTrader source code is a complete code for the MT4 Expert Advisor. You can save the file to the /experts directory of your MetaTrader installation and you'll be able to compile the strategy into a standard EA.

62

Genetic Builder User's Guide

4.5 Strategy Editor


Strategy Editor is a simple but quite powerful wizard that allows you to edit the strategies generated by Genetic Builder, or create your own ones. To create new strategy, go to menu File -> Create strategy or click on the plus icon on the toolbar. To open existing strategy just select it in the Databank and click Edit.

The Strategy Editor will be opened in a new window. The Editor is simple and intuitive, so theres no big help needed.

Genetic Builder strategies have a fixed format, and editor matches this format with 4 tabs, for Entry Long, Entry Short, Exit Long (if we want to close the trade using some rule other than Stop Loss or Profit Target) and Exit Short. Each tab has IF and THEN part in the IF part you define the conditions, and in the THEN part you define what should happen once the conditions are true.

63

Genetic Builder User's Guide

5 How To...
5.1 Export strategy from Genetic Builder and test it in MetaTrader
When you generate some strategies and find the ones you would potentially like to use in real trading, it is time to test them in MetaTrader.

Genetic Builder normally saves strategies in its own proprietary .str file format, which is nor readable by MetaTrader. In order to test strategies in MT4 you have to export its source code in MQL format This is simple, go to Results and find the strategy you want to use in the Databank. Double-click on it, which opens it in the Result details window above the Databank.

64

Genetic Builder User's Guide


There, go to Source code tab and switch the source code to MetaTrader4 Expert Advisor. This will load the MT4 code of the strategy.

Click on Save to file button, and in the file dialog find the folder where your Metatrader is installed (for example C:\Program Files\Alpari MT)

In this folder you have to go inside the experts directory and save the strategy source code there. So the full path of the file will be for example C:\Program Files\Alpari MT\experts\New_Strategy_0.137.mq4

65

Genetic Builder User's Guide


Now the strategy is copied to Metatrader. You can open MetaTrader now. In Metatrader go to menu Tools -> MetaQuotes Language Editor, or press F4. This will open the language editor. On the right side of the editor you'll have a list of strategies that are in the experts folder. Double-click on our strategy to open it in the editor window and then click on Compile on the top toolbar.

The strategy will be compiled and now it is ready for backtest or running live.

Note - Compilation warnings are normal


Please note that there are some compilation warnings on the bottom. These warnings are normal and they don't influence the strategy work. There are simply some functions that are not used in the strategy and Metatrader is informing you about that. Now that the strategy is compiled , it is ready to be backtested. You can close the MetaEditor, go to the main Metatrader screen and open Strategy Tester.

66

Genetic Builder User's Guide

This will open the Strategy Tester dialog on the bottom and you can run the backtest.

Make sure you select the correct Expert Advisor, Symbol, Timeframe and Date From and To and then click on the Start button. The test will start and after a while you'll get the results.

Explanation of small differences in backtests


If you'll compare test results in Genetic Builder and in Metatrader, you'll see that on some cases the backtesting results are not the same. The results can differ slightly or significantly depending on the type of strategy. Backtesting algorithm used in Genetic Builder is very accurate, but it is not exactly the same algorithm used in Metatrader.

67

Genetic Builder User's Guide

5.2 Import history data from Metatrader


Step 1: Export data from Metatrader Open your Metatrader and go to Tools -> History Center.

There, open the currency you want to export (for example GBPUSD) and double click on 1 Minute (M1) so that it is refreshed on the right side of the screen. Then just click on the Export button and choose your destination file.

Note
Genetic Builder supports import of only 1 Minute data, it will compute the higher timeframes automatically. Now we have the data ready to be imported to Genetic Builder.

68

Genetic Builder User's Guide


Step 2: Create a new symbol in Genetic Builder We can import data to already existing symbol, but that will overwrite its data, so it is better to define a new symbol. Start Genetic Builder, go to Data screen, Manage History Data and click on Add symbol.

Fill out the symbol and full name, check the default spread and tick value. Remember that if you are importing JPY based pairs (USDJPY, GBPJPY, etc) the correct tick value is 100 (instead of 10,000) and decimal places rounding will be 3 (instead of standard 5). Click OK and the new symbol will be created. The symbol doesn't have any data yet, but we are going to import them in the next step.

69

Genetic Builder User's Guide


Step 3: Import data to Genetic Builder Now check the row with the symbol and click on Import data ... button on the top. This will open the import dialog. Import dialog is configurable; it allows to import data from various file formats. Since we use data from MetaTrader, choose MetaTrader4 as a Predefined File Format.

Choose the data file and click on Start Import button. This will start the import process. It could take few minutes, depending on speed of your computer and data size. When the import is finished it will display information window and asks you to close the dialog.

Now we have the new data successfully imported into Genetic Builder and we can use them for tests or new strategies generation.

70

Genetic Builder User's Guide

5.3 Importing tick data from MetaTrader


Since version 2.0 Genetic Builder supports tick data. We can use this feature to import tick data from MetaTrader instead of importing standard minute data.

Note
Tick data in MetaTrader are not real tick data - they are a result of tick simulation that MetaTrader performs on 1 minute data. The advantage of importing tick data from MetaTrader to Genetic Builder is that then GB can perform tests using the same tick simulation as MT4, which means well get exactly the same test results in both programs.

Unlike standard history data, tick simulation data cannot be exported from MT4 History Center. Instead well use a small trick and export the data using a special simple EA called GenBuilder_TickDataExportEA. This simple EA ships with Genetic Builder, you can find it in {Genetic Builder installation directory}/custom_indicators/mq4/ directory. In order to use it in your MetaTrader you have to copy it to: {MetaTrader installation directory}/experts Then restart your MetaTrader and the new EA will be available.

Step 1: Getting the tick data from MetaTrader In MetaTrader open Strategy Tester (View -> Strategy Tester) an din the list of Expert Advisors find our TickDataExportEA.

You then have to set also: symbol that you want to export (for example AUDUSD) period must be M1 check Use date and set date From and To to your desired data interval

After this click on Start button and the export will begin. The export could take several minutes, so wait until it finishes successfully.

71

Genetic Builder User's Guide


The EA will go through all the data history and write generated ticks to a file. This file can be located in {MetaTrader installation directory}/tester/files

Next steps: Importing the data to Genetic Builder The next steps are as same as in the case of importing minute data. You have to create a new symbol and then import the new tick data for this symbol. Please refer to the previous chapter on the description of these steps. The only difference is that our data file has different format, so we should choose MetaTrader tick export format as a Predefined File Format.

72

Genetic Builder User's Guide

5.4 Importing custom indicator from MetaTrader to GB


Custom indicators are a new feature in GB version 2.0. To say it simply, they allow GB to use indicators that are not build-in the program. This allows you to use virtually any of your favorite indicators inside Genetic Builder as standard building blocks, including complicated ones that use multi-timeframe or multi-symbol analysis.

Note
Custom indicators are computed in MetaTrader, not in GB. To get the correct results you have to use the same history data in both GB and MT4. It will not work to compute your custom indicator in MetaTrader with your broker data and then use them in Genetic Builder on data from other source. Before using custom indicators, synchronize your history data so that both GB and MT4 use the same history.

5.4.1

Step 1 - Getting the indicator values from MetaTrader

Custom indicators work in a way that Genetic Builder uses their values computed in another program, for example in MetaTrader. This means we have to compute the indicator in MetaTrader and then import its value(s) to GB. This is little bit complicated, but on the other hand it allows us to use virtually any indicator available for MetaTrader, even if we dont know how exactly it is computed. For computation of indicator values well use a simple EA called GenBuilder_IndicatorExportEA This simple EA ships with Genetic Builder, you can find it in {Genetic Builder installation directory}/custom_indicators/mq4/ directory. In order to use it in your MetaTrader you have to copy it to: {MetaTrader installation directory}/experts Then restart your MetaTrader and the new EA will be available. Well need to open the EA and modify its code a little. Open the MetaQuotes Language Editor from Tools Menu.

73

Genetic Builder User's Guide


This will open the editor that will allow us to modify the EA.

Now find the IndicatorExportEA on the right and double-click on it, this will open the EA in the editor screen. The only thing we have to change in the code is a command that gets the value of the indicator and that writes the value to the file. The code looks like this:
value1 = get indicator value 1 bar ago FileWrite(handle, TimeToStr(Time[1], TIME_DATE),TimeToStr(Time[1], TIME_MINUTES), Close[1], value1);

The code is simple, all it does is it gets the value of the desired indicator and then saves the value to the file. So, to export your own indicator just change the code that gets the indicator value. Example 1 exporting value of standard MT4 indicator, such as Bears Power
value1 = iBearsPower(NULL, 0, 13, PRICE_CLOSE, 1); FileWrite(handle, TimeToStr(Time[1], TIME_DATE),TimeToStr(Time[1], TIME_MINUTES), Close[1], value1);

Example 2 exporting custom indicator from MT4 To get the value of custom indicator in MT4 we have to use the call iCustom(symbol, timeframe, name, parameters, mode, shift) where symbol and timeframe can be left to NULL, 0 to get the actual symbol and timeframe name is the exact name of the custom indicator parameters are indicator parameters separated by comma mode is a line index it can be from 0..7 and it is usually used if indicator returns more than one value shift must be always 1

74

Genetic Builder User's Guide


So for example for Keltner Channel well have the code:
value1 = iCustom(NULL,0, "KeltnerChannel", 20, 1.5, 2, 1); FileWrite(handle, TimeToStr(Time[1], TIME_DATE),TimeToStr(Time[1], TIME_MINUTES), Close[1], value1);

where 20 and 1.5 are the parameters of Keltner Channel indicator and 2 is the line index we want third value of the indicator (index is zero based) that corresponds to the bottom of Keltner Channel.

Example 3 exporting multiple indicator values at once - Ichimoku Tenkan Sen and Kijun Sen it is possible to import multiple indicator values at once, to do this simply use variables value1value6. And dont forget to add all these values also to the FileWrite function.
value1 = iIchimoku(NULL, 0, 9, 26, 52, MODE_TENKANSEN, 1); value2 = iIchimoku(NULL, 0, 9, 26, 52, MODE_KIJUNSEN, 1); FileWrite(handle, TimeToStr(Time[1], TIME_DATE),TimeToStr(Time[1], TIME_MINUTES), Close[1], value1, value2);

First two lines compute different values of Ichimoku indicator and the third line saves them to the data file. After we finished altering the code we can click on the Compile button on the top and indicator should successfully compile.

75

Genetic Builder User's Guide


5.4.2 Step 2 - Exporting the indicator values from MetaTrader

Now we have the export indicator ready and we can use it. In MetaTrader open Strategy Tester (View -> Strategy Tester) and in the list of Expert Advisors find our GenBuilder_IndicatorDataExportEA.

Now you have to set also the symbol you want this indicator to be computed on and timeframe. Check also Use date and set date From and To. After this click on Start button and the export will begin. The export could take several minutes, so wait until it finishes successfully. The EA will go through all the data history, computes indicator value for every bar and write generated ticks to a file. This file can be located in {MetaTrader installation directory}/tester/files

Note
Indicator will have different values for every symbol and every timeframe so you should export it for every symbol and timeframe combination that you want to use in Genetic Builder. To do this, just repeat this Step 2 and choose different symbol or timeframe. Dont forget to rename the exported values file before every export, because otherwise the new values will be added to the end of the file which will make it unusable. Simply go to the /tester/files directory and rename the export file CustInd_XXX.csv to something else (for example MyIndicator_GBPUSD_M15.csv) before running the export again.

76

Genetic Builder User's Guide


5.4.3 Step 3 - Create new custom indicator in Genetic Builder

After we successfully exported indicator values to a file we have to create a new custom indicator in Genetic Builder. Start Genetic Builder, go to Data screen, Manage Custom Indicators and click on Add custom indicator.

Fill out the custom indicator name and choose which symbol and timeframe it was generated for. Remember, custom indicator values are always computed relative to a symbol and timeframe. In this example we used symbol EURUSD_fhdb and M15 timeframe. Then choose the indicator values type. It can be either: Number - if it is indicator such as CCI, RSI, MACD etc. If the indicator is an oscillator (which means that its value oscillates around some number, like CCI oscillates around 0) then set this middle value to the dialog field. Otherwise set it to 0. Price - if the indicator value is price, like moving average or Bollinger Bands. Price range if the indicator value is price range (difference between two prices), such as ATR or Bollinger Bands Range. Boolean if the indicator returns true/false values (zero/nonzero in our case). You can have boolean indicator for example to recognize candle patterns or to implement your own simple trading rules.

77

Genetic Builder User's Guide


How to decide - generally, if the indicator draws on the same chart as price, then its return type is price. If it draws its lines into a separate window below the main chart then it is Number, with the exception of special indicators like ATR that compute some kind of price difference or range. Click OK and the new symbol will be created. The symbol doesn't have any data yet, but we are going to import them in the next step.

5.4.4

Step 4 - Import indicator values to Genetic Builder

Now check the row with the new custom indicator and click on Import data ... button on the top.

Choose the data file on the top for this you have to go to {MetaTrader installation directory}/tester/files and find the file that was exported in the previous step. The importer then loads first few rows of the file and youll be able to specify the column types. Indicator file can contain several columns with indicator values, in our example we have only one column. For every indicator column used you have to specify indicator code it is the code that was used to generate the indicator values. This code is used by Genetic Builder when it generates the source code of the strategy in MQL code.

78

Genetic Builder User's Guide


Lets assume our custom indicator was Bears Power computed as in our Example 1, and then the indicator code would be: iBearsPower(NULL, 0, 13, PRICE_CLOSE, _BARSBACK_) Please note that we replaced the last parameter with the _BARSBACK_ constant. It is because Genetic Builder would need to define correct number of bars on which this indicator should be computed. _BARSBACK_ constant will be replaced by shift (or bars ago) in the generated MQL code. Now click on Start Import and the import engine checks and imports new custom indicator.

5.4.5

Step 5 - Use the custom indicators

Now that we successfully created and imported new custom indicator we can use it in generation of the new strategies. Make sure that your data for backtest are set for the right symbol and timeframe

Remember, we defined this custom indicator for EURUSD_fhdb symbol and M15 timeframe; it will be not available on another symbol or timeframe.

79

Genetic Builder User's Guide


Now we can go to Settings -> Building blocks and well see our newly defined custom indicator there.

If we want to use it in the strategies, we just have to check it and perhaps set its weight to configure the probability how often it will be used in the strategies. Thats all, now when we start the building process, our new custom indicator will be used just like any other build-in indicator in the newly generated strategies.

80

Genetic Builder User's Guide

5.5 Running reliable backtests in MetaTrader 4


Backtesting allows you to simulate trading over a long period of time in just minutes. Accuracy of MetaTrader Strategy Tester We should realize that backtest cannot be 100% accurate. At best, backtesting offers a close approximation of how trades would be executed in real-time. There are things like widened spreads, requotes, slippage and time delays that affect live trading. The lower timeframes you want to test, the bigger the inaccuracy. It makes sense to rely on the tests only on timeframes from 15 minutes up. 1 min and 5 min timeframes are too small, and the approximations and errors of Strategy Tester would greatly affect the results. It also doesn't make a big sense to test scalping strategies that go only for a few pips. This doesn't mean that such strategies cannot work, it just means that they cannot be accurately tested in Strategy Tester.

History Data
Before backtesting or optimizing, it's important to make sure that your history data is complete and accurate, especially if you're using 'Every tick' as your testing model. If you see 'mismatched chart' errors in your Journal log or if your modeling quality is less than 90%, your history data is insufficient to generate accurate ticks. The data for all currency pairs are managed in History Center. Open the Tools History Center. This will open the History Center window. Double click on a currency pair on the left that you want to backtest for. A list of time periods will appear below the currency. Start by double clicking on 1 Minute (M1) to load the history data for that period. The backtester uses M1 data to generate ticks, so it is important that your M1 data is complete.

81

Genetic Builder User's Guide

You can use the History Center to download the data for backtesting. Your broker automatically provides some recent data, but it might be not enough for backtesting. The easiest way to get the historical data is downloading them from MetaTrader (using the Download button). Be aware that such data is not always complete and can contain large gaps. If you need accurate data with no gaps, there are several data providers. ForexHistoryDatabase.com is one of them. Such data are not free, but you can rely on their quality.

Disconnecting from the broker


This is often a neglected point, but if you want to have reliable backtests you have to disconnect your MetaTrader from a broker. Why is it necessary? It is because even if you are running tests on historical data, MetaTrader uses the actual spread of the given currency pair. And the spread of a pair is continually changing every few seconds, even if only by 0.1-0.5 pips. So if you'll run the test now and then the same test in 5 minutes, you'll most probably not get exactly the same results, because the spread changed a little in the meantime and that affected the test results.

Note
There are some brokers (for example Alpari) that widen their spreads significantly during weekends. This means that running your backtest during a weekend will give you much worse results than running the same test during normal weekday. If you want to run your backtests also during the weekends and/or you want to get 100% comparable results, you have to run your tests with the same spreads and this means with MT4 disconnected from the broker. If you disconnect your MT4 from a broker, it will keep the same spreads as it had before you disconnected it (so it is not recommended to disconnect MT4 during weekends), and as a result your tests will return the same results every time you run them. It is a good practice to have two different MT4 installations:

one for live trading one for backtesting and optimization, disconnected from the broker

82

Genetic Builder User's Guide


How to disconnect the MetaTrader4 First of all, the MetaTrader must be online and connected at least for a while, so that it loads the actual spreads. Then you can disconnect it by setting proxy to some dummy value. Go to Tools Options, Server tab and check the box Enable proxy server.

Then click on the Proxy button to set up the proxy.

Put localhost as a Server, and some dummy text into Login and Password. Close the dialog by clicking on OK and close the Options dialog by clicking on OK button again, this will save your settings. Now you have to restart MetaTrader again and next time you'll start it you'll be disconnected from the broker. You should see No connection status on the bottom right corner of MetaTrader.

From now on all your tests will be run with the same spreads, and the results will be the same every time you run the test.

83

Genetic Builder User's Guide

6 Final Words
Congratulations on completing the guide to Genetic Builder. I hope you'll like the program and you'll use it as an important part of your trading. Genetic Builder is very new program, and it is underactive development. This means you can look forward for new exciting features that will move the program functionality even further. I'm open to a new ideas or suggestions, so if you are missing something in Genetic Builder or if you think something can work in a different way, don't hesitate to let me know.

I wish you many successful trades, Mark Fric P.S. I would love to hear your success stories, so please let me know at mailto:support@geneticbuilder.com

P.P.S. I would also appreciate testimonials, or if youll recommend my system to a friend

84