Algorithms, solution methods, comparison of their performance - page 5

 
Vasiliy Sokolov:

Peter, are you drunk? In the substring of ..._25_... four characters: _, 2, 5, _.

Yes, you're right. I missed that.

But we can fix it.

 
Vasiliy Sokolov:

In the substring ..._25_... four characters: _, 2, 5, _.

Not all of them can be accounted for. Thanks for pointing out the specific error.
 
Реter Konow:

Yes, you're right. Missed that point.

But it can be fixed.

Apparently, the patient is incurable.

 

I'll fix the code and post it.

Please wait.

By the way. Emotions may be tempered. There's nothing wrong with it.

 
Реter Konow:

I'll fix the code and post it.

Please wait.

Hey. Emotions may be tempered. There's nothing to worry about.


It's happening. What's dead doesn't want to die.

 

Done:

//+------------------------------------------------------------------+
//|                                                        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 stringlen = StringLen((string)deal_number); //добавлено
 //--------------------------------------------
 //Получаем начало строки магика.
 //--------------------------------------------
 int Magic_position_start =  StringFind(All_magics,"_" + (string)deal_number + "_",0) + stringlen + 2;
 //--------------------------------------------
 //Получаем конец строки магика.
 //--------------------------------------------
 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(1000);
   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));
   
  }
//+------------------------------------------------------------------+
 

Peter, your example is inherently delusional and unworkable. In the real world, the transaction number is always random. You can't write:

//--------------------------------------------
 //Получаем конец строки магика.
 //--------------------------------------------
 int Magic_position_end   =  StringFind(All_magics,"_" + (string)(deal_number + 1) + "_",0); //тут по идее снова начинается поиск и он уже идет с самого начала снова не знаю зачем искать еще раз, надо хотябы поиск начинать с тагоже места где нашли начало маджика чтоли... и искать просто подчеркивание... 

We don't know the next transaction number.

 
Vasiliy Sokolov:

In the real world, the transaction number is always random. You can't write:

We don't know the next transaction number.

Not really.

Let's say we are trading and we have already made 300 trades.

If we need to get any medjic before the 300th trade, we always have the next trade number.

If we need to get the number of the 300th trade, then... we can always keep the number of the last trade in a variable.

 

The code is certainly not perfect so that it can be applied immediately to trading. It simply demonstrates an approach to the solution. It can be fine-tuned.

 
Реter Konow:

Not really.

Let's say we are trading and have already made 300 trades.

If we need to get any medjic before the 300th trade, we always have the number of the next trade.

If we need to get the number of the 300th deal, then... we can always keep the number of the last trade in some variable.


What's wrong with a regular array of ints? what's the point of the thongs.... Again, imagine that instead of a string, you use a class that stores a dynamic array of charts - and you think that's fast?