Download MetaTrader 5

A little help with coding

To add comments, please log in or register
All articles are available from MetaTrader 5. Contribute your own one!
christarola
6
christarola 2015.01.09 20:27 

Hi all

i need a little help with this part of a code

At the moment with this code my ea opens maximum two orders each time but the problem is that if there is a second order it could be either a second buy or a second sell and i only need it to be able to open one sell and one buy .I'm not a programmer so please answer me as simple as possible

bool TradeNotPlacedYet()
{
   int total = OrdersTotal();
   if (total > 1)
   {
      for(int cnt=total-1;cnt>=0;cnt--)
      {
         if(OrderSelect(cnt,SELECT_BY_POS))
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
            {
               return (false);
            }
         }
      }
   }
   int histotal = OrdersHistoryTotal();
   if (histotal > 1)
   {
      for(cnt=histotal-1;cnt>=0;cnt--)
      {
         if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
            {
               if (OrderOpenTime() >= Time[0])
               {
                  return (false);
               }
            }
         }
      }
   }
   return (true);


To add comments, please log in or register