With the code attached it doesn't open short pending orders ! and only open 1 pending order for long trades.
I was trying to have 3 pending trades open Short/ Long each Entry price incremented by 25pips.
If you could let me know of any coding mistakes I have made or suggestions are appreciated. Thanks
Can you explain what this line does and what the flow of the code is when you have a Sell order ?
if(OrderType() != OP_BUY) continue;
1 /I added the "continue;" so that if the pending order is for a Sell Pending order it doesn't try to Ordersend the Buy pending order.
Before adding the "continue;" I had the same issues as now. When the The Sell order is triggered it doesn't generate a pending order at all or any error with or without the contine;. I just tried it without the contine; (copy of code attached below).
2 /The second thought behind adding that "OP_Buy" line was to identify which order to send, being a Buy order then now wanting the EA to send the Buy pending order.
I hope this helps to identify were my understanding may be out. Thanks.
if(OrderType()== OP_BUY && OrderMagicNumber()==magicnoa && OrderSymbol() == Symb) { //4 OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice()+ (Point*25)*10,2,00,00," ",magicnoa); Alert("Pending Order Opened ");
1 /I added the "continue;" so that if the pending order is for a Sell Pending order it doesn't try to Ordersend the Buy pending order.
Before adding the "continue;" I had the same issues as now. When the The Sell order is triggered it doesn't generate a pending order at all or any error with or without the contine;. I just tried it without the contine; (copy of code attached below).
The problem with this is that if the Order is a Sell it will never get to the code that you want it to as the continue will just skip the loop to the next order so Sell orders will never be handled.
You code above will never open a pending Buy order when it has found a Sell order because of the . . .
if(OrderType()== OP_BUY
. . . a OP_SELL would fail this test and the following block of code (that places the pending Buy) will not be executed. Your new code above should do what you wanted ?
I do not clearly understand how your EA works but after this line
Try using the else operator to continue the flow as in
And of course change the OrderType() in line 2 to OrdersTotal().
else{ if(OrderMagicNumber()==magicnoa && OrderSymbol() == Symb) { OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice()+ (Point*25)*10,2,00,00," ",magicnoa); Alert("Pending Order Opened "); }
It goes wrong when you open new trades while you still checking the open trades....
First checking trades has to be done with checking OrdersTotal() //can't do it with OrderType
If there is one buy open and not right pending buy amount trades open then after you have done the loop you can place them not inside the loop
Also for sell trades .....
Check your open trades and then look if it is needed to open new pending or manage the trades you have....
for(int ipend =OrderType(); ipend<=7 ; ipend++) { //2 if(OrderSelect(ipend,SELECT_BY_POS,MODE_TRADES)) { //3
- You can NOT use OrderType(), OrderOpenPrice(), etc, UNTIL you do an order select
- What does OrderSelect(by_POS) require and what are you giving it?
- See How to count number of opend positions? - MQL4 forum
Thanks Raptor UK and Lema for your assistance, I changed the cylce "for" as per the code attached but only 1 pending order is comming through rather then 3 pending orders .I would like to have 3 pending orders each incremented by 20pips and as 1pending order goes to market another pending order opens maintaining a minimum of 3 pending orders until all orders are closed.
I have tried changing in the cycle "for" ipend<=5 to 1 or and even to 10. But still I only recevie 1 pending order. Is anyone aware how I can acheive this ?
I have also attached the code to modify the pending order and to add a stop loss,( ECN broker). I am only getting "Orderselect failed:0". I have tried both "Select_by_ Pos and Select_ by_Ticket but get the same result,Orderselect Failed: 0.
Any assistance on how I can improve these 2 issues would be welcomed.
// Create Pending Orders SLP= Bid - New_Stop(pendingsl)*Point; SLP2= Ask + New_Stop(pendingsl2)*Point; RefreshRates(); if( pendingorders >0 ) { //1 for(int ipend =OrdersTotal(); ipend<=5 ; ipend--) { //2 if(OrderSelect(ipend,SELECT_BY_POS,MODE_TRADES)) { //3 if(OrderType()== OP_BUY && OrderMagicNumber()==magicnoa && OrderSymbol() == Symb) { //4 OrderSend(Symb,OP_BUYSTOP,Lts,OrderOpenPrice()+ (Point*20)*10,2,00,00," ",magicnoa); Alert("Pending Order Opened "); if(Ticket < 0) // Less the 0 order failed "else" otherwise process order modify. { Alert ("OrderSend failed",GetLastError()); } else { //8 if(!OrderSelect(Ticket,SELECT_BY_TICKET)) { Alert("OrderSelect failed: ",GetLastError()); } else { //9 if (!OrderModify(OrderTicket(),OrderOpenPrice(),SLP,00,0)) { Alert("OrderModify Failed",GetLastError()); } } //4 } //8 } //9 if(OrderType()== OP_SELL && OrderMagicNumber()==magicnoa && OrderSymbol() == Symb){ OrderSend(Symb,OP_SELLSTOP,Lts,OrderOpenPrice() - (Point*20)*10,2,00,00," ",magicnoa); Alert("Pending Order opened"); } else { Alert("Pending Order Failed" ,GetLastError()); } if(Ticket < 0) { Alert ("OrderSend failed",GetLastError()); } else { //8 if(!OrderSelect(Ticket,SELECT_BY_POS,MODE_TRADES)) //For Pending orders how to show this ? { Alert("OrderSelect failed: ",GetLastError()); } else { //9 if (!OrderModify(OrderTicket(),OrderOpenPrice(),SLP2,00,0)) { Alert("OrderModify Failed",GetLastError()); } } //1 } //2 } //3 } //8 } //9
.
Thanks
- You can NOT use OrderType(), OrderOpenPrice(), etc, UNTIL you so an order select
- What does OrderSelect(by_POS) require and what are you giving it?
- See How to count number of opend positions? - MQL4 forum
Thanks WHroeder, I will have a look at that .
I have also attached the code to modify the pending order and to add a stop loss,( ECN broker). I am only getting "Orderselect failed:0". I have tried both "Select_by_ Pos and Select_ by_Ticket but get the same result,Orderselect Failed: 0.
You need to read the Documentation for OrderSelect() . . .
You can't do this and expect it to work . . .
if(!OrderSelect(Ticket, SELECT_BY_POS, MODE_TRADES))
. . . . SELECT_BY_POSition and you give it a ticket number not a position in the pool.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
With the code attached it doesn't open short pending orders ! and only open 1 pending order for long trades.
I was trying to have 3 pending trades open Short/ Long each Entry price incremented by 25pips.
If you could let me know of any coding mistakes I have made or suggestions are appreciated. Thanks