Verb Guide to EA Optimization!

Results 1 to 4 of 4
 0 Attachment(s)    

Thread: Verb Guide to EA Optimization!

  1. #1
    Junior Member
    Join Date
    Jan 2009

    Smile Verb Guide to EA Optimization!

    I have decided to write an article on this topic. It's on my blog also: Step by Step Guide to Optimizing an Expert Advisor! : verbtheory trading blog

    I hope you find this helpful, 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.

    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: MQL4 Articles: strategy tester.

    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!
    Last edited by verbtheory; 06-09-2009 at 17:30.
    -David T-
    Skype: verbtheory
    Trades and insights:
    Verbtheory's Day Break System v1.0
    "Only when the tide goes out do you discover who's been swimming naked." - Warren Buffett

  2. #2
    Senior Member
    Join Date
    Jan 2009


    Thanks for the information, i will put it to good use

  3. #3
    Junior Member
    Join Date
    Jan 2009


    Thanks! I've made a small update. Will add more to it as I go along.
    -David T-
    Skype: verbtheory
    Trades and insights:
    Verbtheory's Day Break System v1.0
    "Only when the tide goes out do you discover who's been swimming naked." - Warren Buffett

  4. #4
    Junior Member
    Join Date
    Jan 2009


    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.

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

    -David T-
    Skype: verbtheory
    Trades and insights:
    Verbtheory's Day Break System v1.0
    "Only when the tide goes out do you discover who's been swimming naked." - Warren Buffett

Similar Threads

  1. Economic Indicators guide
    By painofhell in forum Trading discussion
    Replies: 0
    Last Post: 08-19-2014, 23:39
  2. ForexWonder User Guide?
    By ChuckNZ in forum Commercial expert advisors
    Replies: 1
    Last Post: 03-25-2012, 16:22
  3. VPS Guide to MT4
    By funyoo in forum Virtual private server
    Replies: 13
    Last Post: 09-07-2010, 14:26
  4. Need some EA guide...
    By ApacheDan in forum Ideas for expert advisors
    Replies: 4
    Last Post: 04-22-2010, 11:15
  5. Newbie Guide: How to use EA
    By fairylord in forum Expert advisors backtesting
    Replies: 10
    Last Post: 09-26-2009, 16:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Verb Guide to EA Optimization!

GadgetVersus GadgetVersus France W3Ask W3Ask Brasil W3Ask Deutschland W3Ask España W3Ask France W3Ask Italia W3Ask Nederland