dictionary mql or something similiar. Checking if pendings were opened.

 
Hello i need help with checking if pending orders were opened in my EA.

Currently I am doing it like - I save in static value number of opened trades.
Then Im checking opened trades and if this values is bigger than the value in static variable then it means pending order was opened. Thats fine and working well (not talking about cases when metatrader crash or something)

So what I want to achieve now is - My EA is openaning trades in sequences and each sequence has its own uniq MagicNumber (generated). It means there is pending order with MagicNumber = 55 and penging order with MagicNumber 57.
How could I store values about how many opened trades I currently have in each sequence? There is not anything like dictionary or mapped array in MQL.
It would be great if there would be dictionary. I would just ask for value of variable "mySuperArray[MagicNumber]" and it would give me number of trades.

Could please anyone help me or suggest different way? Thank you so much and have a nice day.
 
Foed:
Hello i need help with checking if pending orders were opened in my EA.

Currently I am doing it like - I save in static value number of opened trades.
Then Im checking opened trades and if this values is bigger than the value in static variable then it means pending order was opened. Thats fine and working well (not talking about cases when metatrader crash or something)

So what I want to achieve now is - My EA is openaning trades in sequences and each sequence has its own uniq MagicNumber (generated). It means there is pending order with MagicNumber = 55 and penging order with MagicNumber 57.
How could I store values about how many opened trades I currently have in each sequence? There is not anything like dictionary or mapped array in MQL.
It would be great if there would be dictionary. I would just ask for value of variable "mySuperArray[MagicNumber]" and it would give me number of trades.

Could please anyone help me or suggest different way? Thank you so much and have a nice day.

int OrderCount(int magic)
  {
   int cnt=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS)) continue;
      if(OrderSymbol()      != _Symbol) continue; // optional
      if(OrderMagicNumber() != magic)   continue;
      if(OrderType() < 2)               cnt++;    // only counts OP_BUY and OP_SELL
     }  
   return(cnt);  
  }
 
Foed I save in static value number of opened trades.  Then Im checking opened trades and if this values is bigger than the value in static variable then it means pending order was opened.
If mean an order was opened on some chart. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
 
Foed:
Hello i need help with checking if pending orders were opened in my EA.

Currently I am doing it like - I save in static value number of opened trades.
Then Im checking opened trades and if this values is bigger than the value in static variable then it means pending order was opened. Thats fine and working well (not talking about cases when metatrader crash or something)

So what I want to achieve now is - My EA is openaning trades in sequences and each sequence has its own uniq MagicNumber (generated). It means there is pending order with MagicNumber = 55 and penging order with MagicNumber 57.
How could I store values about how many opened trades I currently have in each sequence? There is not anything like dictionary or mapped array in MQL.
It would be great if there would be dictionary. I would just ask for value of variable "mySuperArray[MagicNumber]" and it would give me number of trades.

Could please anyone help me or suggest different way? Thank you so much and have a nice day.
See this topic : https://www.mql5.com/en/forum/170566
Help please, array mangement question. MQL4 vs .Net
Help please, array mangement question. MQL4 vs .Net
  • www.mql5.com
Hello, I am bringing some of my indicators over from NinjaTrader which are C# written and have a couple of questions regarding array management I a...
 
whroeder1:
If mean an order was opened on some chart. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
When counting opened trades Im using my own function what works similiar as honest_knave described.
 
Alain Verleyen:
See this topic : https://www.mql5.com/en/forum/170566
Thank you for dictionary. Will help a lot. Thanks
 
frantisek-fanda:
When counting opened trades Im using my own function what works similiar as honest_knave described.

I'm not quite sure what the problem is then? Perhaps I have misunderstood.

input int Magic1 = 55;
input int Magic2 = 57;
static int was_Magic1 = OrderCount(Magic1),
           was_Magic2 = OrderCount(Magic2);
int is_Magic1 = OrderCount(Magic1),
    is_Magic2 = OrderCount(Magic2);
  
if(is_Magic1 > was_Magic1)
  {
   printf("Order opened in %i sequence",Magic1);
   was_Magic1 = is_Magic1;
  }
if(is_Magic2 > was_Magic2)
  {
   printf("Order opened in %i sequence",Magic2);
   was_Magic2 = is_Magic2;
  }


 

 
honest_knave:

I'm not quite sure what the problem is then? Perhaps I have misunderstood.

input int Magic1 = 55;
input int Magic2 = 57;
static int was_Magic1 = OrderCount(Magic1),
           was_Magic2 = OrderCount(Magic2);
int is_Magic1 = OrderCount(Magic1),
    is_Magic2 = OrderCount(Magic2);
  
if(is_Magic1 > was_Magic1)
  {
   printf("Order opened in %i sequence",Magic1);
   was_Magic1 = is_Magic1;
  }
if(is_Magic2 > was_Magic2)
  {
   printf("Order opened in %i sequence",Magic2);
   was_Magic2 = is_Magic2;
  }



Actually I dont know... :) Magicnumber wil lbe dynamicly changing during time, so in using with dictionary posted above all should be fine.

Just one questions. That to do when MT4 will fall. All static values will be deleted and ...

Thank you!

 
When you quote someone, please make sure that your reply is outside the quote. I have moved it for you, but next time make sure that you write outside of the quote
 
frantisek-fanda:

Just one questions. That to do when MT4 will fall. All static values will be deleted and ...

Yes, static variables will not survive a restart.

If you need persistent storage because the data for recovery no longer exists, you need to look at global variables of the terminal, or reading/writing to file. 

 
thank you guys.
Reason: