Skip to content

Instantly share code, notes, and snippets.

@mamirjamali
Last active January 4, 2023 09:31
Show Gist options
  • Save mamirjamali/23ff11ca8ed5b248281a982e98ee8b9b to your computer and use it in GitHub Desktop.
Save mamirjamali/23ff11ca8ed5b248281a982e98ee8b9b to your computer and use it in GitHub Desktop.
MQL - Get the last order open price of the history and print it
double MylastOrderOpenPrice()
{
// retrieving info from trade history
double LastOrderOpenPrice = 0;
int i, hstTotal = OrdersHistoryTotal();
for (i = 0; i < hstTotal; i++)
{
//---- check selection result
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if (i == OrdersHistoryTotal() - 1)
{
if (OrderType() == OP_BUY)
{
LastOrderOpenPrice = OrderOpenPrice();
Print(LastOrderOpenPrice);
}
if (OrderType() == OP_SELL)
{
LastOrderOpenPrice = OrderOpenPrice();
Print(LastOrderOpenPrice);
}
}
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false)
{
Print("Access to history failed with error (", GetLastError(), ")");
break;
}
}
return (LastOrderOpenPrice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment