My current function to check current position (0 = flat, 1 = long, -1 = short) is as follows:
int getCurrentPosition()
{
if (order_Ticket < 0)
{
return (0); //no position at the moment
}
else
{
if (OrderSelect(order_Ticket,SELECT_BY_TICKET,MODE_TRADES))
{
switch(OrderType())
{
//return opened long positions
case OP_BUY : return (1);
break;
//return opened short positions
case OP_SELL : return (-1);
break;
}
}
else if (OrderSelect(order_Ticket,SELECT_BY_TICKET,MODE_HISTORY))
{
return (0);
}
}
}
It doesn't work though. Anyone got a simpler, easier function?
int getCurrentPosition()
{
if (order_Ticket < 0)
{
return (0); //no position at the moment
}
else
{
if (OrderSelect(order_Ticket,SELECT_BY_TICKET,MODE_TRADES))
{
switch(OrderType())
{
//return opened long positions
case OP_BUY : return (1);
break;
//return opened short positions
case OP_SELL : return (-1);
break;
}
}
else if (OrderSelect(order_Ticket,SELECT_BY_TICKET,MODE_HISTORY))
{
return (0);
}
}
}
It doesn't work though. Anyone got a simpler, easier function?