Close order automatically after a given period and/or SL - page 4 1234 New comment Simon Gniadkowski 2012.02.06 22:38 #31 Please use the SRC button to post code . . . . Simon Gniadkowski 2012.02.06 22:40 #32 It maybe that you are trying to close an order twice . . if (OrderType() == OP_BUY || OP_SELL) { bool Closed = OrderClose(OrderTicket(),OrderLots(), OrderClosePrice(), UseSlippage, Red); openbuy = 0; opensell = 0; } if (OrderType() == OP_SELL) { Closed = OrderClose(OrderTicket(),OrderLots(), OrderClosePrice(), UseSlippage, Red); opensell = 0; openbuy = 0; } } You only need one of these . . . and use . . . if (OrderType() <= OP_SELL) that covers OP_SELL and OP_BUY read this: https://docs.mql4.com/constants/trading [Deleted] 2012.02.07 12:10 #33 I changed the code like this: for(int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if((OrderOpenTime()+3600) < TimeCurrent()) { if (OrderType() == OP_BUY) { bool Closed = OrderClose(OrderTicket() ,OrderLots(), OrderClosePrice(), UseSlippage, Red); openbuy = 0; } if (OrderType() == OP_SELL) { Closed = OrderClose(OrderTicket() ,OrderLots(), OrderClosePrice(), UseSlippage, Red); opensell = 0; } } } } Now I need to find out how I let the code count opensell and openbuy to 0 when hitting the StopLoss or TakeProfit Tjipke de Vries 2012.02.07 13:13 #34 nirvanamac: I changed the code like this: Now I need to find out how I let the code count opensell and openbuy to 0 when hitting the StopLoss or TakeProfit opensell = 0; openbuy =0; for(int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) //==> select also on magicnumber and symbol { if(OrderMagicnumber()== magicnumber && OrderSymbol()== Symbol() && OrderType() == OP_BUY){openbuy++;} if(OrderMagicnumber()== magicnumber && OrderSymbol()== Symbol() && OrderType() == OP_SELL){opensell++;} if((OrderOpenTime()+3600) < TimeCurrent() && OrderMagicnumber()== magicnumber && OrderSymbol()== Symbol()) { if (OrderType() == OP_BUY) { bool Closed = OrderClose(OrderTicket() ,OrderLots(), OrderClosePrice(), UseSlippage, Red); openbuy = openbuy-1; //openbuy--; } if (OrderType() == OP_SELL) { Closed = OrderClose(OrderTicket() ,OrderLots(), OrderClosePrice(), UseSlippage, Red); opensell = opensell-1; //opensell--; } } } } Select directly on magicnumber and symbol this code will then be written in a better way If you use it the way you had made it then you will close all open trades longer running then a hour (also not from this one) Opening and Closing Positions Opening and Closing Positions Bulk Operations - Trade [Deleted] 2012.02.07 13:28 #35 deVries: Select directly on magicnumber and symbol this code will then be written in a better way If you use it the way you had made it then you will close all open trades longer running then a hour (also not from this one) Hi deVries...I've tried it and will check it now with TP and SL...thanks a lot... [Deleted] 2012.02.07 13:34 #36 Wow now it looks good :) not the performance but the EA with SL and TP 1234 New comment
Please use the SRC button to post code . . . .
It maybe that you are trying to close an order twice . .
You only need one of these . . . and use . . .
that covers OP_SELL and OP_BUY read this: https://docs.mql4.com/constants/trading
I changed the code like this:
Now I need to find out how I let the code count opensell and openbuy to 0 when hitting the StopLoss or TakeProfit
I changed the code like this:
Now I need to find out how I let the code count opensell and openbuy to 0 when hitting the StopLoss or TakeProfit
Select directly on magicnumber and symbol this code will then be written in a better way
If you use it the way you had made it then you will close all open trades longer running then a hour (also not from this one)
Select directly on magicnumber and symbol this code will then be written in a better way
If you use it the way you had made it then you will close all open trades longer running then a hour (also not from this one)
Hi deVries...I've tried it and will check it now with TP and SL...thanks a lot...
Wow now it looks good :) not the performance but the EA with SL and TP