HELP with code, Order would not close together.

 

Hi, I am programing a EA with 3 max open orders, found the order open function is fun but those orders would not close together, they close one by one, I try some different way but still the same

please help me to check the code. I got the code from the MACD sample. just change a little bit of original code, like "if total<3" (was 1)

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL &&

OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY)

{

if(Bid>=mafast)

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);

return(0);

}}}}

I want all three order close once the price over the upper red line.

 

By having (using the SRC button to make code easier to read)

return(0);

in your loop, you destroy the loop, as it will immediately jump out.

Place it after the loop, which is difficult to work out where it is as you've not got it nicely formatted

 

In Your Code you do select ONE order and THAN you check the closing condition... (if Bid >= mafast) for each Order...

1. You must check your closing condition FIRST and THAN close all opened Orders...

2. return(0); must be plased after your for() Cycle... If the return(0) is inside, you kill your for() cycle...

... something like this ... :

if(Bid>=mafast) 
{
   for(cnt=0;cnt<total;cnt++)
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_BUY && OrderSymbol()==Symbol()) 
      {
         OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
      }
   }
   return(0);


}

The second Thing is

Greetz

https://www.mql5.com/go?link=http://www.mql-trading.de//

https://www.mql5.com/go?link=http://www.tradertoolbox.de//

 
sebecht:

In Your Code you do select ONE order and THAN you check the closing condition... (if Bid >= mafast) for each Order...

1. You must check your closing condition FIRST and THAN close all opened Orders...

2. return(0); must be plased after your for() Cycle... If the return(0) is inside, you kill your for() cycle...

... something like this ... :

The second Thing is

Greetz

https://www.mql5.com/go?link=http://www.mql-trading.de//

https://www.mql5.com/go?link=http://www.tradertoolbox.de//


the second thing is .. .both sides does not work ;-)
 

You MUST count down when closing multiple orders. In the presence of another EA/chart you must test orderSelect.

for(int pos=OrdersTotal()-1; pos>=0; pos--) if(
   OrderSelect(pos, SELECT_BY_POS)
&& OrderType()==OP_BUY 
&& OrderSymbol()==Symbol()) 
      {
         if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)){
            Alert("OrderClose failed ",GetLastError());
      }


 
EADeveloper:

the second thing is .. .both sides does not work ;-)


@ EADeveloper...

I know...

both sides are under construction...

Reason: