Ea I do not cancel the open order

 
Good morning, everyone. I am using an ea that I have created, which normally works fine, but this morning as I normally do I went in to check if any trades had been executed and found an open order that should have been cancelled. Normally it does cancel them, but something happened and it didn't, and it's probably a bug in my code. 

This is the part of the code that detects if the sl has been exceeded and cancels the open order:

 
 if(tradea() && !notOpenOrders())
            {
             ulong ticket = OrderGetTicket(getTicket());
             //Sleep(sleepLong);
             CopyLow(_Symbol,0,0,1,Low);
             CopyHigh(_Symbol,0,0,1,High);
             CopyTime(_Symbol,0,0,2,TimeS);
             if(waitingOrderType=="buy" && tradea())
               {
                if(Low[0]<actualSL || High[0]>=actualTP)
                  {
                   trade.OrderDelete(ticket);
                   candleChecked = true;
                  } 
               }
             else if(waitingOrderType =="sell" && tradea())
               {
                if(High[0]>actualSL || Low[0]<=actualTP)
                  {
                   trade.OrderDelete(ticket);
                   candleChecked = true;
                  } 
               }
               //Sleep(sleepLong);
            }
           }
 
 
I was thinking that it might have something to do with the ea rebooting when it loses network connection, but I'm not sure if that's how it really works.
Because actualSL and actualTP are variables that I assigned them the value calculated when I send the order, I don't have a function that gets that data from the order or the position. Maybe that could be it? Here's what I'm referring to:

     

        if(condBull)
              {
               waitingOrderType = "buy";
               actualSL    = Low[1];
               actualEntry = High[1];
               actualTP    = NormalizeDouble(actualEntry+(actualEntry-actualSL)*ratio,_Digits);
               if(dblLotsRisk(actualEntry,actualSL)<volumeVerificator && dblLotsRisk(actualEntry,actualSL)!=0.0)
                 {
                  orderSLBuy(actualEntry,actualSL,actualTP);
                  candleChecked = true;
                 }
               contadorPip = sumaPip;
               Sleep(sleepShort);
              }
            else if(condBear)
              {
               waitingOrderType = "sell";
               actualSL    = High[1];
               actualEntry = Low[1];
               actualTP    = NormalizeDouble(actualEntry-(actualSL-actualEntry)*ratio,_Digits);
               if(dblLotsRisk(actualEntry,actualSL)<volumeVerificator && dblLotsRisk(actualEntry,actualSL)!=0.0)
                 {
                  orderSLSell(actualEntry,actualSL,actualTP);
                  candleChecked = true;
                 }
               contadorPip = sumaPip;
               Sleep(sleepShort);
              }

    

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.