Is this code outdated in MQL5 Counting the number of long Position, Please help me look into it. thanks

 
#include <Trade\Trade.mqh>


#define MagicNumber = 0;   // Magic number

int OnInit()
{  

return(INIT_SUCCEEDED);

}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()

 {
    Comment("Number of Buy Positions: = ", OrdersCounter()); 
 }
  
  
//---------------------------------------------------------------  
int OrdersCounter()
  {
   int counter=0;
//---
   for(int i=OrdersTotal()-1; i>=0; i--) 
   {
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() && OrderType() == OP_BUY)
    // if((OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) && (OrderSymbol() == Symbol()) && (OrderType() == OP_BUY))
              {
               counter++; //count the Position
              }
           
   return counter;
   
    }
    
  //----------------------------------------------------------------
 
 




   
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. You are counting orders not positions.
    MT5: first select a position via CPositionInfo, directly, or by 'MT4Orders' library (2016)

  3. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

 
Darker Host:
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() && OrderType() == OP_BUY) 

You are using MQL4 trade functionality. It will not work in MQL5.

 
Fernando Carreiro #:

You are using MQL4 trade functionality. It will not work in MQL5.

My God..... thanks Fernando Carreiro. Have suffer a lot before asking for help
 
Darker Host #: My God..... thanks Fernando Carreiro. Have suffer a lot before asking for help

Use William Roeder's suggestions in his post for alternative MQL5 code ... "MT5: first select a position via CPositionInfo, directly, or by 'MT4Orders' library (2016)"

 
Fernando Carreiro #:

Use William Roeder's suggestions in his post for alternative MQL5 code ... "MT5: first select a position via CPositionInfo, directly, or by 'MT4Orders' library (2016)"


Thank you sir, I will look into it.