Counting open orders from an ae

 
Counting open orders from an ae

Guys I created this function that should count orders opened by an ea 
int OrdiniAperti( int MagicNumberint)
{
int count=0;
for(int i = OrdersTotal()-1; i >= 0; i--)
{
int tcket = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberint)
{
count = count+1;
return count;
}
}
return 0; 

But I printed the result but it always gives me 0 you can tell me where the error is

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. OrderSelect does not return a ticket (tcket) number.

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  3. If you actually find what you are looking for, you increment count to one and return that. Put your return outside the loop, and return the count.
  4. texoro: always gives me 0 you can tell me where the error is
    Elsewhere.
 
How to start with MQL5
How to start with MQL5
  • 2020.03.12
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.