Download MetaTrader 5
To add comments, please log in or register
Find out how to install MetaTrader on Linux
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
7888
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