Can't count pending orders

 

Hello everyone, I have a simple problem with Buy-Limit order

I want just one order to put but while backtesting I see unlimited orders put every tick

and these are my codes

if ( BuyLimit () < 1 )
if ( Buys     () < 1 )
                    {
                    trade.SetExpertMagicNumber(MagicNumber);
                    trade.BuyLimit( LotF       ,    Ask - .0005,   _Symbol    ,    Ask - .0065,   Bid        ,  0    );   
                    }           

while :


int Buys()
 {
  int B=0,i;
  for ( i=0; i<PositionsTotal();  i++){ 

    if (  Symbol() == PositionGetSymbol(i)   && MagicNumber==PositionGetInteger(POSITION_MAGIC)  && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY
       )
       { B++;}
                                      }
           return(B);
       }
///////////////////////////////
int BuyLimit()
  {
 int BL=0,i;
 for ( i=0; i<OrdersTotal();  i++ )
         { OrderSelect(OrderGetTicket(i));
           if ( Symbol()    == PositionGetSymbol(i) &&  MagicNumber == PositionGetInteger(POSITION_MAGIC)&&  (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_LIMIT
              )
                           
    { BL++;}
    }
  return(BL);
}  

I hope if there are mistakes in my codes, I discover them

Thanks

 
Show your OnInit.
 
Vladimir Karputov #:
Show your OnInit.

Just This :

int OnInit()
            {
             if (_Digits==4 || _Digits<=2) MyPoint=_Point;
             if (_Digits==3 || _Digits==5) MyPoint=_Point*10;   
              return(INIT_SUCCEEDED);
            }
 
Amgad Samir Nassief Abdelmalek # :

Just This :

You have to do it in OnInit ()

   m_trade.SetExpertMagicNumber(InpMagic);
 
Vladimir Karputov #:

You have to do it in OnInit ()

I tried it but this error appeared after compile 

"m_trade" -undeclared identifier  

 
Amgad Samir Nassief Abdelmalek # :

I tried it but this error appeared after compile 

"m_trade" -undeclared identifier  

Everything is correct. I gave you my template. My object is named 'm_trade' - your object is named 'trade'.

 
Vladimir Karputov #:

Everything is correct. I gave you my template. My object is named 'm_trade' - your object is named 'trade'.

My EA works after deleting 

 Symbol()    == PositionGetSymbol(i) &&  MagicNumber == PositionGetInteger(POSITION_MAGIC)&& 

and

OrderSelect(OrderGetTicket(i));

So, There are problems with the definitions of Symbol and Magic Number 

 
Amgad Samir Nassief Abdelmalek # :

My EA works after deleting 

and

So, There are problems with the definitions of Symbol and Magic Number 

Yes, you have a problem - you are designing the EA incorrectly. You are not doing the required initialization.

You have to do this in OnInut:

Forum on trading, automated trading systems and testing trading strategies

Can't count pending orders

Vladimir Karputov, 2021.11.25 07:25

You have to do it in OnInit ()

   m_trade.SetExpertMagicNumber(InpMagic);

Reason: