MnQInvestmentDevelopment/MnQInvestment/04_Tutorials/LEARNINGGetTradeHistory.mq5

97 lines
3 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 15:08:44 +02:00
//+------------------------------------------------------------------+
//| LEARNINGGetTradeHistory.mq5 |
//| Copyright 2023, M & Q Investment Group |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, M & Q Investment Group"
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
//--- GET LAST PROFIT FUNCTION ---
string Getlastprofit()
{
//get history
HistorySelect(0,TimeCurrent());
uint TotalNumberofdeals=HistoryDealsTotal();
ulong Ticketnumber=0;
long OrderType = 0;
double OrderProfit = 0;
string MySymbol = "";
string PositionDirection = "";
string MyResult = "";
long Dealentry = 0;
//go through deals
for(uint i=0; i < TotalNumberofdeals ; i++)
{
//looking for ticket number
if((Ticketnumber=HistoryDealGetTicket(i))>0)
{
//get profit
OrderProfit = HistoryDealGetDouble(Ticketnumber, DEAL_PROFIT);
OrderType = HistoryDealGetInteger(Ticketnumber, DEAL_TYPE);
MySymbol = ;
//get deal entry type to check for close types
Dealentry = HistoryDealGetInteger(Ticketnumber, DEAL_ENTRY);
//if currency pair fits
if (MySymbol == _Symbol)
if (OrderType == DEAL_TYPE_BUY || OrderType == DEAL_TYPE_SELL)
if (Dealentry == 1)
{
//set sell order type if close type was buy
if (OrderType == DEAL_TYPE_BUY)
PositionDirection = "Sell-Trade";
//set buy order type if close type was sell
if (OrderType == DEAL_TYPE_SELL)
PositionDirection = "Buy-Trade";
MyResult = "Profit: "+OrderProfit+" Ticket: "+Ticketnumber+" Position Direction: "+PositionDirection;
}//if end
}//for end
}
//return the result
return MyResult;
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+