This code will only close one order

 

Hi Folks!!!

Someone kindly assist with a segment of code that is not working as its supposed to. The code should close two orders yet only closes one of the two orders. where am i missing the point??? Thanks in advance and much appreciated.

//Trade target met for two open orders in profit.
   if((ord_count==2 && ord_prof >=10.00))
       { for(cnt=0;cnt<total;cnt++)
           { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
               if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
                  {  
                    OrderCloseReliable(OrderTicket(),OrderLots(),Bid,3,Violet); // close position 
                  }
             }
       }

 

well we can not see how you calculate ord_count nor can we see how you calculate ord_prof.

we can also not tell how you calculate total.

we can also not tell the type of orders that are open.

 
Kenneth Njuguna:

Hi Folks!!!

Someone kindly assist with a segment of code that is not working as its supposed to. The code should close two orders yet only closes one of the two orders. where am i missing the point??? Thanks in advance and much appreciated.

//-- add iteration for

   //Trade target met for two open orders in profit.
   if((ord_count==2 && ord_prof >=10.00))
       { for(cnt=0;cnt<total;cnt++)
           { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
               for(int i=0; i<ord_count; i++)
                 {
                   if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
                     {  
                       OrderCloseReliable(OrderTicket(),OrderLots(),Bid,3,Violet); // close position 
                     }
                 }
           }
       }
 
Roberto Jacobs:

Roberto Jacobs!!!! Thanks a lot my brother!! And definitely much appreciated. The code should now and is working as presribed.

Regards

 
Kenneth Njuguna:

Roberto Jacobs!!!! Thanks a lot my brother!! And definitely much appreciated. The code should now and is working as presribed.

Regards

you're welcome bro.. ^_^