Hi,
You need to use OrdersHistoryTotal() in a separate loop to count the closed orders.
OK, thanks for pointing to it. i changed to this:
// retrieving info from trade history int hstTotal = OrdersHistoryTotal(); for (int i = 0 ; i < hstTotal ; i++) { //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Access to history failed with error (",GetLastError(),")"); break; } OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol()&& OrderMagicNumber()==MagicNumber) closed++; ObjectSetText("history","Closed orders: " + closed, 13, "Arial Bold", Silver); }
but then it just keeps on counting by every tick :) so i suppose i should change the close++ command to something else, but to what?
i also tried with the following code, but also keeps counting:
for(int i=(OrdersHistoryTotal()-1);i>=0;i--) { OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY || OP_SELL) closed++; ObjectSetText("history","Closed orders: " + closed, 13, "Arial Bold", Silver); } }
static int closedOrders=0; if(OrderHistoryTotal()!=closedOrders){ closedOrders=OrdersHistoryTotal(); //do your counting... }//z
//z
thanks! i didnt understand correctly at first, but this one seems to work. appreciate it!
My full EA code is posted below. somehow it opened a buy order yesterday, but it got closed by stoploss today. right now, on eurusd the bar from yesterday (tuesday) opened above ema50 and closed below ema50, so it should take a short now, but it does not. could anyone see what part of my code i'm doing wrong?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
currently im stuck at my EA code. Almost everything works fine, but i also want it to display how many trades are already closed.
Right now is use the following piece of code. But the "Closed orders: " always shows 0, while i have enough closed trades with the same MagicNumber. What am i doing wrong?