I am new to MQL5 programming. I have converted a code that retrieves data from the last closed trade from MQL4 to MQL5. Even though the code is written correctly and there are no programming errors, it does not work at all, neither in live nor in the tester. I kindly request experienced members here to review the code and inform me of any errors or corrections that need to be made and added.
The Code >>
//=========== "Get Last Closed Trade Information For Only One Order" code =========== double LastClosedPosition(string info, int type = -1)
{
double result = 0;
int total = HistoryDealsTotal();
for (int i = total - 1; i >= 0; i--)
{
ulong ticket=HistoryDealGetTicket(i);
bool select = HistoryDealSelect(ticket);
string symbol=HistoryDealGetString(ticket, DEAL_SYMBOL);
long magicNumber=HistoryDealGetInteger(ticket, DEAL_MAGIC);
bool entryType=HistoryDealGetInteger(ticket, DEAL_ENTRY);
double lots=HistoryDealGetDouble(ticket, DEAL_VOLUME);
double entryPrice=HistoryDealGetDouble(ticket, DEAL_PRICE);
double profit=HistoryDealGetDouble(ticket, DEAL_PROFIT);
double takeProfit=HistoryDealGetDouble(ticket, DEAL_TP);
double stopLoss=HistoryDealGetDouble(ticket, DEAL_SL);
if (symbol == Symbol() && magicNumber == MagicNumber)
{
if (type == entryType || type == -1)
{
if (info == "Lots")
result = lots;
elseif (info == "EntryPrice")
result = entryPrice;
elseif (info == "Profit")
result = profit;
elseif (info == "Type")
result = entryType;
elseif (info == "TP")
result = takeProfit;
elseif (info == "SL")
result = stopLoss;
}
}
}
return (result);
}
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 everyone,
I am new to MQL5 programming. I have converted a code that retrieves data from the last closed trade from MQL4 to MQL5. Even though the code is written correctly and there are no programming errors, it does not work at all, neither in live nor in the tester. I kindly request experienced members here to review the code and inform me of any errors or corrections that need to be made and added.
The Code >>