EA differnt result in tester and prop firm account

 

Hi all

My EA is different in teser and prop firm account. Please help


On 7 Sep, 2026,   the no. of lot increase by 1 in tester , but not in prop firm account


Prop firm account



The function is as follows:


int LastLotCnt()

{

   int re;

   

   long l_timecurrent = TimeTradeServer();   

   

   double l_profit_sum = 0;

   double l_profit = 0;

  

         

// history from "100 days before to current time

   if(!HistorySelect(l_timecurrent - 8640000 ,l_timecurrent))  

   {

      Print("Fail to get last lot");

      return -1;

   }

   

   

   int total = HistoryDealsTotal();

   

   if (total == 0) // No history deal

   {

      return 1;

   }

   

   for (int j = total - 1 ; j >= 0 ; j--) 

   {

      ulong ticket =  HistoryDealGetTicket(j);

      

      if (ticket <= 0) 

      {   Print("Failed to get ticket"); 

          continue;

      }

      

        

      long magicno;

      if (!HistoryDealGetInteger(ticket,DEAL_MAGIC,magicno)) 

      {   Print("Failed to get magic number"); 

          continue;

      }

      



      if (magicno == InpMagicNumber)

      {   

      

            long l_dealentry;

            if (HistoryDealGetInteger(ticket,DEAL_ENTRY,l_dealentry)) 

            { 

               if (l_dealentry == DEAL_ENTRY_IN)

               {

               

                  string comment;

                  if(HistoryDealGetString(ticket, DEAL_COMMENT, comment))

                  {

                    if (StringSubstr(comment,0,11) == "No of Lot =")        

                    {        

                       re =  (int) StringSubstr(comment,11,StringLen(comment) - 1);  



                       if (l_profit_sum < 0)

                       {   re = re + 1 + (re/5);

                       }

                                  

                       return re;

                       

                    }

                        

                  }

                          

               }

               else if (l_dealentry == DEAL_ENTRY_OUT)

               {

                  if (HistoryDealGetDouble(ticket,DEAL_PROFIT,l_profit))

                  {

                      l_profit_sum += l_profit;

                  }

               }

            }

         

    }

  }

  return -1; 

}

Peter.

 
You should provide a code where the string "No of Lot" is assigned, not where it's read from the comment, in order to troubleshoot. Apart from the comment difference, the lots seem executed very similar in the tester and online.
 
If it only goes wrong on the live account, I would look at the comment before the counter. Your lot counter depends on the last entry deal's comment starting with "No of Lot =", and the tester hands that string back exactly as you sent it. A live server does not have to. In a client EA I had to move my own tag to the front of the comment because the broker only kept the first 31 characters. If the text arrives shortened or changed, StringSubstr(comment,0,11) no longer matches, the loop quietly skips that deal and the function returns whatever it returns when nothing is found, which would look like the lot not increasing. A quick check is to Print the raw DEAL_COMMENT of the last few entry deals on the prop account and compare it with what the tester journal shows. Longer term I would not keep state in a comment at all. The volume of the last entry is already in DEAL_VOLUME, and a counter can live in a global variable with the account login in its name, which also survives a terminal restart.
 

The tester-vs-live difference here is most likely the DEAL_COMMENT parsing. You're storing state in the deal comment ("No of Lot ="), which the tester preserves exactly - but many live and prop-firm servers rewrite or blank out deal comments (some append their own tags like [tp]/[sl]), so StringSubstr(comment,0,11) fails and LastLotCnt falls through to -1. More robust: read the volume of your last DEAL_ENTRY_IN deal with HistoryDealGetDouble(ticket, DEAL_VOLUME), or keep the counter in a GlobalVariable or a file. Also double-check the 100-day HistorySelect window actually covers history on the new account - a fresh prop account often has far less.

 
Timon-pascal Krueger #:
If it only goes wrong on the live account, I would look at the comment before the counter. Your lot counter depends on the last entry deal's comment starting with "No of Lot =", and the tester hands that string back exactly as you sent it. A live server does not have to. In a client EA I had to move my own tag to the front of the comment because the broker only kept the first 31 characters. If the text arrives shortened or changed, StringSubstr(comment,0,11) no longer matches, the loop quietly skips that deal and the function returns whatever it returns when nothing is found, which would look like the lot not increasing. A quick check is to Print the raw DEAL_COMMENT of the last few entry deals on the prop account and compare it with what the tester journal shows. Longer term I would not keep state in a comment at all. The volume of the last entry is already in DEAL_VOLUME, and a counter can live in a global variable with the account login in its name, which also survives a terminal restart.
Thanks, terminal restart may be the problem to access the previous comment. In live the EA sometime can access the previous comments successful but on 7 Sep it failed to access the comments on 4 Sep. The EA is running on my PC and the PC reboot on 5 Sep causing terminal restart.
 
Kam Yuk Wong #:
Thanks, terminal restart may be the problem to access the previous comment. In live the EA sometime can access the previous comments successful but on 7 Sep it failed to access the comments on 4 Sep. The EA is running on my PC and the PC reboot on 5 Sep causing terminal restart.
Do not use comments for making decisions in MT5 algorithms if you want to build a reliable/reproducable trading system.
 
First log TimeTradeServer(), HistoryDealsTotal() and the last deal comment on both accounts. Prop server time can be different, and deal comments may be changed or empty, so reading the lot count from the comment is risky. Better store the count yourself, or calculate it only from entry deals with your magic number.
 
I think the problem is the comment cannot be accessed after terminal restart. My EA is running on my PC and I sometimes reboot it which caused terminal restart.  Thanks again for all of you.