Topic: MT4 Portfolio not detecting previous trades

Hello

I imported into MT4 a generated portfolio of strategies. I let it run for one day and everything worked. When market closed I closed the chart where the EA was running, but did not closed the trades.

Now the market is open again, the expert is running and the settings are the same. I have 3 trades open with the same magic number prefix of EA settings, but the EA is not detecting those positions... Hence it will not manage them.

How can I fix this? Thanks

Re: MT4 Portfolio not detecting previous trades

Anyone?

Re: MT4 Portfolio not detecting previous trades

The lead developer will have a better say on this. He'll be here.

But usually it doesn't happen, portfolio recognizes its past trades. The problem might be that you closed the chart, if my memory serves me correct it is better to have it on the exact same chart, but on the other hand if the magics are the same (did you double check?) it should work ok.

Have you tried removing the portfolio and re-attaching it few seconds later? Sort of a restart without changing the chart.

And the most trivial - are there any error messages?

Can you replicate the error? First put it on chart, let it open a couple of trades, remove the portfolio, then re-attach it.
And try the same but now by closing the chart and opening a new one and then re-attaching the EA.

Re: MT4 Portfolio not detecting previous trades

Hello

When it happened it was because I accidentely closed the chart. When I opened a new chart and loaded the expert, then past active trades were not picked up. Yes the magic number prefix was the same.
There were no errors by the expert reported.

Re: MT4 Portfolio not detecting previous trades

Right now I just restarted my machine and the EA does not recognize anymore all my open trades. Please how can I get this fixed by monday?

What should I do? There are no errors reported on Journal.

6 (edited by ironhak 2025-12-06 19:03:13)

Re: MT4 Portfolio not detecting previous trades

Just to be extra-clear:

https://i.imgur.com/1e3yB3r.png

Re: MT4 Portfolio not detecting previous trades

Read a bit trough the code and added: SetPosStats(); on the initialization:

int OnInit(void)
  {
   Comment("");
   DeleteObjects();

   barTime   = Time[0];
   stopLevel = MarketInfo(_Symbol, MODE_STOPLEVEL);
   pip       = GetPipValue();

   accountProtectionMessage = "";
   entryProtectionMessage   = "";

   ParseNewsCurrenciesText();
   lastNewsUpdate = TimeCurrent();
   if(!MQLInfoInteger(MQL_TESTER))
      LoadNews();
   
   SetPosStats();
   OnTick();
   ChartRedraw(0);

   return INIT_SUCCEEDED;
  }

Now my trades are recognized and I see them in the text written by the EA in the chart. Possible that I was not seeing any positions because the market is closed, hence OnTick does not get triggered and by consequence SetPosStats() also does not get called?

If that's the case, wouldn't it make sense to have SetPosStats inside OnInit?

Re: MT4 Portfolio not detecting previous trades

Obviously the market needs to be open to check things proper, so you and your fix is making sense. Mql is not my forte unfortunately, but I'll try to confirm few things.

Re: MT4 Portfolio not detecting previous trades

> If that's the case, wouldn't it make sense to have SetPosStats inside OnInit?

It makes sense.

I'll check it and will update the code.

Thank you!