To close position

 

Can anybody please give a code hint 

how to write in MQL5 that was OrderClose() and OrderDelete() in MQL4?

Please no OOP. 

Thanks a lot.

 
"Learner21:

Can anybody please give a code hint 

how to write in MQL5 that was OrderClose() and OrderDelete() in MQL4?

Please no OOP. 

Thanks a lot."

 

#include <Trade\Trade.mqh>

..............

CTrade  trade;

COrderInfo  order; 

CPositionInfo position;

 

// deleting pending orders

for( int i = OrdersTotal() -1; i >= 0; i--)

       if( order.Select( OrderGetTicket( i) )

      {  

                 if( order.Symbol() == your_symbol)

                {

                        ........

                       if( trade.OrderDelete( order.Ticket() ) )

                       { 

                                  // ok, the order was deleted

                       } 

                       else

                       { 

                              // order was not deleted  

                        }

                } 

}

 

//closing buy or sell positions

((first order determines if a buy or sell position) 

 

if( position.Select( your_symbol) )

{

         if( trade.PositionClose( your_symbol) )

        {

            //ok, position is closed

        }

        else

        {

           //position wasn't closed

        }

}

.......... 

 

 

      

     

                                 

 

 

      

                   

 

 

 

.... 

 
Very nice. Thanks a lot.