List of Open Order in Hedge Account MT5

 

Dear,

I wrote a function for get total profit to open by EA. but my function not work.  I notice OrdersTotal() only send pending order only, but how i get open order only.

Please someone help me to correct below coding.


int Profit()
{
     double total_profit=0;
     ulong    ticket;

     for (i=OrdersTotal()-1;i>=0;i--) 
     {
         if((ticket=OrderGetTicket(i))>0) 
         { 

               if  ( (OrderGetInteger(ORDER_MAGIC)==MAGICNUMBER ))  
               {
                  total_profit+= ( PositionGetDouble(POSITION_PROFIT) - PositionGetDouble(POSITION_COMMISSION) - PositionGetDouble(POSITION_SWAP) ) / OrderGetDouble(ORDER_VOLUME_INITIAL) / SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE) / ( five ? 10 : 1 );     
               } 
         }
     }  

    return(total_profit);
    
}
Reason: