Discussion of article "Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results"

 

New article Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results has been published:

While analyzing a huge number of trading strategies, orders for development of applications for MetaTrader 5 and MetaTrader 4 terminals and various MetaTrader websites, I came to the conclusion that all this diversity is based mostly on the same elementary functions, actions and values appearing regularly in different programs. This resulted in DoEasy cross-platform library for easy and quick development of МetaТrader 5 and МetaТrader 4 applications.

Now all is compiled without errors, and data on all orders and deals in trading account's history are displayed in the terminal journal.


All properties of each order/deal, including unsupported ones, are displayed.

The fact is that we have developed the methods returning the flags for supporting specific properties by this order to be virtual, so that they are redefined in the derived classes. These derived classes are then used to display data in the journal. In that case, all should be displayed correctly. If there is a property not supported by the order, it is not displayed in the journal, since the Print(const bool full_prop=false) method of the COrder class has the default flag for disabling a display of unsupported properties in the journal, while the SupportProperty() virtual methods of the class simply return 'true' for any property.

What's next?

The first (and the smallest) part is ready. We have developed a basic object for the collection of history orders and deals as well as for the collection of market orders and positions. So far there is no practical value but this is only the beginning. This single basic object is to become a keystone for the system storing and displaying data on the order system. Our next step is to develop other necessary objects and collections using the same principles. I am also going to automate collection of constantly required data.

Author: Artyom Trishkin

 

As it is a library in development I will wait further articles before doing any global remark.

However I noticed 2 potential problematic situations in this first part :

Firstly.

Sometimes, you may want to get the number of decimal places in a symbol lot. Let's enter this function to our file of service functions:

//+------------------------------------------------------------------+
//| Return the number of decimal places in a symbol lot              |
//+------------------------------------------------------------------+
uint DigitsLots(conststring symbol_name) 
  { 
   return (int)ceil(fabs(log(SymbolInfoDouble(symbol_name,SYMBOL_VOLUME_STEP))/log(10)));
  }

1.a The proposed solution using log is not universal. On some symbol you can perfectly have a volume step of 0.25 for example and the DigitsLots() will return a wrong answer in such case.

1.b Why would you want the "number of decimal places in a symbol lot" ? I don't see any real use case for that.

1.c If you really want to use log function and you will deal with special cases somewhere else, you should use log10, instead of natural logarithm.

return (int)ceil(fabs(log10(SymbolInfoDouble(symbol_name,SYMBOL_VOLUME_STEP))));

1.d Providing such function on the public interface could lead to inefficient results, it uses 5 function calls and could be called several times on each tick.


Secondly.

intOnInit()
  {
//---
   list_all_orders.Sort();
   list_all_orders.Clear();
   if(!HistorySelect(0,TimeCurrent()))
     {
      Print(DFUN,TextByLanguage(": Не удалось получить историю сделок и ордеров",": Failed to get history of deals and orders"));
      returnINIT_FAILED;
     }
   ...

2.a This is not a correct way to call HistorySelect(), you could miss some history information as TimeCurrent() returns the last know tick date from the broker server. Rationale from here and from experience.

2.b It's a bad example to use TimeCurrent() in OnInit() function where you have no guarantee to have a broker connection. In general it's a bad idea to do any data request in OnInit().

 

Thanks for the comments, but this is just a test.

  1. I will consider the possibility of changing the function to another - completely universal
  2. the number of decimal places for the lot of each individual symbol is necessary for the unmistakable sending of trade orders
  3. Your function with log10 does not have a problem voiced by you with a lot step of 0.25?
  4. data on the number of decimal places is written once to the object of the class-symbol. This will be further - in subsequent articles.

A test check in OnInit () is needed just for checking. And only there I get the history of orders in this way. In collections of orders, deals and positions - otherwise.

All this in subsequent articles.

-------------

Спасибо за комментарии, но это всего лишь тест.

  1. я рассмотрю возможность изменения функции на иную - полностью универсальную
  2. количество знаков после запятой для лота каждого отдельного символа нужно для безошибочной отправки торговых приказов
  3. ваша функция с log10 не имеет озвученной вами проблемы с шагом лота 0.25 ?
  4. данные о количестве знаков после запятой записываются единожды в объект класса-символ. Это будет далее - в последующих статьях

Тестовая проверка в OnInit() нужна всего лишь именно для проверки. И только там историю ордеров получаю таким образом. В коллекциях ордеров, сделок и позиций - иначе.

Всё это в последующих статьях.
 
Artyom Trishkin:

Thanks for the comments, but this is just a test.

  1. I will consider the possibility of changing the function to another - completely universal
  2. the number of decimal places for the lot of each individual symbol is necessary for the unmistakable sending of trade orders
  3. Your function with log10 does not have a problem voiced by you with a lot step of 0.25?
  4. data on the number of decimal places is written once to the object of the class-symbol. This will be further - in subsequent articles.

A test check in OnInit () is needed just for checking. And only there I get the history of orders in this way. In collections of orders, deals and positions - otherwise.

All this in subsequent articles.


1. Good.

2. It's not needed if you normalize your lot correctly, something like :

 double lotStep=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
 lots=MathRound(lots/lotStep)*lotStep;

Using lot digits can only lead to problem.

3. log10 has the same problem, it's not universal. It was just to avoid the useless call to log(10).

4. Good.

I know it's only to check but even with test code publicly available, I think we have a responsibility to show and use good practices.

I will read other articles.

 
Alain Verleyen:

1. Good.

2. It's not needed if you normalize your lot correctly, something like :

Using lot digits can only lead to problem.

3. log10 has the same problem, it's not universal. It was just to avoid the useless call to log(10).

4. Good.

I know it's only to check but even with test code publicly available, I think we have a responsibility to show and use good practices.

I will read other articles.

OK. Thanks
 
Hello. Thank you for the great work. I noticed at the end there is a download link for the files as well as a copyright notice denying permission to copy or reprint. The 2 seem to be conflicting. Am I allowed to download and use the file or not? If I use the file does that mean all the profits become yours? Perhaps we can split the rewards on a 50/50 basis where you take all the losses and I take all the profits. ;-)
 
bitmax :
Hello. Thank you for the great work. I noticed at the end there is a download link for the files as well as a copyright notice denying permission to copy or reprint. The 2 seem to be conflicting. Am I allowed to download and use the file or not? If I use the file does that mean all the profits become yours? Perhaps we can split the rewards on a 50/50 basis where you take all the losses and I take all the profits. ;-)

Hi. Of course, you can use the codes from the articles in your development. You cannot reprint the text of the article without the explicit permission of MetaQuotes and use this text in your publications outside this resource. Just read the rules carefully :)

Reason: