Example:
//+------------------------------------------------------------------+ //| Total transactions today by Magic number.mq5 | //| Copyright © 2021, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2021, Vladimir Karputov" #property version "1.000" //+------------------------------------------------------------------+ //| Structure History Deals | //+------------------------------------------------------------------+ struct STRUCT_HISTORY_DEALS { long magic; // Magic number int count_buy; // Number of Buy deals int count_sell; // Number of Sell deals //--- Constructor STRUCT_HISTORY_DEALS() { magic = 0; count_buy = 0; count_sell = 0; } }; STRUCT_HISTORY_DEALS SHistoryDeals[]; //--- input parameters input int Input1=9; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- RequestTradeHistory(SHistoryDeals); int size=ArraySize(SHistoryDeals); for(int i=0; i<size; i++) { Print(IntegerToString(SHistoryDeals[i].magic), ", BUY: ",IntegerToString(SHistoryDeals[i].count_buy), ", SELL: ",IntegerToString(SHistoryDeals[i].count_sell)); } } //+------------------------------------------------------------------+ //| Request trade history | //+------------------------------------------------------------------+ void RequestTradeHistory(STRUCT_HISTORY_DEALS &history_deals[]) { //--- request trade history datetime from_date=iTime(Symbol(),PERIOD_D1,0); datetime to_date=TimeCurrent()+86400; HistorySelect(from_date,to_date); uint total_deals=HistoryDealsTotal(); ulong ticket_history_deal=0; if(total_deals>0) { ArrayFree(history_deals); //--- for all deals for(uint i=0; i<total_deals; i++) { //--- try to get deals ticket_history_deal if((ticket_history_deal=HistoryDealGetTicket(i))>0) { long deal_ticket = HistoryDealGetInteger(ticket_history_deal,DEAL_TICKET); long deal_type = HistoryDealGetInteger(ticket_history_deal,DEAL_TYPE); if(deal_type==DEAL_TYPE_BUY || deal_type==DEAL_TYPE_SELL) { long deal_entry = HistoryDealGetInteger(ticket_history_deal,DEAL_ENTRY); if(deal_entry==DEAL_ENTRY_IN) { long deal_magic = HistoryDealGetInteger(ticket_history_deal,DEAL_MAGIC); //--- int size=ArraySize(history_deals); bool find=false; for(int j=0; j<size; j++) { if(history_deals[j].magic==deal_magic) { if(deal_type==DEAL_TYPE_BUY) history_deals[j].count_buy=history_deals[j].count_buy+1; if(deal_type==DEAL_TYPE_SELL) history_deals[j].count_sell=history_deals[j].count_sell+1; continue; } } if(!find) { ArrayResize(history_deals,size+1); history_deals[size].magic=deal_magic; if(deal_type==DEAL_TYPE_BUY) history_deals[size].count_buy=1; if(deal_type==DEAL_TYPE_SELL) history_deals[size].count_sell=1; } } } } } } } //+------------------------------------------------------------------+
Secret: you need to use custom structure 'STRUCT_HISTORY_DEALS'. The structure for each 'Magic number' contains the number of BUY and SELL deals
Files:

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
TotalEA 02 = 05
Function code, below: