The task of searching for orders - page 13

 
Vladimir Pastushak:
Yeah, I thought maybe someone knew better ....
   double Max1=0;
   double Max2=0; 
   
   int Ticket1=0;
   int Ticket2=0;

   int t=OrdersTotal();
   for(int i=0;i<t;i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderMagicNumber()==Magic && OrderSymbol()==Symbol()){
            if(OrderType()==OP_BUY){
               if(OrderOpenPrice()>Max1){
                  Max2=Max1;
                  Ticket2=Ticket1;                  
                  Max1=OrderOpenPrice();
                  Ticket1=OrderTicket();
               }
               else if(OrderOpenPrice()>Max2){
                  Max2=OrderOpenPrice();
                  Ticket2=OrderTicket();                  
               }
            }
         }
      }
      else{
         return(false);
      }
   }

There is no quicker way. If you want faster, you need to think about the whole EA algorithm, maybe you can get rid of the need to look for two bottoms, two tops on every tick.
 
Dmitry Fedoseev:

There is no quicker way. If you need faster, you should think about the entire algorithm of the EA, maybe you can get rid of the necessity to search for two lower, two upper orders on every tick.

In your variant the data will be equal, i.e. the first and the second top order will have the same ticket

Sorry about that ...

 

I did this

void OrdersInfo :: SearchTicketPriceType()
  {
   double   price_max=0,price_min=0,price_max2=0,price_min2=0,op=0;
   int      tc=-1;
   m_tick_upper  = 0;
   m_tick_upper_ = 0;
   m_tick_lower  = 0;
   m_tick_lower_ = 0;
   Counter=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==m_magic || m_magic==-1)
            if(OrderSymbol  ()==m_symbol || m_symbol==NULL)
               if(OrderType()==m_type_order)
                 {
                  Counter++;
                  op=OrderOpenPrice();
                  tc=OrderTicket   ();
                  //---
                  if(op>price_max) // Самый верхний ордер
                    {
                     price_max=op;
                     m_tick_upper=tc;
                    }
                  if(op<price_min || price_min==0) // Самый нижний ордер
                    {
                     price_min=op;
                     m_tick_lower=tc;
                    }
                  if(tc!=m_tick_upper) // Предпоследний верхний ордер
                     if(op>price_max2)
                       {
                        price_max2=op;
                        m_tick_upper_=tc;
                       }
                  if(tc!=m_tick_lower)
                     if(op<price_min2 || price_min2==0) // Предпоследний нижний ордер
                       {
                        price_min2=op;
                        m_tick_lower_=tc;
                       }
                  //---
                 }
  }
 
Dmitry Fedoseev:

It is better to simply assemble functions for different tasks, specifically sharpened for these tasks, than to try to make something universal.


100%

If you make a portable solution, it is bound to be redundant in some part when applied to a specific task. The more universal you try to make it, the longer the tail of redundancy will be. It's worth stopping in time so that this redundancy will not complicate the life of the coder and the product.

 
Vladimir Pastushak:

I did this

Does it work properly, have you checked?
 
Dmitry Fedoseev:
Does it work properly, have you checked?
I think so ))) ...
 
Alexander Puzanov:


100%

If you make a transferable solution, it is bound to be redundant in some part when applied to a particular task. The more universal you try to make it, the longer the redundancy tail will be. It's worth stopping in time so that this redundancy will not complicate the life of the coder and the product.

I'm trying to switch to OOP for some reason. It's written in praises of OOP that it allows you to collect and catalogue a lot of functions, I had files with a lot of functions before... I thought to file everything, but if for any case it is necessary to have a separate variant then the sense of catalogues of libraries disappears...

It turns out that to avoid redundancy in 99% of cases we still need to write all the code by hand... From scratch I mean...

 
Vladimir Pastushak:
I think so ))) ...
Yeah. Norm.
 
Dmitry Fedoseev:
Yeah. All right.
That's what I wanted when I created this thread, thank you all!
 
Vladimir Pastushak:
That's what I wanted to get by creating this thread, thanks everyone !

I'm not OTK:) Test on orders in the tester or on a demo account. You can be wrong at first glance.

Reason: