当前位置:网站首页>Mt4/mql4 getting started to be proficient in EA tutorial lesson 6 - common functions of MQL language (VI) - common order function

Mt4/mql4 getting started to be proficient in EA tutorial lesson 6 - common functions of MQL language (VI) - common order function

2022-06-22 08:01:00 EA development - green shirt code customer

bool OrderClose()

Closing function , This function is 5 Parameters


bool  OrderClose( 
   int        ticket,      //  The order number 
   double     lots,        //  Hand count 
   double     price,       //  Closing price 
   int        slippage,    //  Slide it  
   color      arrow_color  //  The arrow color 
   );

Manually open an order
 Insert picture description here
The order number is :198463618

Number of hands is :1

The script instance

void OnStart() 
  {
     
   OrderClose(198463618,1,Bid,3,Red);  
  }

Run the script
 Insert picture description here
Order closed successfully !

double OrderClosePrice();

Return the closing price of the order

int OrdersHistoryTotal();

Return the total number of historical transaction orders

bool OrderSelect();

Order identification , There are up to three parameters


bool  OrderSelect( 
   int     index,            //  Order number or custom sort 
   int     select,           //  Parameter type 
   int     pool=MODE_TRADES  //  sort order 
   );

Two parameter form


OrderSelect(12470,   // The order number 
        SELECT_BY_TICKET  // Order number sorting 
        )

Three parameter form

OrderSelect(i,     // Custom serial number 
    SELECT_BY_POS, // Custom sort 
    MODE_HISTORY   // Sort historical orders , Holding bin sort code :MODE_TRADES 
    )

datetime OrderOpenTime();

Return the opening time of the order

datetime OrderCloseTime();

Return the order closing time

double OrderOpenPrice();

Return the opening price of the order

double OrderClosePrice();

Return the closing price of the order

double OrderProfit();

Return order profit and loss

double OrderLots();

Return the number of orders opened

int OrderTicket();

Return the order number of the order

The script instance

void OnStart() 
  {
     
   int hstTotal=OrdersHistoryTotal(); 
   Print("hstTotal for the order:", hstTotal); 
   if(OrderSelect(hstTotal-1,SELECT_BY_POS,MODE_HISTORY)==true) 
    {
     
     datetime ctm=OrderOpenTime(); 
     if(ctm>0) Print("Open time for the order: ", ctm); 
    
     ctm=OrderCloseTime(); 
     if(ctm>0) Print("Close time for the order: ", ctm); 
     
     double close=OrderClosePrice();
     Print("ClosePrice for the order:", close); 
     
     double open=OrderOpenPrice();
     Print("OpenPrice for the order:", open); 
     
     double profite=OrderProfit(); 
     Print("Profite for the order:", profite);
     
     double lots=OrderLots();  
     Print("Lots for the order:", lots);
         
     int ticket=OrderTicket();
     Print("ticket for the order:", ticket);
     
    } 
  else 
    Print("OrderSelect failed error code is",GetLastError());
  }

Example results

Print out the information of the last transaction order
 Insert picture description here
 Insert picture description here
A good workman does his work well , You must sharpen your tools first , The most important thing in trading is to follow the rules , Strictly carry out . Official account , Study MQL Beginner to master EA course , Learn more EA Programming , Write your own EA, Forge your own magic weapon .

 Insert picture description here

原网站

版权声明
本文为[EA development - green shirt code customer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220530131073.html