SendMail advise needed

 
I use SendMail() for when orders open and when close by EA code. This is a Buy open example. I need advise as to using SendMail() when orders are closed by TakeProfit or Stoploss from the Broker's server. Do I need to use OrderSelect with MODE_HISTORY? Could have a code example.

Thanks in advance
Wackena

if(Buy1==1) 
         {
         BarTime=DayOfWeek();
         ret=1;
         TradeDay=TimeDayOfYear(TimeCurrent());
         if(StopLoss > 0) sl=Ask-StopLoss*Point;
         if(TakeProfit > 0) tp=Ask+TakeProfit*Point;
         ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,sl,tp,"BUYSignal",MagicNumber,0,Blue);
         if(UseEmail) SendMail("Signal Alert - Bogie-Daily-v4.0-FullVersion","[" + Symbol() + "]  " + DoubleToStr(Ask,Digits) + "  Open Buy"
         +"  GapExit = "+DoubleToStr(GapExit,Digits)+ " Server Time: " + TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) + " Local Time: " + TimeToStr(TimeLocal(),TIME_DATE|TIME_MINUTES));
         if(ticket>0)
            {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            }
            else Print("Error opening BUY order : ",GetLastError()); 
            return(0);
         }
 
See example of endless looped cycle here - https://www.mql5.com/ru/forum/51821
Reason: