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.
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.
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.
- www.mql5.com
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.
the comment part is well covered above, so just one thing from the prop side.
Best regards
Chris
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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:
Peter.