I
programming MQL4 since some years so I can make indicators and EA without problems…
Now
I’m studying MQL5 but I have some problems.
For
example it’s so simple in MQL4 to count orders by type (open e pending)..
In
MQL5, if I understood, I have to choose if I would to count pending or open orders… I can’t make a function that do all things like in MQL4…
In
MQL4 I simply do something like this:
int TradesCount(int type)
{
int result = 0;
int total = OrdersTotal();
for(int i = 0; i < total; i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) continue;
if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue;
result++;
}
return(result);
}
In MQL5 I can’t… I
should create 2 functions, one to count pending orders and one to count open orders… It’s a ugly scenario for me…
int TradesOpenCount(int type)
{
int result = 0;
int total = PositionsTotal();
for(int i = total - 1; i >=0; i--)
{
if(PositionGetSymbol(i)!=Symbol()) continue;
if(PositionGetInteger(POSITION_MAGIC) != MagicNumber || PositionGetInteger(POSITION_TYPE) != type) continue;
result++;
}
return(result);
}
int TradesPendingCount(int type)
{
int result = 0;
int total = OrdersTotal();
for(int i = total - 1; i >=0; i--)
{
OrderGetTicket(i);
if(type == ORDER_TYPE_SELL_STOP || ORDER_TYPE_BUY_STOP) if(OrderGetString(ORDER_SYMBOL)!=Symbol()) continue;
if(OrderGetInteger(ORDER_MAGIC) != MagicNumber || OrderGetInteger(ORDER_TYPE) != type) continue;
result++;
}
return(result);
}
Same thing for open an order (at market or pending): in MQL4 I created a function that open a trade (at market or pending) passing some data (type,
price, sl, etc...)... In MQL5 I can't do something similar...
Where I'm wrong? There is a way to count orders by type or open an order link in MQL4 (without using MQL4 library).
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello everyone,
I programming MQL4 since some years so I can make indicators and EA without problems…
Now I’m studying MQL5 but I have some problems.
For example it’s so simple in MQL4 to count orders by type (open e pending)..
In MQL5, if I understood, I have to choose if I would to count pending or open orders… I can’t make a function that do all things like in MQL4…
In MQL4 I simply do something like this:
In MQL5 I can’t… I should create 2 functions, one to count pending orders and one to count open orders… It’s a ugly scenario for me…
Same thing for open an order (at market or pending): in MQL4 I created a function that open a trade (at market or pending) passing some data (type, price, sl, etc...)... In MQL5 I can't do something similar...
Where I'm wrong? There is a way to count orders by type or open an order link in MQL4 (without using MQL4 library).
Thanks