How to check if all previous open trades for pair are in profit?

 

I am currently building an EA to automate part of my trading system. However, I am unsure how to program one of the criteria.

I only want the EA to place trades when all current open orders for the currency pair are all in profit. These could be both manual trades and EA placed trades. I believe I need to use an If function and the OrderSelect command but am unsure how to set the profit criteria.

Could someone please point me in the direction of a snippet of code that would give me some hints?

Many thanks.

 
  bool can_place_trades=true;
  for(int x=OrdersTotal()-1;x>=0;x--)
     if(OrderSelect(x,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderProfit()<=0)
        {
        can_place_trades=false;
        break;
        }
  if(can_place_trades)
     {
     //Check conditions to place trades
     } 
not tested
 
Thank you very much for this. I will give it a try.
 
Worked great, Thank you!