Only one buy and one sell position at any point of time

 

Hi, i was looking throught the forum traying to find aswers to my question but found nothing.

Im pretty new to MQL but trying my best.

Well, the question is I have this code but it only opens one buy position. I would like to have second set of code to open one sell position based on different rule.

I need to basicaly use the OrdersTotal for only open buy positions and then use different OdersTotal for sell postions so then i can control how many trades i can open for either buy or sell.

If I just say total < 2 then it might open two same direction position which i dont want.

Any tips on how to code that?

int ticket, total;

total = OrdersTotal();

if(total < 1)
{
  if(cRSIBuy==true)
    {
     ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"My order #2",16384,0,Green);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
    }
}


if (total > 0)
OrderSelect(Symbol(),SELECT_BY_POS,MODE_TRADES);
{
if(cRSISell==true)
   {
   OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
   return(0);
   }
}
Reason: