Skip to content

Instantly share code, notes, and snippets.

@mamirjamali
Created January 4, 2023 09:15
Show Gist options
  • Save mamirjamali/8e1b1594fec2b07270ae8004d5286408 to your computer and use it in GitHub Desktop.
Save mamirjamali/8e1b1594fec2b07270ae8004d5286408 to your computer and use it in GitHub Desktop.
Get the last oder profit of the History
double MylastOrderProfit()
{
// retrieving info from trade history
double LastOrderProfit = 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)
{
LastOrderProfit = OrderProfit();
Print(LastOrderProfit);
}
if (OrderType() == OP_SELL)
{
LastOrderProfit = OrderProfit();
Print(LastOrderProfit);
}
}
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false)
{
Print("Access to history failed with error (", GetLastError(), ")");
break;
}
// some work with order
}
return (LastOrderProfit);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment