mark692: hi guys my EA has has a function of 1. delete pending order for buy, 2. close open order for buy, 3.delete pending order for sell, 4. close open order for sell. When I coded my EA I made it in to two different .mq4 BUY.mq4 and SELL.mq4 to avoid confusion, all is working perfectly fine. The problem occurs when I combine the code into one .mq4. All of a sudden errors appear when i run the combined .mq4 "OrderClose Error 4108" and "OrderDelete Error 4108". Can you help me on this? after this and I will finish my first EA. Thank you so much :) i have noticed for example I have 5 open orders the function to close open order only works on the first 4 trade but the fifth or last order will not be closed and the error will appear.
You are already know what is needed to answer your query. Show your code! We cannot "guess" what is wrong with it.
Fernando Carreiro:
You are already know what is needed to answer your query. Show your code! We cannot "guess" what is wrong with it.
You are already know what is needed to answer your query. Show your code! We cannot "guess" what is wrong with it.
opps sorry i forgot :)
here is the code for my Delete buystop and sell stop
void DeleteBuystopBuyH()//OK { for(int i=OrdersTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType() == OP_BUYSTOP && OrderMagicNumber()== BBuyHMagicNumber && BBuyHMagicNumberCount()==0 && BBuyStopCount()>0 && ActivateBuyH()== False && BSellHMagicNumberCount()==0) { if ( OrderDelete(OrderTicket()) ) continue; Print("OrderClose error ",GetLastError()); return; } } } } void DeleteSellstopBuyH()//OK /*{ for(int i=OrdersTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType() == OP_SELLSTOP && OrderMagicNumber()== BSellHMagicNumber && BSellHMagicNumberCount()==0 && BSellStopCount()>0 && ActivateBuyH()== False && BBuyHMagicNumberCount()==0) { if ( OrderDelete(OrderTicket()) ) continue; Print("OrderClose error ",GetLastError()); return; } } } }
here is the code for my close sell and buy
void CloseSell() { int PositionIndex; int TotalNumberOfOrders; TotalNumberOfOrders = OrdersTotal(); for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) { if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue; if( OrderMagicNumber() == SellMMagicNumber && OrderSymbol() == Symbol() && SBuyHMagicNumberCount() == 1 && CurrentOpenSellTrade() > 0) if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 0 ) ) Print("Order Close failed F, order number: ", OrderTicket(), " Error: ", GetLastError() ); } // } ////////////////////////////////////////////////// void CloseBuy() { int PositionIndex; int TotalNumberOfOrders; TotalNumberOfOrders = OrdersTotal(); for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) { if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue; if( OrderMagicNumber() == BuyMMagicNumber && OrderSymbol() == Symbol() && SSellHMagicNumberCount() == 1 && CurrentOpenBuyTrade() > 0) if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 0 ) ) Print("Order Close failed F, order number: ", OrderTicket(), " Error: ", GetLastError() ); } // }
for(int i=OrdersTotal()-1;i>= 0 ;i--) if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderType() == OP_SELLSTOP && OrderMagicNumber()== BSellHMagicNumber && OrderSymbol()==Symbol() && BSellHMagicNumberCount()==0 && BSellStopCount()>0 && ActivateBuyH()== False && BBuyHMagicNumberCount()==0 ){
Do those functions also do an OrderSelect loop?
William Roeder:
Do those functions also do an OrderSelect loop?
yes sir this two also do an order select
int BSellStopCount() { int BSellStopCount=0; for(int i=OrdersTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType() == OP_SELLSTOP && OrderMagicNumber()== BSellStopMagicNumber) { BSellStop++; } } } return (BSellStop); }
int BSellHMagicNumberCount()t() { int BSellHMagicNumberCount=0; for(int i=OrdersTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderMagicNumber()== BSellHMagicNumber && OrderType() == OP_SELL) { BSellHMagicNumberCount++; } } }
this two sir
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
hi guys my EA has has a function of
1. delete pending order for buy
2. close open order for buy
3.delete pending order for sell
4. close open order for sell
when I coded my EA I made it in to two different .mq4 BUY.mq4 and SELL.mq4 to avoid confusion, all is working perfectly fine. The problem occurs when I combine the code into one .mq4. All of a sudden errors appear when i run the combined .mq4 "OrderClose Error 4108" and "OrderDelete Error 4108". Can you help me on this? after this and I will finish my first EA. Thank you so much :)
i have noticed for example I have 5 open orders the function to close open order only works on the first 4 trade but the fifth or last order will not be closed and the error will appear.