Download MetaTrader 5
To add comments, please log in or register
Do you want to order an application? Find out how to obtain the desired result
Fatbardh Pakashtica
193
Fatbardh Pakashtica 2014.04.17 09:45 
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 ?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.17 10:49  
Show us your code then. Please use SRC when posting the code.
Fatbardh Pakashtica
193
Fatbardh Pakashtica 2014.04.17 11:03  
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

qjol
3243
qjol 2014.04.17 12:00  

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
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.17 12:12  
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.
qjol
3243
qjol 2014.04.17 12:26  
deysmacro:

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

its not a part just the idea
Fatbardh Pakashtica
193
Fatbardh Pakashtica 2014.04.17 12:39  

@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 ?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.17 15:21  

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.

Fatbardh Pakashtica
193
Fatbardh Pakashtica 2014.04.17 17:35  
Hmm it doesent work...
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.18 02:15  
Its ok then since you just need to do some homework a little bit more. XD
/
To add comments, please log in or register