Try this sample
//+------------------------------------------------------------------+ //| Test_OnTrade.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| обработка события Trade | //+------------------------------------------------------------------+ void OnTrade() { static int posTotals=-1; static int ordTotals=-1; static int histOrders=-1; static int histDeals=-1; datetime trade_time=TimeCurrent(); //--- datetime from_date=0;//TimeCurrent()-PeriodSeconds(PERIOD_MN1); datetime to_date=TimeTradeServer(); HistorySelect(from_date,to_date); Print("Requested history from "+ TimeToString(from_date)+" to "+ TimeToString(to_date)); //--- first time calling if(posTotals==-1) { posTotals=PositionsTotal(); ordTotals=OrdersTotal(); histOrders=HistoryOrdersTotal(); histDeals=HistoryDealsTotal(); Print(__FUNCTION__,":List of orders, deals and positions wereinitialized"); } else { int currOrders=OrdersTotal(); int currPositions=PositionsTotal(); int currHistDeals=HistoryDealsTotal(); int currHistOrders=HistoryOrdersTotal(); //--- check orders if(currOrders!=ordTotals) { ordTotals=currOrders; Print("Pending orders list was changed"); } //--- check open positions if(currPositions!=posTotals) { posTotals=currPositions; Print("Open positions list was changed"); } //--- check ordersin history if(currHistOrders!=histOrders) { histOrders=currHistOrders; Print("History orders list was changed"); } //--- check history of deals if(currHistDeals!=histDeals) { Print("Deals history changed"); Print("before:histDeals =",histDeals," currHistDeals =",currHistDeals); histDeals=currHistDeals; //Print("after:histDeals =",histDeals," currHistDeals =",currHistDeals); } } } //+------------------------------------------------------------------+
Rosh:
Try this sample
Thanks Rosh, I now think I understand how Deals work
Try this sample
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
I've played around with the the various Deal-related functions in MQL5 (HistoryDealSelect, HistoryDealsTotal, HistoryDealGetTicket, HistoryDealGetDouble, HistoryDealGetInteger, HistoryDealGetString) and I'm wondering if they apply at all to Forex? I can't find any scenario where HistoryDealsTotal() > 0
Paul
http://paulsfxrandomwalk.blogspot.com/