Download MetaTrader 5

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

To add comments, please log in or register
Add our Twitter channel to friends and follow the news!
Josh Calow
39
Josh Calow 2016.03.17 12:36 

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.

Keith Watford
Moderator
9624
Keith Watford 2016.03.17 12:51  
  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
Josh Calow
39
Josh Calow 2016.03.17 13:55  
Thank you very much for this. I will give it a try.
Josh Calow
39
Josh Calow 2016.03.18 15:43  
Worked great, Thank you!
To add comments, please log in or register