Data Sources and Excel

To make statistical calculations we need to get some data. For the 5 minutes timeframe i will use data exported from the history center of the meta trader.

I will use the last 3 months of data for each pair,  here is a piece of data for the gbpusd pair:

2010.11.18 20:20 1.60325 1.6034 1.60286 1.60328 212
2010.11.18 20:25 1.6033 1.60367 1.60305 1.6033 206
2010.11.18 20:30 1.60326 1.60362 1.60325 1.60341 213
2010.11.18 20:35 1.60344 1.60348 1.60316 1.60345 197
2010.11.18 20:40 1.60344 1.60387 1.60344 1.60387 205
2010.11.18 20:45 1.6039 1.60467 1.60364 1.60453 189
2010.11.18 20:50 1.60453 1.60465 1.60413 1.60462 237
2010.11.18 20:55 1.60468 1.60482 1.60382 1.60434 285
2010.11.18 21:00 1.60438 1.6047 1.60435 1.6047 153
2010.11.18 21:05 1.60469 1.60491 1.60403 1.60426 221
2010.11.18 21:10 1.60424 1.60425 1.60387 1.60394 129

And here the same period for the euro usd:

2010.11.18 20:20 1.36205 1.36206 1.36139 1.36163 175
2010.11.18 20:25 1.36165 1.36222 1.36146 1.36211 109
2010.11.18 20:30 1.36211 1.36281 1.36211 1.36272 128
2010.11.18 20:35 1.36277 1.36335 1.36272 1.36315 168
2010.11.18 20:40 1.36315 1.36341 1.36294 1.36341 120
2010.11.18 20:45 1.36335 1.36405 1.36321 1.36371 196
2010.11.18 20:50 1.36367 1.36382 1.36316 1.36345 193
2010.11.18 20:55 1.36349 1.36354 1.3629 1.36335 197
2010.11.18 21:00 1.36341 1.36352 1.3631 1.36335 158
2010.11.18 21:05 1.36335 1.36404 1.36335 1.3635 132
2010.11.18 21:10 1.36349 1.3635 1.36334 1.36336 53

I am interested in the date, the time and the closing price for each candle which is the 6th column(F in excel).

So exporting the last 3 months will end in 2 csv files with aprox 15000 lines. One big problem i faced is that sometimes one of the sources haves missing data, so i had to make the tedious task of fix the errors, witch they are a lot for some pairs. Helping me with excel i was able to make this task a little quicker.

Excel will be my main tool as statistician, we will get out at least for now from the mql programming language field and use excel built in statistical functions to make our lifes easier.

Tags: , , , ,

Hedge trading first conclusions

After a few days using the MyHedge Expert advisor i can now have some conclusions to make. First, the Hedge strategies haves to be tested live in demo accounts, this means that we cant use the strategy tester because it don’t allow to test stuff in 2 symbols at the same time. We also know there are clever ways to break this limit but i will leave that apart for now.

So trading in demo with myHedge i was playing around with the variables and modifying the script to make it work property, i can say now that i have the EA fully working on my computer.

My strategy until now was:

- use 60 min timeframe to calculate correlation between eur-jpy and gbp-jpy, if this correlation is equal or greater to 0.90 the EA open a long position in the gbp while it sells the eur or vise versa, i tried both ways.

This strategy is again to simple, some times work, some times don’t, so no edge using just that. Hedge minimize risk but it is not a strategy on its own, there is something else needed and i am now trying to find it to have better results.

Also, here is a screenshot of an indicator i am using to overlay 2 charts, it is very useful to see how 2 currencies correleted move, the indicator for the meta trader can be downloaded here:

http://codebase.mql4.com/2757

Tags: , , , , , , ,

The hedge trade

My current trading strategies are based on indicators, specially i did a lot with crossing moving averages.  On my last posts i concluded that a simple moving average cross is to simple to be a reliable signal so i tried to use the upper timeframe to get the trend and trade with it. Results were similar, the cross of moving averages works some times as some other don’t, a clear example is the profitability of year 2010 while in 2009 tests results end with big losses.

The market is so chaotic that it is almost impossible for a trader using a single indicator to predict market behavior. i checked my old notes and i found something that was very interesting and surprising when i saw it and that i think it will drive my approach starting now until i can prove that the strategy don’t work as i did with the moving averages ones.

In my notes i found myself trading the euro using the Sp-500 stocks index, this was in the Euro crisis we had this year. At that time i found that this 2 instruments were moving in the same manner, if the sp-500 started to rally the euro was following it just a few seconds or minutes after.

Correlations are common in the financial world and i am seeing them now as a vulnerability the market haves, it is easy to calculate correlation in real time using mql.

The following 2 articles are what i am studying now, http://codebase.mql4.com/6601 and http://articles.mql4.com/445

Using the second article i was able to test the hedging strategy using the mql tester and i am now using article 1 expert advisor(myHedge) to test hedging in demo live to find a profitable hedging strategy.

There is a lot to do, read and test, i will be adding results to the diary soon.

Tags: , , , , ,

The optimization trap

Making more tests with the optimization process of my last EA i can conclude that for 2010 the EMA cross most profitable is 8 with 173 for short positions.

I found that with bigger values in Take Profits and Trial Stops the expert can get more profits like for example:

2717.52             578.42                          StopLoss=550      TakeProfit=6050      Tral_Stop=1750
profit                   drawdown $                  stop loss                take profit                    start trailing at

This means that my EA using the cross of the 8 EMA and the 173 EMA taking only short position made from 2010-01-01 to 2010-08-30 ( 8 months ) 2717.52 dollars with an initial deposit of 500 dollars. The 2717 is pure profit, the initial 500 are also there, so the trader using this system from the beginning of the year haves now a total of 3217 USD.

This last results are not the closer to the truth i can get, those results were just one of the best passes of the optimizer using control points. I am loading now this variables to the strategy tester and the results are even a little better:


The details

The proof of fire will be to test this in year 2009, i know that the classic 21 and 200 cross failed at 2009.

This is the optimization trap, the values picked was for that period of time and simply don’t work in others when conditions are different.
2010 was a big downtrend almost all the year:

The problem with a simple crossing moving averages expert is that it is to simple, it don’t check how are the conditions of the overall market, i will probably try to use more than one time frame to make something better. For example if trend is down in a h4 or daily chart use only short strategies in the 15 min charts and vise verse.

I am not ready yet.

Tags: , , , ,

Robot Optimization

Optimization of expert advisors will help me find the right parameters for different variables of the program in a period of time. It is better to use the 20 ema crossing the 200 ema or the 30 ema crossing the 193? all this kind of questions can be replied with the optimization process.

I will use control points instead of every tick so the process will be faster, we will use Expert Advisor 9 for optimization. I will run the optimizator with data of the current year, starting january 1 and ending july 31.

The 2 moving averages for the cross will be optimized, the take profits variable, the stop loss variable and the trailing stop will all be optimized as well. the mql build in optimizer will combine all this and display a report.

There is no need to use the same values for short and long trades, what it works good for long it don’t necessarily haves to work for short trades so i made 2 optimizations runs and here are the results:

Long Optimization Reports

Short Optimization Reports

It looks that the optimizer found great results for short trades, the draw down is of 20% and the expected payoff is high. This is what we look in an expert advisor, big payoffs and small drawdowns.

With this new optimized values:

StopLoss=250     TakeProfit=1850     Period_MA_1=9     Period_MA_2=171     Tral_Stop=750

i make a new expert advisor optimized for short sales, when i run it in the strategy tester using the most precise data now we get this curve from january 1st 2010 to today:

Details

Tags: , , , , , , ,

Expert optimization words

ok, so i have for instance an expert advisor that use the cross of emas as trade signals . we were using common ema values for this like 21 with 200 cross.

how do we know this are the best values for a given period like for example for the first 7 months of the current 2010 year ? How do we know what is the best pip amplitude to start trailing the stop on a given period ? To answer this question is for what we use optimization build in feature of metrader. it will test all possibilities for all the variables i want.
let’s say we want variable Period_MA_1 to goes from 1 to 200, and Period_MA_2 can go from 1 to 500, of course the normal variables we used (Period_MA_1=21 and Period_MA_2=200) will be also included at a given point of the optimization.

What are the best values for stop loss ? and for take profits ? All this question will be answered when the optimization process ends, it is a very long process but extremely powerfull as the computer will make thousands of tests for me.

We don’t know if what happened in the past will bee seen again in the future but if i can make an expert that is making money consistently in the last 4 or 5 years, with small drawdonwns, using the 90% feed data we will be closer to put a robot to trade live in the near future.

Tags: , , ,

More historical tests

demonstrates that the EA 9 ( http://fforex.me/robots/emas-cross-21-200-trailing-stop-corrected-tests/ ) had a really bad year during 2009 ending the year with losses.

a loss for an entire year means that the expert will not be profitable, further actions should be taken, i am now working on optimization of this expert. see next post.

Tags: , , , , ,