What is the role of "count" variable?

 
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----


   double ABUY=0;
   double ASELL=0;
   double BBUY=0;
   double BSELL=0;
   double HABUY=0;
   double HASELL=0;
   double HBBUY=0;
   double HBSELL=0;
   double point = MarketInfo(Symbol(),MODE_POINT);
   double expiration=CurTime()+PERIOD_D1*60;

   int pos;
   int n;

   int total= OrdersTotal();
   for( n=0; n<total; n++ ){                                                 // count orders
      if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) )
         continue;

      if( OrderSymbol()==Symbol() )
         continue;
      
      if( OrderMagicNumber()== 1 && OrderType()== OP_BUY ){
      ABUY=2;   //                                                              it's A BUY order
     }
      else if( OrderMagicNumber()== 1 && OrderType()== OP_BUYSTOP ){
      ABUY=1;   //                                                              it's A BUY pending order
     }
      else if( OrderMagicNumber()== 2 && OrderType()== OP_SELL ){
      ASELL=2;   //                                                             it's A SELL order
     }    
      else if( OrderMagicNumber()== 2 && OrderType()== OP_SELLSTOP ){
      ASELL=1;   //                                                             it's B SELL pending order
     }  
      else if( OrderMagicNumber()== 3 && OrderType()== OP_BUY ){
      BBUY=2;   //                                                              it's B BUY order
     }
      else if( OrderMagicNumber()== 3 && OrderType()== OP_BUYSTOP ){
      BBUY=1;   //                                                              it's B BUY pending order
     }
      else if( OrderMagicNumber()== 4 && OrderType()== OP_SELL ){
      BSELL=2;   //                                                             it's B SELL order
     }    
      else if( OrderMagicNumber()== 4 && OrderType()== OP_SELLSTOP ){
      BSELL=1;   //                                                             it's B SELL pending order
     }
       else {                                                                   //IF THERE IS NO ORDERS -> SEND ORDERS
       if (!OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+6*point,4,Bid-52*point,Bid+20*point,"A BUY",1,expiration,Blue)){
       Alert("Disabled to send A BUY", GetLastError()); 
       }
       else if (!OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-8*point,4,Ask+50*point,Ask-22*point,"A SELL",2,expiration,Green)){
       Alert("Disabled to send A SELL", GetLastError());
       }
       }
     }
  
//----
   return(0);
  }

Strategy is loded, deinitialized, uninit reason 1 and removed and initialized. - THATS ALL.

I want it to change the variables or send orders if there is no any orders open.

If you know what is wrong with that, than help me please...

 
BorysekPL:

Strategy is loded, deinitialized, uninit reason 1 and removed and initialized. - THATS ALL.

I want it to change the variables or send orders if there is no any orders open.

If you know what is wrong with that, than help me please...


what i see first...

if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) )
continue;

if( OrderSymbol()==Symbol() )
continue;

mean, if select a order should continue in the loop with the next and do not fullfill the code below

or if the order symbol match with the symbol from chart then continue with next and do not fullfill code below.

u mean something like

if (OrderSelect(n,....)

{

if( OrderSymbol()!=Symbol() ) continue;
and then the rest ...

}

 
EADeveloper:


what i see first...

if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) )
continue;

if( OrderSymbol()==Symbol() )
continue;

mean, if select a order should continue in the loop with the next and do not fullfill the code below

or if the order symbol match with the symbol from chart then continue with next and do not fullfill code below.

u mean something like

if (OrderSelect(n,....)

{

if( OrderSymbol()!=Symbol() ) continue;
and then the rest ...

}

 
  for( n=0; n<total; n++ ){                                                 // count orders
      if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) )
         continue;

      if( OrderSymbol()==Symbol() )
         continue;
Use forward logic, move your test out of the loop, you must count down in the presense of multiple order (multiple charts)
    int count=0;
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
        count++;
    }
    if (count == 0){ ...
 

WHRoeder:
Use forward logic, move your test out of the loop, you must count down in the presense of multiple order (multiple charts)

 int count=0;
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
        count++;
    }
    if (count == 0){ ...

//What is the role of "count" variable?