Download MetaTrader 5
To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
web11
253
web11 2016.07.04 08:40 

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);
    
}
/
To add comments, please log in or register