HistoryDealGetDouble returns 100000.00 every once in a while for no reason in the context of DEAL_PROFIT

 
Here's the code that works most of the time and prints the profit.
   if(OrdPosition)
     {
      if(!PositionSelectByTicket(Ordnum))
        {
         if(logging)
            Print(omagic,cb,ccy.cursym," position closed by user, SL or TP:",Ordnum,cb,EnumToString(OrdDtype),cb);
         if(!istester || logslipTester)
           {
            string reason = "SLTP exit";
            LogSlippage((string) reason,DEAL_ENTRY_OUT);
           }
         OrdPosition=false;
         ccy.number_of_trades++;
         if(!logslipTester && !isoptimizer)
           {
            long position_id=HistoryOrderGetInteger(Ordnum,ORDER_POSITION_ID);
            if(HistorySelectByPosition(position_id))
              {
               ulong thisdealtic=HistoryDealGetTicket(HistoryDealsTotal()-1);
               double prft;
               if(HistoryDealGetDouble(thisdealtic,DEAL_PROFIT,prft))
                 {
                  if(logging)
                     Print(omagic,cb,ccy.cursym," checked profit:",prft);

In the logs, every once in a while I get this:

2021.05.21 02:11:25.098 Core 1 2021.04.23 06:15:50   555556,ETHUSD checked profit:100000.0

I can match the Ordnum to a stop loss hit for small loss in the report:






100000.0 is the most baffling....

 

OK I see why 100000.0.

position_id=HistoryOrderGetInteger(Ordnum,ORDER_POSITION_ID)

Occasionally returns 0 which causes me to wind up with the deposit as the profit. Not sure why yet though, ordnum is a legit order number that got executed and then exited by SL. 

 
Benjamin Dixon:

OK I see why 100000.0.

Occasionally returns 0 which causes me to wind up with the deposit as the profit. Not sure why yet though, ordnum is a legit order number that got executed and then exited by SL. 

Happy ending. Ordnum is not a legit order that executed there must be a bug elsewhere. I'll find it.