for (int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberBuy)// or add && OrderType() == OP_BUY { OrderClose(OrderTicket(),Lots,Ask,SlipPageClose,Blue); } } }
qjol:
Thanks for your reply i placed the code instead of the two lines
and it didnt still work
if(OrderSelect(MagicNumberBuy, SELECT_BY_POS,MODE_TRADES)==true) OrderClose(OrderTicket(),Lots,Ask,SlipPageClose,Blue);
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),SlipPageClose,Blue);
& if it's doesn't go
put some Print(GetLastError()) or Alert(GetLastError()) to find out y
u sure error 3
try
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),SlipPageClose,Blue); int err = GetLastError(); Print ("Last Error is: ", err);
I did it and returned with
2010.12.31 05:42:40 Abdu_First Of The Trend_EA EURUSD,H1: Last Error is: 3
you cant use magicnumber with OrderSelect.
if(OrderSelect(MagicNumberBuy, SELECT_BY_POS,MODE_TRADES)==true) OrderClose(OrderTicket(),Lots,Ask,SlipPageClose,Blue);
loop through all orders and:
if(OrderMagicNumber() == MagicNumberBuy){ //Do your stuff here }
this is only an example, and should be a guidiance.
enotrek:
you cant use magicnumber with OrderSelect.
loop through all orders and:
this is only an example, and should be a guidiance.
Thanks for your help, but how could i loop through all the orders?
maybe this can help you
int cnt; for(cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) // long position is opened { // should it be closed? } if(OrderType()==OP_SELL) // go to short position { // should it be closed? } } } }
Arwee:
maybe this can help you
maybe this can help you
for closing orders u should loop down
for(cnt = OrdersTotal() - 1; cnt >= 0; cnt--)
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 all, i want my expert to close sell order for a pair when it opens buy order for that pair and vice versa. I wrote the following code:
However, the expert opens the sell order, but does not close the buy order that it had opened previously with the MagicNumberBuy.
I don't know how to let the expert know the ticket for the order that has to be closed, so i used the Magic Number.
I need some help, waiting for you reply sir, and thanks.