Serious problem with OrdersTotal()

 

Solved, thanks!

 

DD

A couple of points

If orders may be closing during the count it is always better to count backwards

  int i, iTotalOrders;
  
 
   iTotalOrders=OrdersTotal()-1;
  
   for (i=iTotalOrders; i>=0; i--) 
    {
      //........................
    }

Also, when backtesting you cannot successfully place or 'see' orders on pairs other than the selected test pair

FWIW

-BB-

 

So basically, hedge.

Let's assume we have the following orders:

#1 - BUY
#2 - SELL

For some reason, calling OrdersTotal() at this point always = 1.

Your assumption or the code is wrong. Print out the ticket number of both orders when opened. Verify them in the journal. US brokers don't allow hedging. Post your code.
 

Dj_Diablo:

[...] Can anyone explain why? Thanks!

There are basically four possible explanations which spring to mind:

  1. There is a simple bug in your code which both you and I are overlooking. However, I can't see one. Your code simply seems to be writing OrdersTotal() direct to screen. (And this also rules out any issue with different magic numbers, because that would affect only the display of the orderstr variable, not OrdersTotal.)
  2. You have discovered a fundamental bug in MT4. This is extremely unlikely.
  3. The code snippet you have posted is fine, but the code is not getting called when you think it's getting called. The hypothesis would be that, in your example, the section of code you have posted has not been called since the second order was placed, and therefore the labels have not been updated.
  4. MT4 doesn't always update labels on screen immediately during visual-mode backtesting.

My money is on 4. Try doing a WindowRedraw() after setting the labels.

The only bit which really puzzles me is that you say "If I have multiple orders of the *same* symbol, it works flawlessly". I think you mean "same direction", not "same symbol".

 

Problem solved!

I had a feeling it was a bug on my part, and of course it took a lot of testing to discover it, but alas, that was the problem.

The code is huge and I didn't realize that the whole display code was only being executed on certain situations, thus it never hit this section of the code when I thought it did.

With that said, I wish there was an easier way to deal with huge MQ4 files. A function list would be a great start, so I can quickly jump to/from functions.

Are there any other editors that people use besides the MetaEditor?

 
Dj_Diablo:

[...] Are there any other editors that people use besides the MetaEditor?

My favorite -> https://www.mql5.com/en/forum/123554.
 
I use notepad2 with code folding
 
gordon:
My favorite -> https://www.mql5.com/en/forum/123554.
I use VIM :)
Reason: