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);
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( |
Parameters
index
[in] Number of an order in the list of orders.
Return Value
Value of the ulong type.
Example:
void OnStart()
|
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/
"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); }
- www.mql5.com
In MQL5, a position refers to an open trade that has been executed in the market. It is created when an order is filled and can be either a long position (buy) or a short position (sell).
An order, on the other hand, is a request to execute a trade at a specific price and size. Orders can be of different types, such as market orders, pending orders, and stop orders. Orders can be placed, modified or cancelled, and if they get filled, they will create a position.
In summary, an order is a request to execute a trade while a position is the result of a filled order, an open trade.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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