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 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);
}
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.
- www.mql5.com
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
See this topic : https://www.mql5.com/en/forum/170566
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 Magic2 = 57;
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;
}
I'm not quite sure what the problem is then? Perhaps I have misunderstood.
input int Magic2 = 57;
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!
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.