Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 613

 
Tigerfreerun:
If (OP_BUY==0)

Why are you misleading? You either don't know yourself, then please keep your ignorance out of a HELP thread or you are just kidding around but forgot that you are in a serious beginner's help thread.

SanNneK:
here's the condition if all orders are zeroif(OrdersTotal()==0). and what condition to write if there are zero bays?

We need to loop through all orders and calculate the number of orders with OrderType()==ORDER_TYPE_BUY

 
Artyom Trishkin:

Why are you misleading? Either you don't know, then please keep your ignorance out of a HELP thread, or you're just kidding around, but you forgot you're in a serious beginner's help thread.

I need to loop through all orders and calculate the number of orders with OrderType()==ORDER_TYPE_BUY.

Hear hear. I would appreciate it if you could help me with this function, which I wrote about on previous page. I myself use this function for counting orders:

int Count(int type,string sy)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {if(sy==OrderSymbol() && OrderMagicNumber()==Magic && (type==-1 || OrderType()==type)) count++;}
     }
   return(count);
  }
 
Tigerfreerun:

Hear hear. I would be grateful if you could help with the function I wrote about on the last page. I myself use this function for counting orders:

What kind of help do you need? It's quite a working function in Kim's style.
 
Alexey Viktorov:
What help do you need? It's quite a working function in Kim's style.

On the last page I wrote a function with an error incorrect start position 0 for ArraySortfunction. And a request for an explanation of the function. I'm duplicating

void MaxMinProfit()
{
int i, N, MaxTic, MinTic;
double   MinProf=0, MaxProf=0, OP, g, a[][2];
string MinSym, MaxSym;
ArrayResize(a, 0);
 
for (i=OrdersTotal()-1; i>=0; i--) 
  {    
   if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 
    { 
     if (OrderType()==OP_SELL ||  OrderType()==OP_BUY )
      {
       OP = NormalizeDouble(OrderProfit()+OrderSwap()+OrderCommission(),2);
       
      if (MinProf>OP) 
      {
       
          MinProf=OP;
          MinTic=OrderTicket();
          MinSym=OrderSymbol();
          
         }
         
      if (OP>0) 
      {
       
          N++;
            ArrayResize(a, N);
            a[N-1][0]=OP;
            a[N-1][1]=OrderTicket();
          
         }
         
         }
         }
         
         }
         
      ArraySort(a, WHOLE_ARRAY, 0, MODE_DESCEND);//MODE_ASCEND);
      
      for (i=0; i<Level; i++) 
       {
     
     g+=a[i][0];
     //int ti=a[i-2][1];
     }
         
         
     
     if(MinProf <0 && (g+MinProf)>=ProcMax)
      {
       for (i=0; i<Level; i++) 
       {
       if (OrderSelect(a[i][1], SELECT_BY_TICKET, MODE_TRADES))
        {
        //Alert(a[i][1]);
         if (OrderType()== OP_BUY)
         {
          OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), Slip, CLR_NONE);
          }
          if (OrderType()== OP_SELL)
           {
           OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), Slip, CLR_NONE);
           }
          }
         }
          
          
          
          if (OrderSelect(MinTic, SELECT_BY_TICKET, MODE_TRADES))
        {
         if (OrderType()== OP_BUY)
         {
          OrderClose(MinTic, OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), Slip, CLR_NONE);
          }
          if (OrderType()== OP_SELL)
           {
          OrderClose(MinTic, OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), Slip, CLR_NONE);
           }
          }}       
return;
}
 

What is the best way to pass parameters between class elements, which in turn are also class elements?

Given:

class element{
public:
int a;
        void fnc(){
        a++;            
        }
};

class elementBase{
public:
	 int b;
        element one;
        element two;
};

Is there any way to change the value of two.a from the function a.fnc() ?


In my problem, variables from class two should be recalculated when elements in class one are changed. (Can you tell me how to do it nicely?)

Is there any way to get the value of b fromelementBase class?

 
Tigerfreerun:

On the last page I wrote a function with an error incorrect start position 0 for ArraySortfunction. And a request for an explanation of the function. Duplicate

The direction to think: If profit is less than zero... what will be the size of the array during sorting???

What will be the size of the array if there are no orders at all???
 
Alexey Viktorov:

Direction to think about: If the profit is less than zero... what size will the array be during sorting???

And what size will the array be if there are no orders at all???
I do not really understand what exactly this function does. But, as the author mentioned, my task is to overlap losing orders with profitable ones between symbols. I would be glad if you could help me correct and understand this function.
 
Tigerfreerun:
I don't really understand what exactly this function does. But as the author has said, its task is to overlap losing orders with profitable ones between symbols. I would be glad if you could help me fix and understand the function

What are your compilation errors? Show a screenshot.

There are no errors in the code, but there are some minor flaws that don't affect the functionality

 
Vitaly Muzichenko:

What are your compilation errors? Show a screenshot.

There are no errors in the code, but there are some minor bugs that do not affect performance

When running the robot "incorrect start position 0 for ArraySortfunction." could you explain this function, maybe I'll understand what's wrong...
Files:
yOXZsAXZ-X4.jpg  479 kb
Pe3JLH8tgCc.jpg  556 kb
 
Tigerfreerun:
When my robot starts "incorrect start position 0 for ArraySortfunction." could you explain this function, maybe I will understand what's wrong...

Well, you have shown the non-critical errors.

How the function works, you have answered it yourself:

Forum on trading, automated trading systems and trading strategy testing

Any questions newbies have on MQL4, help and discussion on algorithms and codes

Tigerfreerun, 2018.09.06 21:53

I don't really understand exactly what this function does. But as the author said - the task is to overlap losing orders with profitable ones between the symbols. I would be glad if you could help me to correct and understand this function

Reason: