Extend MQL!!

To add comments, please log in or register
pengie
210
pengie  

Before I start, I want to say this is a great forum and I wish to make my first contribution .

I noticed a lot of programmers are using OrdersTotal() to get the total number of orders in order to determine whether to open a new position or not. However, I feel that most of us may be running multiple EAs so using OrdersTotal() will actually prevent different EAs from working simultaneously. So I have written a short library with a few useful functions. If EA programmers use this library, multiple EAs will be able to co-exist.

The library contains the following functions:

int CountOrdersIfMagic(int magicNumber);

Get the total number of orders in the system with this magic number

int CountOrdersIfMode(int cmd);

Get the total number of orders in the system with this type of the operation. E.g. CountOrdersIfMode(OP_BUY) will get the total number of BUY orders in the system.

int CountOrdersIfSymbol(string symbol);

Get the total number of orders in the system with this symbol pair. E.g. CountOrdersIfMode("EURUSD") will get the total number of orders in the system for the EUR/USD pair.

int CountOrders(string symbol="", int magicNumber=-1, int cmd=-1);

This is the general function to get the total number of which fulfils the three given conditions. If the default value is used for a certain condition, that condition will not be used as a restricting condition for the CountOrders function.

int GetFirstTicketByMagic(int magicNumber);

int GetFirstTicketByMode(int cmd);

int GetFirstTicketBySymbol(string symbol);

int GetFirstTicket(string symbol="", int magicNumber=-1, int cmd=-1);

int GetNextTicket();

This series of GetFirstTickets and GetNextTicket function is to enable the programmer to iterate through all tickets which fulfils the different conditions. For example, if I want to iterate through all orders which have a certain magic number, 12345, I will do the following:

for (int ticket=GetFirstTicketByMagic(12345); ticket!=0; ticket=GetNextTicket())

{

OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);

...

...

}

int GenerateMagicNumber(int seed, string symbol, int timeFrame);

Generate a unique magic number based on a given seed, symbol and timeframe. The seed should preferrably not exceed 9999. E.g. int magic = GenerateMagicNumber(1234, Symbol(), Period());

string GenerateComment(string EAName, int timeFrame);

Generate a unique comment based on the EA name and timeframe. E.g. string comment = GenerateComment("MyEA", Period());

---Updated on 9 March 2006 GMT 0100h.

Fixed some minor bugs

---Updated on 9 March 2006 GMT 0900h.

Added two new functions, GenerateMagicNumber and GenerateComment

---Todo list

Add functions for MM and TrailingStops.

Files:
Sergey Golubev
Moderator
113796
Sergey Golubev  
pengie:
Before I start, I want to say this is a great forum and I wish to make my first contribution .

I noticed a lot of programmers are using OrdersTotal() to get the total number of orders in order to determine whether to open a new position or not. However, I feel that most of us may be running multiple EAs so using OrdersTotal() will actually prevent different EAs from working simultaneously. So I have written a short library with a few useful functions. If EA programmers use this library, multiple EAs will be able to co-exist.

The library contains the following functions:

int CountOrdersIfMagic(int magicNumber);

Get the total number of orders in the system with this magic number

int CountOrdersIfMode(int cmd);

Get the total number of orders in the system with this type of the operation. E.g. CountOrdersIfMode(OP_BUY) will get the total number of BUY orders in the system.

int CountOrdersIfSymbol(string symbol);

Get the total number of orders in the system with this symbol pair. E.g. CountOrdersIfMode("EURUSD") will get the total number of orders in the system for the EUR/USD pair.

int CountOrders(string symbol="", int magicNumber=-1, int cmd=-1);

This is the general function to get the total number of which fulfils the three given conditions. If the default value is used for a certain condition, that condition will not be used as a restricting condition for the CountOrders function.

int GetFirstTicketByMagic(int magicNumber);

int GetFirstTicketByMode(int cmd);

int GetFirstTicketBySymbol(string symbol);

int GetFirstTicket(string symbol="", int magicNumber=-1, int cmd=-1);

int GetNextTicket();

This series of GetFirstTickets and GetNextTicket function is to enable the programmer to iterate through all tickets which fulfils the different conditions. For example, if I want to iterate through all orders which have a certain magic number, 12345, I will do the following:

for (int ticket=GetFirstTicketByMagic(12345); ticket!=0; ticket=GetNextTicket())

{

OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);

...

...
}

Thanks a lot Pengie.

Nicholishen
1016
Nicholishen  
pengie:
Before I start, I want to say this is a great forum and I wish to make my first contribution .

I noticed a lot of programmers are using OrdersTotal() to get the total number of orders in order to determine whether to open a new position or not. However, I feel that most of us may be running multiple EAs so using OrdersTotal() will actually prevent different EAs from working simultaneously. So I have written a short library with a few useful functions. If EA programmers use this library, multiple EAs will be able to co-exist.

The library contains the following functions:

int CountOrdersIfMagic(int magicNumber);

Get the total number of orders in the system with this magic number

int CountOrdersIfMode(int cmd);

Get the total number of orders in the system with this type of the operation. E.g. CountOrdersIfMode(OP_BUY) will get the total number of BUY orders in the system.

int CountOrdersIfSymbol(string symbol);

Get the total number of orders in the system with this symbol pair. E.g. CountOrdersIfMode("EURUSD") will get the total number of orders in the system for the EUR/USD pair.

int CountOrders(string symbol="", int magicNumber=-1, int cmd=-1);

This is the general function to get the total number of which fulfils the three given conditions. If the default value is used for a certain condition, that condition will not be used as a restricting condition for the CountOrders function.

int GetFirstTicketByMagic(int magicNumber);

int GetFirstTicketByMode(int cmd);

int GetFirstTicketBySymbol(string symbol);

int GetFirstTicket(string symbol="", int magicNumber=-1, int cmd=-1);

int GetNextTicket();

This series of GetFirstTickets and GetNextTicket function is to enable the programmer to iterate through all tickets which fulfils the different conditions. For example, if I want to iterate through all orders which have a certain magic number, 12345, I will do the following:

for (int ticket=GetFirstTicketByMagic(12345); ticket!=0; ticket=GetNextTicket())

{

OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);

...

...
}

Very Cool...Thanks!

ammar
49
ammar  

Dear Pengie ,

I have noticed when I execute an EA , that OrderModify is not executed when there is a new order (Buy or Sell ) to be opened in the same bar.

What can I do for it?

Thanks for your help.

Ammar.

pengie
210
pengie  
ammar:
Dear Pengie ,

I have noticed when I execute an EA , that OrderModify is not executed when there is a new order (Buy or Sell ) to be opened in the same bar.

What can I do for it?

Thanks for your help.

Ammar.

Hi Ammar,

It will be better if you can show us a snippet of your EA. It is difficult to say what is wrong without seeing some code.

ammar
49
ammar  

Dear Pengie ,

Here it is , I hope you can solve the problem.

Thank you .

Ammar

Files:
cci21.mq4 5 kb
pengie
210
pengie  
ammar:
Dear Pengie ,

Here it is , I hope you can solve the problem.

Thank you .

Ammar

Hi Ammar,

Hope this solved your problem. BTW, I don't think this is the appropriate thread to bring up problems with cci. You should post it in the correct thread next time

Files:
cci21_2.mq4 5 kb
ammar
49
ammar  

Dear Pengie ,

First off all , thank you very much for your help, you are very kind.

Secondly, I'm sorry for posting this problem in this thread , but I thought that this problem is due to OrdersTotal() function you had mentioned above ( sorry but I have just started learning MQL ) .

Sorry again.

Ammar

vpopovic
41
vpopovic  

Project -10k Live EA Portfolio-

I hope I can get some help setting up my trading plan in return I will post detailed live results, hopefully to serve as a guideline for what is performing and what is not.

My obvious concern would be about MARGIN. Trading mini lots of course but I am sure there will be situation when 10-20 trades are open at the same time. Do my fears have a foundation or I am just paranoid?

My knowledge of code is almost 0 but I do understand that each EA has a different type of money management. Would it be possible to insert into each EA that max trade is only 2% of account balance or equity?(maybe even 1% to protect account even more) On other hand would that interfere with MM that EA already use?

Also I have some understanding of magic number, time filters but I am completely terrified to try to change it myself as this is the REAL money that will be on the line. I hope I can general answers to my questions here, and if somebody want to help me customize settings for portfolio I can pay some change via paypal and then for couple of months I will give small percentage of the profits (hopefully).

Sergey Golubev
Moderator
113796
Sergey Golubev  

It is almost impossible to run many EAs in one copy of MetaTrader.

It may be some case when many EAs wanted to open/modify/close the orders in the same time. It is just one case. But there are a lot of different cases why it is totally difficult or almost impossible to run many EAs in one Metatrader.

There are some (free) library files to do it. But and in this case it is difficult. Just select one or two EAs.

The other related thing is the broker. Every broker is having different data and some EAs (or most of them) are having different performance with different broker.

Just one example.

NewsTrader.5 EA is placing 3 stop orders in every side. 36 totally. SBS EA is placing 4 perding orders. TPE EA is placing the other 4. GridMACD EA and MaChannel is openning many orders during the day. Envelope 2.11 is placing many pending orders during the day at once.

So to use it in one copy of Metatrader it is necessary to have some special tool namely Portfolio Manager. We don't have it yet. I mean no where: no any commercial and no any for free. Does not exist yet. We wanted to start to create this kind of tool in elite section but seems it is very difficult.

My suggestion is the following:

start with broker (not all mentioned EAs are profitable with every broker), then - your deposit size (GoldWarrior02b, for examlpe, for big deposit size), then - your risk (GridMACD EA, TPE EA and MaChannel are risky EAs - just for example), then select one or two EAs only. Then try to look at the riginal threads to understand the trading system.

Do not trade EA with real money of you don't understand the system and why EA is openning the orders.

Then ask the questions in the forum. Which questions? For example: "what bad in this EAs? What is negative points for this EAs? I know that it may be profitable but when and why will I get the losses?".

Some people looked at the profit during the testing. The other people looked at the losses just to understand how to avoid it.

P.S.

7 EAs from your list are from elite section.

Please don't post it in public. I understand that it is easy to download all EAs and all the statements from one my elite section post or excel file ... But please ...

gcgipson
488
gcgipson  

repost, disregard.

To add comments, please log in or register