Hello, I am trying to get current market position(nr. of lots and direction) like this :
int OpenPosQTY()
{
int cnt = 0; int lots = 0;
for (int ic = OrdersTotal() - 1; ic >= 0; ic--)
{
OrderSelect(ic, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY) cnt++;
if (OrderType() == OP_SELL) cnt--;
lots = OrderLots() ;
}
}
Print("OPEN POSITION :", DoubleToStr(cnt *lots,6) );
return (cnt*lots);
}
Problem is that the variable is updated very late - seconds after a trade happens... I guess that is due to the fact that it recalculates with every new tick.... I need it to be instantly as I want to forward this change to an externall app. which will trade on other API.
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, I am trying to get current market position(nr. of lots and direction) like this :
int OpenPosQTY()
{
int cnt = 0; int lots = 0;
for (int ic = OrdersTotal() - 1; ic >= 0; ic--)
{
OrderSelect(ic, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY) cnt++;
if (OrderType() == OP_SELL) cnt--;
lots = OrderLots() ;
}
}
Print("OPEN POSITION :", DoubleToStr(cnt *lots,6) );
return (cnt*lots);
}
Problem is that the variable is updated very late - seconds after a trade happens... I guess that is due to the fact that it recalculates with every new tick.... I need it to be instantly as I want to forward this change to an externall app. which will trade on other API.
Any idea how could this be done?