Forex Nirvana Forum - Helping you reach forex enlightenment

Verb Guide to EA Optimization!

This is a discussion on Verb Guide to EA Optimization! within the MetaTrader 4 Backtesting & Optimization forums, part of the Automated Trading Systems (Expert Advisors) category; In preparation for the Quik DBS EA, I have decided to write an article on this topic. It's on my ...






Free Downloads: 14 Critical Lessons Every Trader Should Know & Learn Elliott Wave Analysis

Sponsors

Forex VPS



Forex Brokers









Go Back   Forex Nirvana Forum - Helping you reach forex enlightenment > Automated Trading Systems (Expert Advisors) > MetaTrader 4 Backtesting & Optimization

The Path to Forex Enlightenment


MetaTrader 4 Backtesting & Optimization Discussions related to backtesting and optimization of expert advisors for the MetaTrader 4 platform.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-06-2009, 07:35 PM
verbtheory's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Seattle, WA
Posts: 550
Thanks: 46
Thanked 119 Times in 56 Posts
Thumbs up Verb Guide to EA Optimization!

In preparation for the Quik DBS EA, I have decided to write an article on this topic. It's on my blog also: http://www.manualforextrader.com/for...3&t=73&start=0

Enjoy!

Ever wondered how to optimize an EA?

There certainly are a lot of brains on this planet and I'm sure there are better ways that others have devised but I havent found them readily available or they are not willing to share so...

Here's how I go about the basics of optimizing, backtesting and why.

In general, the idea is to get the profit maximum up. Next step is to optimize trade management variables like breakeven, targets and trailing to increase profit factor while reducing drawdown.

We will utilize control points to get a rough idea of optimization then use every tick to test our results from control point testing. This will enable us to get faster results as every tick modelling is VERY slow.

Setup
Make sure your expert is loaded into your metatrader/experts folder.
Make sure any indicators that the EA uses are in your metatrader/experts/indicators folder.

Goto Tools -> History Center and double click the symbol you want to test. Double click on M1 and download the data. Hit Ok at any prompts and recalculate. Double-click on each of the periods and it will recalculate all of them. Important step. This way you will have all of the data you need to test. It's a good idea to go into your metatrader folder and delete any .HST files you may have before doing this to ensure your data quality is acceptable.


Open up a chart and drag the EA from the navigator in metatrader onto the chart.
Hit F6, this will bring you to the strategy tester and it will look like this:





Choose the correct period for your EA and the symbol you wish to test.
Choose a date range to test with. Start with a small date range at first. It is much easier to optimize a small range to get an idea of how the EA could react in a bigger date range. It will help the optmization process move much faster. Start with 6 months then expand to one year, two years and so on in subsequent runs.
Select the "Expert properties" button and proceed to optimization steps.

Optimization Steps
Let's start with maximizing our profit!
Using default entry parameters, take off all trade management like breakeven, first targets, etc. Turn them all off.
Select Stop Loss and Take Profit
Enter basic value for stop loss and take profit then increment them by 5 all the way up to say 1000.

Example below, notice how you check the box then enter start (will start testing at), step (how much to increment by) then Stop (test up to)


Make sure to choose the Optimization tab and check mark the Profit box. That way it will test for maximum profit.


Additionally switch over to the Testing tab and enter your starting balance. Depending on the trading strategy this will be critical. I usually start with 10,000 in the balance. Hit OK.

Check the "Optimization" check box.


Hit the start button. It should look like the picture below. Notice how many passes it's going to test... lol. Might as well go get some lunch this is going to take awhile.


As the tester progresses through each pass, it will report back any profitable passes in the "Optimization Graph" and "Optimization Results" tabs. What I do is use the graph (right click in the graph and deselect 2D surface) to watch the optimization process and wait for the results. Looking at the graph helps me see the highest profit gains first then switch to the "Optimization Results" and sort by profit to see progress.

Here is an example:

3:1 reward to risk???? drooooool.

The tops represent the highest profit gained, then I switch to results and sort by Profit:


Once all of the passes have completed, I can examine the tester results that look interesting to me. By right clicking and on the result I want, I can now set that as the input parameters to test the with.

Ooooo... 1.31 profit factor with 9.34% drawdown! :P

Now it's time to test these crude results with 90% modelling quality and see how they react.

Go back out to the settings tab and uncheck the "Optimization" box. Select the "Model" dropdown box and choose "Every tick..". This will show us an accurate picture of how the EA will react to historical market conditions. By downloading the History of the symbol to be traded, the quality will be about 90%. Of course, data feeds are all over the place so this is really just a best guess.

Usually in the beginning of testing, I like to watch the trades as they progress so I check mark the "Visual mode" box and adjust the slider for the speed at which the chart will scroll. This way I can get an even better feel for how things might react.


Hit start and there you have it! A new chart will appear and the trades will get logged for you to watch and ponder how to reduce drawdown and maximize profit.

After watching the trades you get a sense for how and where you might take profit, set targets or even start trailing. You can even pause the test in real time by hitting the pause button and measure things out to devise some trade management strategies. Here is an example:


Reducing Drawdown & Increasing Profit Factor
Since there are so many combinations that are possible when it comes to trade management, it would be better to throw these things into the tester and have it optimize for us.

Simply follow the steps above for optimizing stop loss and take profit BUT only do it for the trailing stop, breakeven and targets.
Select control points for modelling quality again.
Check mark the "Optimization" box and hit start.
Analyze the results, pick the best one and set that as the input.
Test using "Every tick" modelling and check out the results.

Rinse & repeat until you have acceptable settings!

Now remember there are many trading strategies out there. For example, basket trading cannot be fully automated in backtesting on Metatrader but you can test individual pairs and accumulate their results then run it in excel. Just a caveat for you.

I'm going to end it here as this has been long enough of a read. I hope you have found this helpful and definitely know this isnt the A-Z guide but should get a majority of people ready to optimize and backtest!

Additionally, there are many great resources out there on backtesting that I'm sure folks will tag onto. I'll add them here on the first post but here's a good one to start with: http://articles.mql4.com/tester.

UPDATES:
Make sure to set maximum profit to 999999 or else you will limit the amount of profit it will optimize for lol. See below.


Enjoy and Ciao for Now!
__________________
-David T-
Verbtheory Trading Journal
-----------------------------------------------
When time is short, timing is everything.
In such an environment, technical analysis comes into it's own.

Last edited by verbtheory; 06-09-2009 at 12:29 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 3 Users Say Thank You to verbtheory For This Useful Post:
ansana (08-17-2009), jrbucks (10-25-2009), Seanmcgu (08-04-2009)
Sponsored Links
  #2 (permalink)  
Old 06-06-2009, 08:56 PM
verbtheory's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Seattle, WA
Posts: 550
Thanks: 46
Thanked 119 Times in 56 Posts
Lightbulb

Brainwork Section 1.0

So I have been giving additional thought to optimization. The standard theory is if you optimize for a longer period of time, you will gain settings that could conceivably yield consistent gains.

I would like to challenge this thinking. By posing some questions.

1 - When trading, does one size fit all?
2 - Is one month like the next?
4 - Is it possible that by optimizing for the last 10 years that you can predict your next 10 years?
5 - Can backtesting account for news events, holidays and major financial events (tax day? ring a bell?)

If you can answer emphatically, YES to all of these questions then this isnt written for you.

I think it's pretty clear that traders must be dynamic in the way that they trade. After all this is a competitive market place and even though on this forum we do help each other, institutions are out to get us!

Here are a couple of things I've been kicking around:

- Quarterly & Monthly Optimization
If it's good enough for the business world, it's good enough for us. In my day job, I forecast monthly and we make corrections and modify our actions to counter what's happening in the market. The banks are the major traders in FOREX. Guess what? They are a business. What do you think they do?

- Backtesting in chunks to avoid major events
For example, would you trade Jan 2nd or 3rd?? NOT ME. Although I'd be tempted, that is sheer lunacy. There's got to be a buffer for the trading world to return to some semblance of normalcy if such a thing exists. If we add a buffer before and after major holidays and events, we can remove most likely unprofitable days depending on the strategy you employ. What about Tax day in the US??? Does anyone notice that many systems get thrown off in April & May? Could it be that economic news will be driving these periods. At any rate, I wonder what would happen if you tested around these periods.

A rough estimate (forgive me for being so US centric):
Jan 01 - New Year's Day
Jan 19 - Martin Luther King, Jr (govt holiday)
Jan 26 - Chinese New Year
Feb 16 - President's Day (govt holiday)
Apr 01 - April Fools (it just sounds risky!)
Apr 09 - Passover
Apr 10 - Good Friday
Apr 15 - Tax Day (US)
Apr 19 - Easter
May 25 - Memorial Day
Jun 14 - Flag Day (govt holiday)
Jun 30 - Last Fiscal Year Day for many corporations and businesses
Jul 04 - Independence Day
Aug 22 - First Day of Ramadan
Sep 11 - A very bad day in history.
Sep 18 - Rosh Hashanah
Oct 12 - Columbus Day
Oct 12 - Thanksgiving (Canada!!!)
Nov 11 - Veterans Day (govt holiday)
Nov 26 - Thanksgiving
Dec 12 - Hanukkah
Dec 25 - Christmas Day
Dec 26 - Kwanzaa
Dec 30 - Last Fiscal Year Day for the rest of the Corporations and businesses
Dec 31 - New Years Eve
------------------------
25 DAYS!

And that's pretty much just North America! FOREX is global to backtest and optimize volumes from countries who take the day off??

Let's do the math... 25 days out of 365 days that you shouldnt trade. Let's take Fridays through Saturday off too! 52 x 3 = 156 no trade days???? I know some of these intersect with the holidays but jeeeezus!

So out of 365 days, we have about 180 days to trade!!!! That doesnt count the number of news releases that occur which many should not trade if you rely on oscillation! You could easily reduce this number by 10-15% since news tends to drive markets nutty.

So I want to ask everyone again.

Is it important to backtest for an entire year??????

OMG, I need to stop now.

Resources:
Best Days of the Week to Trade
When NOT to Trade
Major Holidays of the World

Ciao!
__________________
-David T-
Verbtheory Trading Journal
-----------------------------------------------
When time is short, timing is everything.
In such an environment, technical analysis comes into it's own.

Last edited by verbtheory; 06-09-2009 at 06:21 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to verbtheory For This Useful Post:
PixeLM (03-08-2010), Seanmcgu (08-04-2009)
  #3 (permalink)  
Old 06-07-2009, 11:02 AM
thesecret's Avatar
Senior Member
 
Join Date: Jan 2009
Posts: 865
Thanks: 79
Thanked 222 Times in 80 Posts
Exclamation

Keep on mind.
__________________
-=Think outside of the box=-
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to thesecret For This Useful Post:
Seanmcgu (08-04-2009)
  #4 (permalink)  
Old 06-07-2009, 09:33 PM
Quiksilver's Avatar
Senior Member
 
Join Date: Mar 2009
Location: I'm out. Sorry
Posts: 754
Thanks: 33
Thanked 757 Times in 158 Posts
Lightbulb Great Thread !

Great thread verb!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-09-2009, 11:59 AM
verbtheory's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Seattle, WA
Posts: 550
Thanks: 46
Thanked 119 Times in 56 Posts
Default

I tried downloading data from collectivefx and it gives me the no new data available. So still looking for a nice data feed. I have heard that IBFX volume feed is pretty accurate however.

Quote:
Originally Posted by thesecret View Post
__________________
-David T-
Verbtheory Trading Journal
-----------------------------------------------
When time is short, timing is everything.
In such an environment, technical analysis comes into it's own.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-09-2009, 06:22 PM
verbtheory's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Seattle, WA
Posts: 550
Thanks: 46
Thanked 119 Times in 56 Posts
Lightbulb Should You Optimize for 10 years???

Brainwork Section 1.0

So I have been giving additional thought to optimization. The standard theory is if you optimize for a longer period of time, you will gain settings that could conceivably yield consistent gains.

I would like to challenge this thinking. By posing some questions.

1 - When trading, does one size fit all?
2 - Is one month like the next?
4 - Is it possible that by optimizing for the last 10 years that you can predict your next 10 years?
5 - Can backtesting account for news events, holidays and major financial events (tax day? ring a bell?)

If you can answer emphatically, YES to all of these questions then this isnt written for you.

I think it's pretty clear that traders must be dynamic in the way that they trade. After all this is a competitive market place and even though on this forum we do help each other, institutions are out to get us!

Here are a couple of things I've been kicking around:

- Quarterly & Monthly Optimization
If it's good enough for the business world, it's good enough for us. In my day job, I forecast monthly and we make corrections and modify our actions to counter what's happening in the market. The banks are the major traders in FOREX. Guess what? They are a business. What do you think they do?

- Backtesting in chunks to avoid major events
For example, would you trade Jan 2nd or 3rd?? NOT ME. Although I'd be tempted, that is sheer lunacy. There's got to be a buffer for the trading world to return to some semblance of normalcy if such a thing exists. If we add a buffer before and after major holidays and events, we can remove most likely unprofitable days depending on the strategy you employ. What about Tax day in the US??? Does anyone notice that many systems get thrown off in April & May? Could it be that economic news will be driving these periods. At any rate, I wonder what would happen if you tested around these periods.

A rough estimate (forgive me for being so US centric):
Jan 01 - New Year's Day
Jan 19 - Martin Luther King, Jr (govt holiday)
Jan 26 - Chinese New Year
Feb 16 - President's Day (govt holiday)
Apr 01 - April Fools (it just sounds risky!)
Apr 09 - Passover
Apr 10 - Good Friday
Apr 15 - Tax Day (US)
Apr 19 - Easter
May 25 - Memorial Day
Jun 14 - Flag Day (govt holiday)
Jun 30 - Last Fiscal Year Day for many corporations and businesses
Jul 04 - Independence Day
Aug 22 - First Day of Ramadan
Sep 11 - A very bad day in history.
Sep 18 - Rosh Hashanah
Oct 12 - Columbus Day
Oct 12 - Thanksgiving (Canada!!!)
Nov 11 - Veterans Day (govt holiday)
Nov 26 - Thanksgiving
Dec 12 - Hanukkah
Dec 25 - Christmas Day
Dec 26 - Kwanzaa
Dec 30 - Last Fiscal Year Day for the rest of the Corporations and businesses
Dec 31 - New Years Eve
------------------------
25 DAYS!

And that's pretty much just North America! FOREX is global to backtest and optimize volumes from countries who take the day off??

Let's do the math... 25 days out of 365 days that you shouldnt trade. Let's take Fridays through Saturday off too! 52 x 3 = 156 no trade days???? I know some of these intersect with the holidays but jeeeezus!

So out of 365 days, we have about 180 days to trade!!!! That doesnt count the number of news releases that occur which many should not trade if you rely on oscillation! You could easily reduce this number by 10-15% since news tends to drive markets nutty.

So I want to ask everyone again.

Is it important to backtest for an entire year??????

OMG, I need to stop now.

Resources:
Best Days of the Week to Trade
When NOT to Trade
Major Holidays of the World

Ciao!
__________________
-David T-
Verbtheory Trading Journal
-----------------------------------------------
When time is short, timing is everything.
In such an environment, technical analysis comes into it's own.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-14-2009, 03:10 PM
Senior Member
 
Join Date: Jan 2009
Posts: 319
Thanks: 6
Thanked 11 Times in 10 Posts
Default

Hey Verb, I was trying to use your method on Quick's new EA but I'm getting a lot of errors with Optimization checked... in point of fact it errors out and doesn't do anything Keeps saying it is discarding data. Any advice?
__________________
LMT Stats - http://madpoet1.mt4stats.com
Euro Blaster Stats - http://madpoet.mt4stats.com
Accurate Signal/MegaDroid/WSS - http://madpoet2.mt4stats.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-14-2009, 03:30 PM
verbtheory's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Seattle, WA
Posts: 550
Thanks: 46
Thanked 119 Times in 56 Posts
Default

Hey bud, did you delete all of your .hst files and re-download the history from history center?

Here is what my optimization incrementals look like for quik macd:







Perhaps if you could post a picture of the errors that would help.

Ciao!

Quote:
Originally Posted by madpoet View Post
Hey Verb, I was trying to use your method on Quick's new EA but I'm getting a lot of errors with Optimization checked... in point of fact it errors out and doesn't do anything Keeps saying it is discarding data. Any advice?
__________________
-David T-
Verbtheory Trading Journal
-----------------------------------------------
When time is short, timing is everything.
In such an environment, technical analysis comes into it's own.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-14-2009, 04:43 PM
Senior Member
 
Join Date: Jan 2009
Posts: 319
Thanks: 6
Thanked 11 Times in 10 Posts
Default

Ahhh... I wasn't messing with the steps. Yikes! How did you decide on those numbers?
__________________
LMT Stats - http://madpoet1.mt4stats.com
Euro Blaster Stats - http://madpoet.mt4stats.com
Accurate Signal/MegaDroid/WSS - http://madpoet2.mt4stats.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-14-2009, 04:55 PM
verbtheory's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Seattle, WA
Posts: 550
Thanks: 46
Thanked 119 Times in 56 Posts
Default

Nothing too scientific, I just tried to stay within minimum and maximum numbers that wouldnt take an incredibly long time to optimize. In this setup the TP & SL ratios are the ones that take a long time.

Quote:
Originally Posted by madpoet View Post
Ahhh... I wasn't messing with the steps. Yikes! How did you decide on those numbers?
__________________
-David T-
Verbtheory Trading Journal
-----------------------------------------------
When time is short, timing is everything.
In such an environment, technical analysis comes into it's own.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply

Bookmarks

Tags
forex, indicators, metatrader, mql, mql4, mt4, trade management, trading, trailing stop

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -5. The time now is 04:39 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2
Ad Management by RedTyger