Check the documentations for these: HistoryOrdersTotal, HistoryOrderGetDouble, HistoryOrderGetInteger
Yashar Seyyedin #:
Check the documentations for these: HistoryOrdersTotal, HistoryOrderGetDouble, HistoryOrderGetInteger
Hello, first of all thank you for your response. I have tried the following way but it does not detect any pending order.
int TradeCount(ENUM_TIMEFRAMES TimeFrame) { int Cnt; ulong Ticket; long EntryType; datetime DT[1]; Cnt = 0; if(CopyTime(_Symbol, TimeFrame, 0, 1, DT) <= 0) { Cnt = -1; } else { HistorySelect(DT[0], TimeCurrent()); for(int i = HistoryOrdersTotal() - 1; i >= 0; i--) { Ticket = HistoryOrderGetTicket(i); EntryType = HistoryOrderGetInteger(Ticket, ORDER_TYPE); int PositionMagicNumber = (int)PositionGetInteger(POSITION_MAGIC); if(EntryType==ORDER_TYPE_BUY || EntryType == ORDER_TYPE_SELL || EntryType == ORDER_TYPE_BUY_STOP || EntryType == ORDER_TYPE_BUY_LIMIT || EntryType == ORDER_TYPE_SELL_STOP || EntryType == ORDER_TYPE_SELL_LIMIT) { if(PositionMagicNumber == Magic) { Cnt++; } } } } return(Cnt); }
Hi
You shouldn’t use PositionGetInteger – when selecting orders you can simply use something like that:
int TradeCount(ENUM_TIMEFRAMES TimeFrame) { int Cnt; ulong Ticket; long EntryType; datetime DT[1]; Cnt = 0; if(CopyTime(_Symbol, TimeFrame, 0, 1, DT) <= 0) { Cnt = -1; } else { HistorySelect(DT[0], TimeCurrent()); for(int i = HistoryOrdersTotal() - 1; i >= 0; i--) { Ticket = HistoryOrderGetTicket(i); EntryType = HistoryOrderGetInteger(Ticket, ORDER_TYPE); int OrderMagicNumber = (int)HistoryOrderGetInteger(Ticket,ORDER_MAGIC); if(OrderMagicNumber == Magic) { Cnt++; } } } return(Cnt); }
Best Regards
Thank you all for your contributions.

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
Hello I have the following code that calculates the open orders in a given Timeframe, but I don't know how to count also the pending orders.