Count closed orders ?

 
Hello, I am coding a small grid system and I have a problem now and can't solve that. For my system I need a function that closes all trades, if one order closed, for example at the stoploss or at the takeprofit. Can somebody help me please ? I thought that I need something that counts my closed orders ?
 
Show us your code then. Please use SRC when posting the code.
 
deysmacro:
Show us your code then. Please use SRC when posting the code.

Actually I havent a code for that function or do you mean the whole code ? My only problem is that I need a solution to let the Ea do something if the ea close an order. Why do I need that ? I saw that if i would work with the stoploss and the takeprofit, the Ea will sometimes take the stoploss but not the takeprofit and I will solve that problem and let it close ALL trade( includes pending order) if one OR more orders are closed by the ea

Thank you for your quick answer

 

count the open orders save it somewhere if there is a change close them all

previousOpenOrders = x;
currentOpenOrders =y;
if (currentOpenOrdess < PreviousOpenOrders)
Close Them All
 
Faat94:

Actually I havent a code for that function or do you mean the whole code ? My only problem is that I need a solution to let the Ea do something if the ea close an order. Why do I need that ? I saw that if i would work with the stoploss and the takeprofit, the Ea will sometimes take the stoploss but not the takeprofit and I will solve that problem and let it close ALL trade( includes pending order) if one OR more orders are closed by the ea

Thank you for your quick answer


Actually what you want already covered so many times. Google it. What qjol put here is a part of what you want to achieve.
 
deysmacro:

What qjol put here is a part of what you want to achieve.

its not a part just the idea
 

@qjol : That is how I count the buy and the sell orders but how can I set previousOpenOrders = x; currentOpenOrders =y; ?

int BuyTotalMagicOpen() {
int OrderCount = 0;
for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
if (OrderType() == OP_BUY) OrderCount++;
}
return (OrderCount);
}


int SellTotalMagicOpen() {
int OrderCount = 0;
for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
if (OrderType() == OP_SELL) OrderCount++;
}
return (OrderCount);
}

@deysmacro :I had use Google but I didnt found something, can you give me an idea what exactly i have to google ?

 

Put ...

int BuyTotalMagicOpen() {
int OrderCount = 0;
for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
if (OrderType() == OP_BUY) OrderCount++;
}
return (OrderCount);
}


int SellTotalMagicOpen() {
int OrderCount = 0;
for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
if (OrderType() == OP_SELL) OrderCount++;
}
return (OrderCount);
}

if (currentOpenOrdess < PreviousOpenOrders)
{Close-Them-All-code-here}

previousOpenOrders = currentOpenOrders;

Something like that.

 
Hmm it doesent work...
 
Its ok then since you just need to do some homework a little bit more. XD
Reason: