Download MetaTrader 5

what is the differnece between position and order?

To add comments, please log in or register
Track all payments in your profile. It is easy!
LEE Chun Wing
831
LEE Chun Wing 2010.05.23 18:06 

what is the differnece between position and order? 

i would like to have an example of how to get OrderOpenTime of an opened order e.g. EURUSD.OpenTime()

 

thanks 

lee
191
lee 2010.05.23 18:20  
kelly posted  :

what is the differnece between position and order? 

i would like to have an example of how to get OrderOpenTime of an opened order e.g. EURUSD.OpenTime()

 

thanks 

that is the question that i want to ask:

what's the d of PositionsTotal() and OrdersTotal() in MQL5 

lee
191
lee 2010.05.23 18:31  
kelly posted  :

what is the differnece between position and order? 

i would like to have an example of how to get OrderOpenTime of an opened order e.g. EURUSD.OpenTime()

 

thanks 

OrderOpenTime is getting by OrderGetInteger() in OrderSelect() function

but how to find the index of OrderSelect() also is my puzzle

that is use

 OrderGetInteger(ORDER_TIME_SETUP ,orderOpenTime); 

then the result of  order Open Time will save at "orderOpenTime" this variable


the identifier of OrderGetInteger() is ORDER_TIME_SETUP

remember datetime is integer value 

 

besides, u may get sl by 

sl=OrderGetDouble(ORDER_SL);

or as

OrderGetDouble(ORDER_SL,sl); 
lee
191
lee 2010.05.23 18:38  

i have find how to get the ticket number of orderSelect

OrderGetTicket

Returns ticket of a corresponding order automatically selects the order for further working with it using functions.

ulong  OrderGetTicket(
   int  index      // Number in the list of orders
   );

Parameters

index

[in]  Number of an order in the list of orders.

Return Value

Value of the ulong type.

Example:

void OnStart()
  {
   
datetime from=0;
   
datetime to=TimeCurrent();


//--- request the entire history
   
HistorySelect(from,to);
//--- variables for returning values from order properties
   
ulong    ticket;
   
double   open_price;
   
double   initial_volume;
   
datetime time_setup;
   
string   symbol;
   
string   type;
   
long     order_magic;


//--- number of current pending orders
   
uint     total=OrdersTotal();
//--- go through orders in a loop
   
for(uint i=0;i<total;i++)
     {
      
//--- return order ticket by its position in the list
      
if(ticket=OrderGetTicket(i))
        {
         
//--- return order properties
         open_price=       
OrderGetDouble(ORDER_PRICE_OPEN);
         time_setup=       
OrderGetInteger(ORDER_TIME_SETUP);
         symbol=           
OrderGetString(ORDER_SYMBOL);
         order_magic=      
OrderGetInteger(ORDER_MAGIC);
         positionID =      
OrderGetInteger(ORDER_POSITION_ID);
         initial_volume=   
OrderGetDouble(ORDER_VOLUME_INITIAL);
         type=GetOrderType(
OrderGetInteger(ORDER_TYPE));


         
//--- prepare and show information about the order
         
printf("#ticket %d %s %G %s at %G was set up at %s",
                ticket,                 
// order ticket
                type,                   
// type
                initial_volume,         
// placed volume
                symbol,                 
// symbol
                open_price,             
// specified open price
                
TimeToString(time_setup)// time of order placing
                );
        }
     }
//---
  }
//+------------------------------------------------------------------+
//|  returns the string name of the order type                       |
//+------------------------------------------------------------------+
string GetOrderType(long type)
  {
   
string str_type="unknown operation";
   
switch(type)
     {
      
case (ORDER_TYPE_BUY):            return("buy");
      
case (ORDER_TYPE_SELL):           return("sell");
      
case (ORDER_TYPE_BUY_LIMIT):      return("buy limit");
      
case (ORDER_TYPE_SELL_LIMIT):     return("sell limit");
      
case (ORDER_TYPE_BUY_STOP):       return("buy stop");
      
case (ORDER_TYPE_SELL_STOP):      return("sell stop");
      
case (ORDER_TYPE_BUY_STOP_LIMIT): return("buy stop limit");
      
case (ORDER_TYPE_SELL_STOP_LIMIT):return("sell stop limit");
     }
   
return(str_type);
  }

 

lee
191
lee 2010.05.23 18:57  

order   = pending order

position = opened order

deal = alter the SL\TP of order or position

 

uint     total=PositionsTotal();
for(uint i=0;i<total;i++) {
   
  if ( ticket = OrderGetTicket(i) )
            {
         
       open_price=       OrderGetDouble(ORDER_PRICE_OPEN);
                time_setup=       
OrderGetInteger(ORDER_TIME_SETUP);
               symbol=           
OrderGetString(ORDER_SYMBOL);
              order_magic=      
OrderGetInteger(ORDER_MAGIC);
              positionID =      
OrderGetInteger(ORDER_POSITION_ID);
              initial_volume=   
OrderGetDouble(ORDER_VOLUME_INITIAL);
               type= GetOrderType(
OrderGetInteger(ORDER_TYPE));

            }

 

http://mqlmagazine.com/mql-programming/orders-positions-and-deals-part-ii/ 

Wackena
648
Wackena 2010.05.23 20:17  

"Order" is manually or by EA initiated from an OrderSend() call. The "Order" then initiates a "Deal" that is sent to Broker's server. On success, then a "Position" is opened that is seen in the Toolbox/trade tab. The "Position" can have only 1 trade or superposition of multiple trades of same symbol and type.

OrdersTotal() call is for Pending Orders only. As soon as "Order" converts to a "Deal", then the "Order" is closed. Then you can only access these closed "Order" by using HistorySelect() call, then followed by HistoryOrderGetTicket() call. Example:https://www.mql5.com/en/docs/trading/historyordergetticket. Similar procedure for HistoryDeals.

Here is a way to get the OrderOpenTime of the last order processed in current opened position.

datetime LastOrderOpenTime()
{
   datetime Ltime;
   uint total=0;
   
   HistorySelect(0,TimeCurrent()); // selects history for all closed orders and deals
   total=HistoryOrdersTotal(); // gets history orders total. This number references the last closed order
         
   if( PositionsTotal() > 0 ) // Only looks for last order open time when at least 1 positions is open.
      {
         for(uint i=0;i<total+1;i++)
            {
             if( PositionSelect(_Symbol) )
              {
                HistoryOrderGetTicket(i);
                Ltime=HistoryOrderGetInteger(i,ORDER_TIME_SETUP);
              }
           }
      }
      
   return(Ltime);
}
Documentation on MQL5: Trade Functions / HistoryOrderGetTicket
  • www.mql5.com
Trade Functions / HistoryOrderGetTicket - Documentation on MQL5
skatt
186
skatt 2010.05.25 23:27  
I am under the impression that orders are any requests that are sent to the server, whether or not they are successfully filled, and deals are orders that have been successfully filled. A position would be the total holdings of a symbol (one position allowed per symbol). Please correct me if I'm wrong. I hope the documentation will improve by the time MT5 is released.

To add comments, please log in or register