Solution for a stupid question?

 

Hi!!

I've been looking for a solution for my problem but I've not found it. I think this is an stupid question from a non programmer like me :))

I've never had this problem before because always I've written EA with only one position at the same time. Now I'm writting one EA that open several position at the same the time. The problem is that I want open one trade per signal and I get several position per signal at the same time. i.e. open buy if CCI tf240 >0 && CCI tf5 croos up 0 lline, in this case I'll have one buy each time CCI in M5 croos up the zero line and CCI in H4 is above 0, so I can have 2,3 o more buy orders, with the code I've written each time CCI in M5 cross up zero line the EA open several positions not one. So how can I do for open one position per signal??

I think the solution must be in ordersend loop:

void BuscarAbrir()
{
if (var_752)
   {
   if (Kumo == 1) Print("SELL signal");
   int ticket = 0;
   Arko = 0;
   while ((ticket <= 0) && (Arko < Number))
      {
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      ticket = OrderSend(Symbol(),OP_SELL,Lotes,Bid,Slippage,0,0,Version,MagicNumber,0,Red);
      if (ticket < 0)
         {
         Print("Error opening SELL order! ",ErrorDescription(GetLastError()));
         Arko++;
         }
      }
   }
      else
   {
   if (var_748)
      {
      if (Kumo == 1) Print("BUY signal");
      ticket = 0;
      Arko = 0;
      while ((ticket <= 0) && (Arko < Number))
         {
         while (!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         ticket = OrderSend(Symbol(),OP_BUY,Lotes,Ask,Slippage,0,0,Version,MagicNumber,0,Blue);
         if (ticket < 0)
            {
            Print("Error opening BUY order! ",ErrorDescription(GetLastError()));
            Arko++;
            }
         }
      }
   }
}
 

one partial solution: modify your code like below:

datetime lasttime=NULL;
int start()
{
if (Time[0] == lasttime ) return(0); 
lasttime = Time[0] ;

.......................
socond solution: record your last signal, if new signal simlar last, no tsend order.