Algorithms, solution methods, comparison of their performance

 

In this thread we will discuss different ways of solving these or those problems and compare performance of the proposed solutions.

Everyone is welcome to discuss problems and methods of solving them ;)

 

I propose to solve a problem:

  1. Write a function that on each call will accept and write some pseudo-random number, which will be a conditional"honeyjack".

2. write a second function that calls the first function a pseudo-random number of times and passes it the (generated) conditional "medjic".

3. Write a third function that will return the"medjic" number by the"transaction" number (any ordinal number) passed by the user.


Requirements:

  1. The memory consumption for writing "medjic" should be as close as possible to the number of "medjic", the number of which is unknown in advance.
  2. Functions should work quickly.

//--------------------------------------------------------

I think the library under discussion has the tools to solve this problem.


ZS. All three functions simulate the work with EA orders, the number of which is not known in advance. Hence, the task fits into our theme.

 
Реter Konow:

I propose to solve a problem:

  1. Write a function that on each call will accept and write some pseudo-random number, which will be a conditional"medjic".

2. write a second function that calls the first function a pseudo-random number of times and passes it a (generated) conditional "medjic".

3. to write the third function, which will return the number of"medjik" by the number of"deal" (any serial number), which is transferred by the user.

Requirements:

  1. The memory consumption for writing the "medgies" should be as close as possible to the number of "medgies", the number of which is not known in advance.
  2. The functions have to work quickly.

I think the library in question has the tools to solve this problem.

SZY. All three functions imitate the work with Expert Advisor orders, the number of which is not known in advance. Therefore the problem fits our theme.

Piotr, I believe that any function must have some benefit. I do not quite understand what good comes out of any of the three functions ?

 
Victor Ziborov:

Peter, I think every function has to be of some benefit. I'm not quite sure what positive effect any of these three functions have ?

This is an offshoot of https://www.mql5.com/ru/forum/221917

Here we are testing the effectiveness of the solutions proposed by the library in practice.

In that thread, it was suggested that the solution of writing medjic orders to a string and then putting them into an array was inefficient.

The new Generic library also has a solution to this problem.

Interesting to confirm or refute the statement that writing to a string is an ineffective solution.

I think it will be useful and interesting to see what practice will show.


All who want, may try to solve this task with the help of the library's toolkit.

I will try to solve this task in my own way.

Then we will compare the performance.

Библиотека Generic классов - ошибки, описание, вопросы, особенности использования и предложения
Библиотека Generic классов - ошибки, описание, вопросы, особенности использования и предложения
  • 2017.12.07
  • www.mql5.com
С 6 декабря 2017 года в стандартную поставку MetaTrader 5 стали входить так называемые Generic-классы, реализующие эффективные алгоритмы для хранен...
 

Reg Konow, if you are organising something, please do it on a decent level, not spontaneously and from.....stand.

The terms should be clear, unambiguous and with concrete examples....
Here is a list of questions that arose from a close reading of the entire first paragraph.

  1. Написать функцию, которая на каждом обращении будет принимать и записывать некоторое псевдо-случайное число, которое будет условным "меджиком".

1) Why bold the text which is not meaningful?
2) Is taking a pointer a "call" to a function or not yet? The function is called.
3) The term "write a number" is usually used when working with files. Is it an inaccuracy and refers to working with data in memory, or does it still require saving data between program runs?
4) If you want, a pseudo-random number can be negative, but magic is not. So what do we have: magic or pseudo-random within a certain range? Which one?

 
Sergey Dzyublik:

Reg Konow, if you're organising something, please do it on a decent level, not spontaneously and from.....stand.

Terms should be clear, unambiguous and with concrete examples....
Here is a list of questions that arose from a close reading of the entire first paragraph.

1) Why bold the text which is not meaningful?
2) Is taking a pointer a "call" to a function or not yet? The function is called.
3) The term "write a number" is usually used when working with files. Is it an inaccuracy and refers to working with data in memory, or does it still require saving data between program runs?
4) If you want, a pseudo-random number can be negative, but magic is not. So what do we have: magic or pseudo-random within a certain range? Which one?

Main task:

To implement quick access to a specific magician via a transaction number.

It is necessary to write magicians into a "dictionary" and access them through the transaction number.

The number of orders is not known in advance, hence the size of the dictionary is unknown.

However, access has to be fast and the amount of memory allocated has to be acceptable.

The task I suggest is aimed at imitating the work of an EA which places orders and then gets their mages by the trade number to further work with them.

You can solve the problem any way you like.

A specific number of a magician does not matter. It can be any number. It's just a simulation.


Added:

Corrected above"Implement fast access to a specific magic via transaction number. " .

 

If we add three magic numbers: 10, 11, 12
Then what are their transaction numbers? 0, 1, 2?

 
Sergey Dzyublik:

If we add three magic numbers: 10, 11, 12
Then what are their transaction numbers? 0, 1, 2?

In another thread, knowledgeable people have said that it is impossible to make an effective solution to write magicians to a string and get them quickly "on the fly" from the string.

However, in my opinion, if the number of future warrants is unknown, then the only good solution is to write magicians to the string.

I argued that there would be no loss in speed.

Here is a practical proof:

//+------------------------------------------------------------------+
//|                                                        Magic.mq5 |
//|                                                      Peter Konow |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Peter Konow"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
string All_magics;
int    order_number;
int    Random_orders_of_strategy;
//+------------------------------------------------------------------+
void Save_magic(int magic)
{
 order_number++;
 //---------------------------------
 //Записываем каждый магик вместе с порядковым номером ордера.
 //---------------------------------
 All_magics +=  "_" + (string)order_number + "_" + (string)magic;
 //---------------------------------
}
//+------------------------------------------------------------------+
void Trading()
{
 Random_orders_of_strategy = MathRand();
 
 //----------------------------------------
 //Имитируем открытие неопределенного количества ордеров стратегии.
 //----------------------------------------
 for(int a1 =  0; a1 < Random_orders_of_strategy; a1++)
   {
    int this_magic = MathRand();
    //----------------------------
    Save_magic(this_magic);
    //----------------------------
   }
 //----------------------------------------
}
//+------------------------------------------------------------------+
int Get_magic(int deal_number)
{
 //--------------------------------------------
 //Получаем начало строки магика.
 //--------------------------------------------
 int Magic_position_start =  StringFind(All_magics,"_" + (string)deal_number + "_",0) + 3;
 //--------------------------------------------
 //Получаем конец строки магика.
 //--------------------------------------------
 int Magic_position_end   =  StringFind(All_magics,"_" + (string)(deal_number + 1) + "_",0);
 //--------------------------------------------
 //Получаем количество цифр из которых состоит магик.
 //--------------------------------------------
 int Magic_lenght         =  Magic_position_end - Magic_position_start;
 //--------------------------------------------
 //Извлекаем магик из общей строки.
 //--------------------------------------------
 string Magic             =  StringSubstr(All_magics,Magic_position_start,Magic_lenght);
 //--------------------------------------------
 //Возвращаем цифровое значение магика.
 //--------------------------------------------
 return((int)Magic);
}
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Trading();
   //--------------------------
   ulong t1 = GetMicrosecondCount();
   Get_magic(1);
   ulong t2 = GetMicrosecondCount();
   //--------------------------
   Print("Время исполнения функции Get_magic() при количестве ордеров ",Random_orders_of_strategy," равно ",t2 - t1);
   //--------------------------
   Print("Random_orders_of_strategy  ",Random_orders_of_strategy);
   Print("magic 1:  ",Get_magic(1),"  magic 2: ",Get_magic(2),"  magic 3: ",Get_magic(3));
   
  }
//+------------------------------------------------------------------+


Maybe someone will find my solution useful...

(the code finds the right magic out of more than 24,000 magic orders in 15 microseconds!)

(Also, not a byte of extra memory is wasted.)

If someone can make it faster, please.
 
Sergey Dzyublik:

If we add three magic numbers: 10, 11, 12
Then what are their transaction numbers? 0, 1, 2?

No. Deal numbers must start with one.
 

This is an interesting question on the subject:

For example, there is a multi-currency EA in which the next lot of the next order is based on results of orders already opened on different pairs


condition of opening an order - if there is a signal to open it, the total lot does not exceed 0.1 and the total drawdown is not more than 101% of the deposit

Option one: fill all data into the array and retrieve it when the next order is requested (we won't open new orders every tick)


Version two - each time we issue a request to open the next order, we should check all data available at the current time for all pairs



Which solution will be faster and less costly?

 

Bummer )