Download MetaTrader 5
To add comments, please log in or register
Do you want to learn MQL5? 300 articles will help you!
Ivan
120
Ivan 2011.07.15 09:49 

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.

JMRodMartins
238
JMRodMartins 2011.07.15 17:14  
"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

        }

}

.......... 

 

 

      

     

                                 

 

 

      

                   

 

 

 

.... 

Ivan
120
Ivan 2011.07.16 06:54  
Very nice. Thanks a lot.
/
To add comments, please log in or register