Find if you have a pending or open order using a OrderSelect loop
actually i got both but they are inside a for loop do i have to work on both ? and how can i work on them or one of the orderselect ?
here is the code for my pending order and open order inside the for loop :
for(PositionIndex=TotalNumberOfOrders-1; PositionIndex>=0; PositionIndex --)//Here is my For Loop that check to Delete any pending order opened while a pending just got Hit { if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES )//OrderSelect N01 { continue; } if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()==Symbol() && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP)) { continue; } if(OrderType()==OP_SELL) { result=OrderDelete(ticket1,clrNONE);//EURUSD-->BUY result=OrderDelete(ticket1,clrNONE);//USDJPY--->BUY result=OrderDelete(ticket1,clrNONE);//USDCAD--->BUY result=OrderDelete(ticket2,clrNONE);//EURUSD--->SELL result=OrderDelete(ticket2,clrNONE);//USDJPY---->SELL result=OrderDelete(ticket2,clrNONE);//USDCAD---->SELL result=OrderDelete(ticket1,clrNONE);//GPBUSD--->BUY result=OrderDelete(ticket2,clrNONE);//GPBUSD--->SELL } else if(OrderType()==OP_BUY) { result=OrderDelete(ticket1,clrNONE);//EURUSD-->BUY result=OrderDelete(ticket1,clrNONE);//USDJPY--->BUY result=OrderDelete(ticket1,clrNONE);//USDCAD--->BUY result=OrderDelete(ticket2,clrNONE);//EURUSD--->SELL result=OrderDelete(ticket2,clrNONE);//USDJPY---->SELL result=OrderDelete(ticket2,clrNONE);//USDCAD---->SELL result=OrderDelete(ticket1,clrNONE);//GPBUSD--->BUY result=OrderDelete(ticket2,clrNONE);//GPBUSD--->SELL } } for(PositionIndex=TotalNumberOfOrders-1; PositionIndex>=0; PositionIndex --)//Here is my For Loop that check to Delete the Open order who have reached the StopLoss or The TakeProfit { if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES))//Here is my OrderSelect N02 if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()==Symbol() && (ticket1==OP_BUY || ticket2==OP_SELL)) if(OrderType()==OP_SELL )//SELL ORDER On Positif TRADE if(!OrderClose(ticket2,0.01,Bid-Price*Point ,clrNONE) ) //Here the Ticket2(Bid) are closing if it is on a TakeProfite side Print("Price on positif side -----> ", Bid-Price*Point ); if(OrderType()==OP_SELL )//SELL ORDER On Negatif TRADE if(!OrderClose(ticket2,0.01,Bid+Price*Point,5,clrNONE)) //Here the Ticket2(Bid) are closing if it is on a StopLoss side if(OrderType()==OP_BUY )//BUY ORDER On Positif TRADE if(!OrderClose(ticket1,0.01,Ask+Price*Point,5,clrNONE)) //Here the Ticket1(Ask) are closing if it is on a TakeProfite side Print("Price on positif side -----> " ,Ask+Price*Point ); if(OrderType()==OP_BUY )//BUY ORDER On Negatif TRADE if(!OrderClose(ticket1,0.01,Ask-Price*Point,clrNONE)) //Here the Ticket1(Ask) are closing if it is on a StopLoss side Print("Order Close failed, order number: ",ticket1," Error: ",GetLastError()); }
How many times do you need to test the same thing in the same if? | if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()==Symbol() && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP)) |
If ticket1/2 is a ticket then it will never be the magic number or the order type of the selected order, so the if is never true. If ticket1/2 is not a ticket, the the OrderDelete will never work as it requires a ticket number. | if((OrderMagicNumber()==ticket1 || OrderMagicNumber()==ticket2) && OrderSymbol()==Symbol() && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP) && (ticket1==OP_BUYSTOP || ticket2==OP_SELLSTOP)) : result=OrderDelete(ticket1,clrNONE);//EURUSD-->BUY |
Why are you doing this inside a OrderSelect loop? Why are you deleting the same ticket1 three times however many orders are open. Either it worked or it didn't. | result=OrderDelete(ticket1,clrNONE);//EURUSD-->BUY result=OrderDelete(ticket1,clrNONE);//USDJPY--->BUY result=OrderDelete(ticket1,clrNONE);//USDCAD--->BUY |
Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles | result=OrderDelete(ticket1,clrNONE); |
I previously said Orders are not inside any loop. Post your code where you check if you have any orders and do not open more. | You aren't checking anything. You are doing things without checking. Basically your code is gibberish. |
Do you really expect to be able to close and order at a price other then the current market Bid or Ask? | if(!OrderClose(ticket1,0.01,Ask+Price*Point,5,clrNONE)) |

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 ,
Any body can tell me how i can loop my ea after the whole process is complete( Open pending order --> pending order get hit ---> open order get close --> no order --> start again --> Open pending order etc.. etc.. )
Thanks for the help.