Documente Academic
Documente Profesional
Documente Cultură
User's Guide
Version 2.1.0
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
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.
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
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!
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.
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
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.
11
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.
12
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
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
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
Custom Indicators Importing custom indicator from MetaTrader to GB Manage Custom Indicators
Strategy Editor
a new feature that allows you to edit or create a new strategy. More here: Strategy Editor
16
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.
17
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
19
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
Operators Greater Lower Crosses Above Crosses Below And Or Time Values Hour Minute
Day of Week
20
Enter at 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.
21
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
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
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
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).
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
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 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 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
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
28
We'll not start build process yet, we have to review the settings before that.
29
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
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
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
3.3.4
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
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
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
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
This screen is where you can manage (create, import, modify) the history data that are used for backtesting.
36
4.1.3
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
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
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
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
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
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
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.
43
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
44
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.
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
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
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
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
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
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
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
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.
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
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
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
The screen is divided into two separate areas. On the bottom there is a Databank, above is the Result Details window.
55
Databank is a storage place where the generated strategies are stored in all the program modes.
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
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
58
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
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
MetaTrader 4 Expert Advisor (*.MQ4) displays the full source code of the trading strategy in the MQL (MetaTrader 4) programming language.
61
62
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
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
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
The strategy will be compiled and now it is ready for backtest or running live.
66
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.
67
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
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
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
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
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
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
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
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
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
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
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
5.4.4
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
5.4.5
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
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
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
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.
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
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
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
84