Help needed in OrderClose.

 

Need to close order when price reaches to certain level. its simple but I couldn't make it. I am a newbie, appreciate your help.

example below.


double Ticket, Openprice, Lot,  Tp=150;


    Symb=Symbol();                               // Security name

    

    for(int i=1; i>=OrdersTotal(); i++)          // Loop through orders

     {

      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one

        {                                       // Analyzing orders:

         if (OrderSymbol()!=Symb)continue;      // Another security

         

         Ticket=OrderTicket();                  // Number of selected order

         Openprice=OrderOpenPrice();            // Price of selected order

         Lot   =OrderLots();                    // Amount of lots

        }

  

   {

   if (Bid>=Openprice+Tp*Point);

      bool Ans=OrderClose(Ticket,Lot,Bid,2);

   }
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. for(int i=1; i>=OrdersTotal(); i++)          // Loop through orders
    Infinite loop.
  3. Give your order a take profit, and it will close itself.
  4.    if (Bid>=Openprice+Tp*Point);
    
          bool Ans=OrderClose(Ticket,Lot,Bid,2);
    The if statement does nothing; the close is always called.
  5. Both assume a buy order.
 
Is there any way to close order when price reaches to certain level. i don't want to mention take profit in the Ordersend. 
 
Your question has already been answered. Fix your broken code.
Reason: