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.

The reason it only broke on the live account is the restart: the tester keeps your exact comments in memory, but after a real restart you are re-reading history the broker has already rewritten, so StringSubstr finds nothing and the count resets.

I'd stop deriving the count from history at all and persist it directly. Keep the running lot counter per magic number in a global variable (GlobalVariableSet), and mirror it to a small file in OnDeinit so it survives a terminal restart or crash. On startup, read the file back, then reconcile against the real closed deals using DEAL_VOLUME and the deal's profit, never the comment. That way the decision never depends on a string the broker is free to change, and the tester and live account finally agree.

hi @Kam Yuk Wong


There are a couple of things in
LastLotCnt() that can make the result differ between the tester and a prop account.
The first thing I would check is that you are filtering the history not only by DEAL_MAGIC , but also by symbol and position ID. Otherwise, another deal with the same magic can affect l_profit_sum .

Also, you only handle DEAL_ENTRY_IN and DEAL_ENTRY_OUT . MT5 can also return DEAL_ENTRY_INOUT for a position reversal, so that case should be considered too. MQL5



One more important point:
HistorySelect() uses trade-server time, so make sure the history range is actually covering the same trades on both accounts. MQL5

I’d log the following for both runs:
DEAL_TICKET, DEAL_TIME_MSC, DEAL_SYMBOL, DEAL_POSITION_ID, DEAL_ENTRY, DEAL_MAGIC, DEAL_VOLUME, DEAL_PROFIT

Then compare the last few deals around 7 Sep. That will usually show exactly where the tester and prop account start producing different inputs.

I would investigate the history data first rather than changing the lot formula itself.

Documentation on MQL5: List of MQL5 Constants
Documentation on MQL5: List of MQL5 Constants
  • www.mql5.com
All MQL5 constants in alphabetical order...
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.
Hi Kam,

 the comment part is well covered above, so just one thing from the prop side.

Your counter raises the lot after a losing run (re + 1 + re/5). On a prop account I'd test that part harder than the
restart. I lost a challenge in phase 2 to one bad day that broke the daily loss limit, with the balance already close
to the target. With lots growing after losses, that one day can come a lot sooner.

Maybe run the tester with the prop's daily loss limit as a hard rule and see how often it would have been hit.

Best regards
Chris