- Now as the EA runs, for each OUTER loop there is its associated INNER loop. This then creates an entry that is duplicated upon every loop iteration.
HELP REQD:
- What I would like to do is to somehow create an array that holds ONLY single entries and NO duplicate ones.
- I have started my attempt (shown below) by trying to filter out duplicate entries but I keep getting the above output.
- To simply assist (or point me in the right direction) how I might be able to remove the duplicate entries (based on the position ID) and maybe create a new array that could hold only the single positions?!?!? (maybe)
- NOTE: I intend to run the function in my main EA after every new bar creation.
Any help or assistance would be greatly appreciated - Many thanks in advance
void _OutputTradesToCSVFile()
{
//--- set the start and end date to request the history of dealsdatetime startDate = (TimeCurrent() - (PeriodSeconds(PERIOD_W1) * 2)); // from 2 weeks agodatetime endDate = TimeCurrent(); // till the current momentulong dealOutTicket = -1;
ulong dealInTicket = -1;
// create TWO arrays to hold trades & unique trades
struct_TradeDetails tradesArray[];
// RETRIEVE: ALL orders & deals for the previous TWO weeks if(HistorySelect(startDate, endDate))
{ // RETRIEVE: ONLY deals for the previous TWO weeksint totalDealsLoop = HistoryDealsTotal();
// LOOP: if "dealOutTicket = HistoryDealGetTicket(i)" AND the deal is an 'OUT' tradefor( int i = totalDealsLoop; i >= 0; i-- )
{
if((dealOutTicket = HistoryDealGetTicket(i)) > 0 &&
HistoryDealGetInteger(dealOutTicket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
{ // RETRIEVE: GET DEAL 'OUT' DATAulong positionID = HistoryDealGetInteger(dealOutTicket, DEAL_POSITION_ID);
ulong closeDealID = HistoryDealGetInteger(dealOutTicket, DEAL_TICKET);
string symbolID = HistoryDealGetString(dealOutTicket, DEAL_SYMBOL);
// RETRIEVE: ONLY deals with the previous CLOSING position ID & is an 'IN' tradefor( int j = totalDealsLoop; j >= 0; j-- )
{
if( (dealInTicket = HistoryDealGetTicket(j) ) > 0 &&
HistoryDealGetInteger(dealInTicket, DEAL_ENTRY) == DEAL_ENTRY_IN &&
HistoryDealGetInteger(dealInTicket, DEAL_POSITION_ID) == positionID)
{ // RETRIEVE: GET DEAL 'IN' DATAulong openOrderID = HistoryDealGetInteger(dealInTicket, DEAL_ORDER);
ulong openDealID = HistoryDealGetInteger(dealInTicket, DEAL_TICKET);
datetime openDealTime = (datetime)HistoryDealGetInteger(dealInTicket, DEAL_TIME);
// Create a new trade object
struct_TradeDetails obj_trade;
obj_trade.openDealTime = openDealTime;
obj_trade.symbolID = symbolID;
obj_trade.openOrderID = openOrderID;
obj_trade.openDealID = openDealID;
obj_trade.closeDealID = closeDealID;
obj_trade.positionID = positionID;
// Resize tradesArray[]ArrayResize( tradesArray, ArraySize(tradesArray) + 1 );
// Add the trade values to the obj_trade object
tradesArray[ArraySize(tradesArray) - 1] = obj_trade;
ArrayPrint(tradesArray);
}
}
}
}
bool isDuplicate = false;
// for( int k = 0; k < ArraySize(tradesArray); k++ )
{
for ( int l = 0; l < ArraySize(tradesArray); l++ )
{
if( tradesArray[k].positionID == tradesArray[l].positionID )
{
isDuplicate = true;
break;
}
}
if( !isDuplicate )
{
// Add the unique trade to uniqueTradesArrayArrayResize(tradesArray, ArraySize(tradesArray) + 1);
tradesArray[ArraySize(tradesArray) - 1] = tradesArray[k];
}
}
}
}
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.
Any help or assistance would be greatly appreciated - Many thanks in advance