Download MetaTrader 5

This code will only close one order

To add comments, please log in or register
Do you keep a blog? Place a link to MQL5.community there and make money!
Kenneth Njuguna
181
Kenneth Njuguna 2015.12.03 16:41 

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 
                  }
             }
       }

Marco vd Heijden
Moderator
4685
Marco vd Heijden 2015.12.03 17:05  

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.

Roberto Jacobs
46437
Roberto Jacobs 2015.12.03 17:19  
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 
                     }
                 }
           }
       }
Kenneth Njuguna
181
Kenneth Njuguna 2015.12.04 09:56  
Roberto Jacobs:

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

Regards

Roberto Jacobs
46437
Roberto Jacobs 2015.12.04 10:08  
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.. ^_^
To add comments, please log in or register