MQL5- Loop to check if position is profiting or losing?

Discussion in 'MetaTrader 5' started by johnnybegoode, Jan 12, 2017.

  1. johnnybegoode

    johnnybegoode Trader

    42
    0
    22
    MQL5- Loop to check if position is profiting or losing?

    How to look for profiting and looking positions?

    Returning the ticket/deal numbers
     
  2. Enivid

    Enivid Administrator Staff Member

    7,799
    253
    114
    Something like this:

    Code (MQL5):

    for (int i = 0; i < PositionsTotal(); i++)
    {
       ulong ticket = PositionGetTicket(i);
       if (ticket <= 0)
       {
           Print("Failed to select position.");
           continue;
       }

       if (PositionGetDouble(POSITION_PROFIT) > 0) Print("Profitable position, ticket = ", ticket);
       else if (PositionGetDouble(POSITION_PROFIT) < 0) Print("Losing position, ticket = ", ticket);
       else if (PositionGetDouble(POSITION_PROFIT) = 0) Print("Breakeven position, ticket = ", ticket);
    }
     
     

Share This Page