Last active
January 4, 2023 09:32
-
-
Save mamirjamali/dafc9d03a91f2f53934d2b072705b53a to your computer and use it in GitHub Desktop.
MQL - Get the last order type in the history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string MyLastOrderType() | |
{ | |
// retrieving info from trade history | |
string LastOrderType = "None"; | |
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) | |
{ | |
LastOrderType = "Buy"; | |
Print(LastOrderType); | |
} | |
if (OrderType() == OP_SELL) | |
{ | |
LastOrderType = "Sell"; | |
Print(LastOrderType); | |
} | |
} | |
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) | |
{ | |
Print("Access to history failed with error (", GetLastError(), ")"); | |
break; | |
} | |
// some work with order | |
} | |
return (LastOrderType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment