The task of searching for orders - page 3

 
Игорь Герасько:

When implementing different "grids" I came up with the following structure:

The structure is filled in on every new tick, based on the Magic Number value (it stores all the information needed to identify the order: order number, which grid it belongs to, etc.).

This is the code I came up with

class Info
  {
private:
   struct str
     {
      string            Sym;                                // Символ ордера
      string            Com;                                // Коммент ордера
      int               Tic;                                // Тиккет ордера
      int               Typ;                                // Тип ордера
      int               Mag;                                // Меджик номер ордера
      double            Lot;                                // Лот ордера
      double            Pri;                                // Цена открытия ордера
      double            SL_;                                // Стоп лосс ордера
      double            TP_;                                // Тейк профит ордера
      datetime          Tim;                                // Время открытия ордера
      double            Pro;                                // Профит ордера
     };
   int               m_tick_upper;                          // Тиккет максимального по цене ордера
   int               m_tick_upper_;                         // Тиккет предпоследнего максимального по цене ордера
   int               m_tick_lower;                          // Тиккет минимального по цене ордера
   int               m_tick_lower_;                         // Тиккет предпоследнего минимального по цене оредра

   int               m_tick_start;                          // Тиккет первого по времени ордера
   int               m_tick_start_;                         // Тиккет вторго по времени ордера
   int               m_tick_end;                            // Тиккет последнего по времени ордера
   int               m_tick_end_;                           // Тиккет предпоследнего по времени ордера

   int               m_magic;                               // Меджик номер
   string            m_symbol;                              // Символ ордера

   void              SearchTicketPriceType(const int type); // Поиск по цене
   void              SearchTicketTimeType(const int type);  // Поиск по времени

public:

   str               Price_Max;                             // Структура запроса максимальных ценн
   str               Price_Min;                             // Структура запроса минимальных  ценн
   str               Time_End;                              // Структура последних ордеров
   str               Time_Start;                            // Структура начальных ордеров

   str               Price_Max2;                            // Структура запроса максимальных ценн
   str               Price_Min2;                            // Структура запроса минимальных  ценн
   str               Time_End2;                             // Структура последних ордеров
   str               Time_Start2;                           // Структура начальных ордеров

   void              SetMagic (const int    mag) { m_magic  = mag; } // Принудительное указание меджик номера
   void              SetSymbol(const string sym) { m_symbol = sym; } // Принудительное указание символа

   void              SearchTimeOrder(const int type);       // Заполнение структуры по времени      
   void              SearchPriceOrder(const int type);      // Заполнение структуры по ценам 

                     Info(const string sym,const int mag);  // Параметрический конструктор
                     Info(){};
                    ~Info(){};
  };
 
Михаил:
...

"By the way - if the Windows is down, the EA cannot delete orders either - only manual here, so this example cannot fully apply to auto-trading."

POSSIBLE, you probably don't know how. If interested I can post the code.

Nah, you don't need the code. Algorithm in brief, if you can... I really don't know how to run an EA in a terminal running in a crashed OS
 
Artyom Trishkin:
No, you don't need a code. Algorithm in a nutshell, if you can... I really don't know how to run an EA in a terminal running in a crashed OS

It's easier for me to lay out the code than to explain it:

//+------------------------------------------------------------------+
//| Expert Remove orders function                                    |
//+------------------------------------------------------------------+
void RemoveOrders()
{
  int orders_total = OrdersTotal();
//---  
  if ( orders_total > 0 )
  {
    for ( int i = 0; i < orders_total; i++ )
    {
      ulong temp_order_ticket = OrderGetTicket( i );
      
      if ( OrderSelect( temp_order_ticket ) )
      {
        string temp_symbol = OrderGetString( ORDER_SYMBOL );
        
        if ( temp_symbol == _Symbol )
        {
          RemoveOldOrder( temp_symbol, temp_order_ticket );
        }
      }
    }
  }
}

//+------------------------------------------------------------------+
//| Expert remove old order function                                 |
//+------------------------------------------------------------------+
void RemoveOldOrder( const string symbol, const ulong ord_ticket )
{
  MqlTradeRequest request = {0};
  MqlTradeResult  result  = {0};
  
  request.action = TRADE_ACTION_REMOVE;
  request.order  = ord_ticket;
  
   if ( OrderSend( request, result ) )
   {
     if ( result.retcode == TRADE_RETCODE_PLACED )
     { 
//        SetTransCount( true );
     }
  }
  else
  {
    Print( "Удаление старого ордера не выполнено! Билет = ", ord_ticket);
  }
}
 
Vladimir Pastushak:

This is the code I came up with

Shit, man, *** don't bullshit. You yourself defined the right direction: state should be recovered from the current environment, what MT gives you is the most reliable option. Instead of it, you write a long and useless class Info, into which you have to somehow cram the values found by external functions. Yes, eventually it will contain the variables you need: maximum and minimum ticket in terms of price for the order, as well as other important for you stuff. But in reality the problem is solved by a specialized container of orders: Imagine you have a list of orders, where each order represents a table row with many columns (order id, open time, open price, profit, etc., etc.). You do sorting by one of the columns, and get exactly the sequence you need. So, all this can be done with help of classes, which you like to use (though clueless, sorry). I'll write how to do it tomorrow, if you're interested.
 
Vasiliy Sokolov:
Shit, man, *** don't bullshit. You yourself have defined the right direction: state should be recovered from the current environment, what MT gives you is the most reliable option. Instead of it, you write a long and useless class Info, into which you have to somehow cram the values found by external functions. Yes, eventually it will contain the variables you need: maximum and minimum ticket in terms of price for the order, as well as other important for you stuff. But in reality the problem is solved by a specialized container of orders: Imagine you have a list of orders, where each order represents a table row with many columns (order id, open time, open price, profit, etc., etc.). You do sorting by one of the columns, and get exactly the sequence you need. So, all this can be done with help of classes, which you like to use (though clueless, sorry). How to do it - I'll write tomorrow, if you're interested.

Very eager to see....

I need information not for the sake of information, but for further processing and calculation ...

 
Михаил:

It's easier for me to post the code than to explain it:

How will it work on a broken computer? (no surprise at all with the functions).

That's why I said - I don't need code. I need an algorithm that works on a computer that doesn't work (the axis is broken, if you remember a quote: "I really don't know how to run the Expert Advisor in the terminal, which is running on the crashed OS", and I don't need VPS and other stuff - think, that the OS on the computer, server, etc., where the terminal with the Expert Advisor is running, is crashed - your code is a poultice for it there and ... ).

 
Artyom Trishkin:

How will it work on a broken computer??? (no surprise at all with the functions).

That's why I said - I don't need code. I need an algorithm that works on a computer that's not working (because the OS is down, if you remember - and I quote: "I really don't know how to run the Expert Advisor in the terminal, which is running on the crashed OS", and I don't need VPS and other stuff - think, that the OS on the computer, server, etc., where the terminal with the Expert Advisor is running, is crashed - your code is a poultice for it there and ... With your code and ... ).

Here we go, forger in the forest...

Let's finish our discussion here!

 
Михаил:

Here we go, for better or for worse...

Let's end our discussion here!

No problem. I'm sick and tired of trying to make my point...
 
Artyom Trishkin:
No problem. I'm sick of trying to get my point across...

The bottom line is that even if the operating system on the server is down, you can run a home PC that will restore control of the account at the time that is required to restart the servo.

In my practice of working with the VDS / VPS servers OS has never flipped, but restarts are unforeseen and scheduled happens.

The essence of my question is to competently write code which collects information about current situation...

 
Vladimir Pastushak:

...

The point of my question is to correctly write code that collects information about the current situation...

You wrote here that you have already written in procedural style. So, all you have to do is to collect it all into a class. You can also remove some parameters from function call, make methods for presetting parameters (magik, symbol), but it's better not to do.

Of course if there is nothing to do, you can go another way. Class. It has method Refresh() to get list of orders (the only one that can return false). The other methods use this list.

Reason: