Download MetaTrader 5

Experiences developing a multi currency EA

To add comments, please log in or register
Have you developed a profitable strategy? Share it with millions of traders via Signals!
Ingvar Engelbrecht
4499
Ingvar Engelbrecht 2014.03.22 00:04 

The EA I am developing is a Swing Trader EA.

It uses Daily, 4-hour and 1-hour to determine trend. It uses 5-Minute for prospective entry and 1-M for entry.

In order to make it independent of broker server time it is not a good idea to use the 4H and 1D data as is since they will differ depending on the servers time zone. 2 choices.

Either make your own 4H and 1H from the 1H data or just put in a longer period on 1H data. It feels natural to just multiply by 4 and 24 but you can really use other factors too. I do.

Since you are working on a multi currency architecture it is quite logical to split each pair into 2, one for long and one for short trades and optimize them separately. It does give better results my tests show.

When looping thru the pairs checking for entry start with the highest TF (1D). If it does not say buy or sell skip that pair and go for next. Work down in the time frames. If a time frame does not align skip

and goto next pair. Minimizes load on your computer/server.

Do not use OnTick to control your scanning loop. You attach your EA on a pair and that means you get ticks for that pair. These ticks might be ok for other pairs and it might not. Took me several hours

to figure out why I got different results on some pairs when running on different pair windows.

Optimizing is done with the EA running on the pair you want to optimize. Running multi mode is probably on some other pair. Using OnTimer instead and the problem was resolved.

Make it simple to switch between single mode and multi mode. For multi mode I use a simple file containing the parameters. One row for each pair (actually 2, one for long and one for short trades).

I read the file every hour so I do not have to stop the EA if I want to do some changes or additions.

An interface to MySQL is planned instead of a file.

Running all pairs concurrently requires quite a lot of memory. And it is not always sufficient to have a computer with a lot of physical memory installed. You will need to run a 64 bit OS. I had too.

The EA is not finished yet and there is still a lot of optimizing and debugging to do. And possibly also improvements. Preliminary tests running 18 pairs (36 optimization runs) shows some very promising

. When doing optimization runs always pick parameters that give the straightest equity curve and a reasonable profit on each pair.

I originally built the architecture with pending orders for TP and SL since the original design was with more than 1 position per entry. I have given up on that. I experienced several different cases

of “loose cannons” in the form of missing or leftover TP and SL. To complicated.. Just places an order with SP and TP. Maybe later. Maybe in MT4 after porting it to MT4.

It has been a long haul getting this far. Learning MQL5, employing some “Class” structure and then some. I am sure it will pay off in the end.

You just have to live with the phrase.

“There is no substitute for perserverance”

Like they say in drag racing. “There is no substitute for cubic inches” :-)


My two bits


Ingvar Engelbrecht. Retired long time programmer.

Rogerio Figurelli
Moderator
39483
Rogerio Figurelli 2014.03.22 02:48  
ingvar_e:

The EA I am developing is a Swing Trader EA.

...

Hi Ingvar, thanks for sharing, and what about any results? Was worth all that effort?
Dua Yong Rew
5422
Dua Yong Rew 2014.03.22 08:16  

Since you are working on a multi currency architecture it is quite logical to split each pair into 2, one for long and one for short trades and optimize them separately. It does give better results my tests show.

Does that curve fit? 

Ingvar Engelbrecht
4499
Ingvar Engelbrecht 2014.03.22 10:48  
figurelli:
Hi Ingvar, thanks for sharing, and what about any results? Was worth all that effort?

   I hope so! The results has varied. Some "improvements" has been good some bad. The last one was using Onticks instead of Ontimer so I have a couple of days running new optimisation runs.  38 of them in fact.

  Best backtest has been 30.000 in net profit running 30 pairs betting 0.4 lots  from 2012-12-01 to 2014-02-26. Excellent equity curve. Hope I will get back to it in a couple of days. Had a nice un on forward test for 14 days

  but then I screwed up the code. (its a lot)

Ingvar Engelbrecht
4499
Ingvar Engelbrecht 2014.03.22 10:59  
doshur:

Since you are working on a multi currency architecture it is quite logical to split each pair into 2, one for long and one for short trades and optimize them separately. It does give better results my tests show.

Does that curve fit? 

   Curve fitting is always a potential hazard with backtest/optimization. In any system. It is not specifically related to treating a pair like 2 different pairs or multicurrency systems. I do a few other things that hopefully will keep it under control.

   - When picking a result I choose a result on low drawdown, equity curve straightness and profit.  In that priority order.

   - I do optimization in 2 or 3 steps. 1. Basic parameters for trend and trend reversal  2. Entry parameters   3. Filters and a bit of adjustments to TP an SL depending on volatility. Not mixing parameters for different functions is a good thing in my opinion

 

Rogerio Figurelli
Moderator
39483
Rogerio Figurelli 2014.03.22 14:07  
ingvar_e:

   I hope so! The results has varied. Some "improvements" has been good some bad. The last one was using Onticks instead of Ontimer so I have a couple of days running new optimisation runs.  38 of them in fact.

  Best backtest has been 30.000 in net profit running 30 pairs betting 0.4 lots  from 2012-12-01 to 2014-02-26. Excellent equity curve. Hope I will get back to it in a couple of days. Had a nice un on forward test for 14 days

  but then I screwed up the code. (its a lot)

I see, but take care if you use just OnTick() for multi-currency, mainly if your strategy is for small periods or scalping, as you can lose relevant ticks for the other symbols.

Maybe a better approach (facing the market we never know what is really better) is to start with a very, very simple EA (and just one symbol), looking for a good equity curve, and just after that improves step by step. 

Jose Miguel Soriano
4957
Jose Miguel Soriano 2014.03.24 17:43  
ingvar_e:

The EA I am developing is a Swing Trader EA.

It uses Daily, 4-hour and 1-hour to determine trend. It uses 5-Minute for prospective entry and 1-M for entry.

In order to make it independent of broker server time it is not a good idea to use the 4H and 1D data as is since they will differ depending on the servers time zone. 2 choices.

Either make your own 4H and 1H from the 1H data or just put in a longer period on 1H data. It feels natural to just multiply by 4 and 24 but you can really use other factors too. I do.

Since you are working on a multi currency architecture it is quite logical to split each pair into 2, one for long and one for short trades and optimize them separately. It does give better results my tests show.

When looping thru the pairs checking for entry start with the highest TF (1D). If it does not say buy or sell skip that pair and go for next. Work down in the time frames. If a time frame does not align skip

and goto next pair. Minimizes load on your computer/server.

Do not use OnTick to control your scanning loop. You attach your EA on a pair and that means you get ticks for that pair. These ticks might be ok for other pairs and it might not. Took me several hours

to figure out why I got different results on some pairs when running on different pair windows.

Optimizing is done with the EA running on the pair you want to optimize. Running multi mode is probably on some other pair. Using OnTimer instead and the problem was resolved.

Make it simple to switch between single mode and multi mode. For multi mode I use a simple file containing the parameters. One row for each pair (actually 2, one for long and one for short trades).

I read the file every hour so I do not have to stop the EA if I want to do some changes or additions.

An interface to MySQL is planned instead of a file.

Running all pairs concurrently requires quite a lot of memory. And it is not always sufficient to have a computer with a lot of physical memory installed. You will need to run a 64 bit OS. I had too.

The EA is not finished yet and there is still a lot of optimizing and debugging to do. And possibly also improvements. Preliminary tests running 18 pairs (36 optimization runs) shows some very promising

. When doing optimization runs always pick parameters that give the straightest equity curve and a reasonable profit on each pair.

I originally built the architecture with pending orders for TP and SL since the original design was with more than 1 position per entry. I have given up on that. I experienced several different cases

of “loose cannons” in the form of missing or leftover TP and SL. To complicated.. Just places an order with SP and TP. Maybe later. Maybe in MT4 after porting it to MT4.

It has been a long haul getting this far. Learning MQL5, employing some “Class” structure and then some. I am sure it will pay off in the end.

You just have to live with the phrase.

“There is no substitute for perserverance”

Like they say in drag racing. “There is no substitute for cubic inches” :-)


My two bits


Ingvar Engelbrecht. Retired long time programmer.

I use OnChartEvent (). 

I think that solves all problems. No ticks are lost. 

OnTimer () is not a correct solution: https://www.mql5.com/en/code/215 and https://www.mql5.com/en/code/209. 

You can see an example of how to resolve the input of parameters in multicurrency in the utility <link removed by moderator>

Best regards from Spain.

"MCM Control Panel" for Multicurrency Expert Advisors and Indicators
"MCM Control Panel" for Multicurrency Expert Advisors and Indicators
  • votes: 12
  • 2010.12.23
  • Konstantin Gruzdev
  • www.mql5.com
The MCM Control Panel provides the solution for multicurrency trading in MetaTrader 5.
Rogerio Figurelli
Moderator
39483
Rogerio Figurelli 2014.03.24 18:01  
josemiguel1812:

I use OnChartEvent (). 

I think that solves all problems. No ticks are lost. 

OnTimer () is not a correct solution: https://www.mql5.com/en/code/215 and https://www.mql5.com/en/code/209. 

You can see an example of how to resolve the input of parameters in multicurrency in the utility https://www.mql5.com/en/market/product/3147

Best regards from Spain.

Indeed, I 100% agree about that.
Ingvar Engelbrecht
4499
Ingvar Engelbrecht 2014.03.27 21:23  
josemiguel1812:

I use OnChartEvent (). 

I think that solves all problems. No ticks are lost. 

OnTimer () is not a correct solution: https://www.mql5.com/en/code/215 and https://www.mql5.com/en/code/209. 

You can see an example of how to resolve the input of parameters in multicurrency in the utility <link removed by moderator>

Best regards from Spain.

  Apart from the higher timeframes my EA only needs information when a new 1 minute bar has closed.

 Works fine with a timer, got excellent backtesting results and  light load on the server despite running 15 pairs. And since I split

long and short trades it is really like running 30 pairs. 

Kourosh Davallou
40130
Kourosh Davallou 2014.03.28 12:55  
ingvar_e:

  Apart from the higher timeframes my EA only needs information when a new 1 minute bar has closed.

 Works fine with a timer, got excellent backtesting results and  light load on the server despite running 15 pairs. And since I split

long and short trades it is really like running 30 pairs. 

Multi-currency is a good idea, but you should not see aggregated profit and loss currencies with a single currency.
To add comments, please log in or register