Errors, bugs, questions - page 1914

 
nys2000:

Could you be more specific?


start from scratch

 
nys2000:

Could you be more specific?

for(i=1; i <=OrdersTotal(); i++) Orders in this list are numbered from zero to OrdersTotal()-1 inclusive (let Artem Trishkin excuse me, just shortened the wait for nys2000).
 
Aleksei Beliakov:

start from scratch


These are two equivalent options. If for (i=1...) then OrderSelect(i-1,...), if for (i=0,...) - OrderSelect(i,...)

 
Vladimir:
for(i=1; i <=OrdersTotal(); i++) Orders in this list are numbered from zero to OrdersTotal()-1 inclusive (let Artem Trishkin excuse me, just shortened the wait for nys2000).

Thanks, but the numbering of orders from 0 to OrdersTotal()-1 is taken into account in OrderSelect(i-1,...)

 
int OrdersTotalT(int _type)
  {
   int _total=0;
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {

      bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()==_type)
        {
           _total++;
        }
     }
   return(_total);
  }
 
nys2000:

Thank you, but the numbering of orders from 0 to OrdersTotal()-1 is accounted for in OrderSelect(i-1,...)


Do the reverse order of the search ...

 
nys2000:

Here's a simple code like this:

At the moment the function is started, two Buy positions are open. The function prints the presence of two orders twice: Passage 1, Passage 2.

We remove the comments and run the function again. It vigorously takes down one buy order, declares "Passage #1" and leaves the loop. The message "Passage #2" does not appear.

What is the magic?


1. i=1, we calculated the orders ... checked condition 1<= 2 ? yes. Selected and closed the order.

2. i++ (i=2)

3. OrdersTotal()=1 <---------- by closing the order inside the loop actually changed the condition to exit the loop

4. 2<=1 ? no <----------- here your "magic" and accordingly exit from the loop

void CloseAllOrders()
{
bool Ans;
int total=OrdersTotal();
   for(int i=1; i <=total; i++)     
      {      
      Print("Проход № ", i);      
      if (OrderSelect(i-1,SELECT_BY_POS)==true) 
         {  
         if (OrderSymbol() != Symbol())
            continue;
         if (OrderType()==0)
             {
//            Ans=OrderClose(OrderTicket(),OrderLots(), NormalizeDouble(Bid,Digits),25);
             }           
         if (OrderType()==1)
             {
//            Ans=OrderClose(OrderTicket(),OrderLots(), NormalizeDouble(Ask,Digits),25);
             } 
         }
      }      
         
return;
   
}
 

why is there an additionalCHART_WINDOW_HANDLE chart ID, what purpose does it serve?

 
Konstantin:

why is there an additionalCHART_WINDOW_HANDLE chart ID, what purpose does it serve?

I will assume that the chart ID is for mql environment and HWND is for winapi.
 

Error during execution

int f( int t )
{
union U {
        U( int t ) : t1( t ) {}
        int t2;
        int t1;
};
	U u( t );
        return u.t2;
}
void OnStart()
{
        Print( f( 3 ));
}

Result: random number (certainly not 3)
Reason: