issue on getting open price using HistoryOrderGetDouble(trans.position,ORDER_PRICE_OPEN)

 

Dears...

I'm trying to get the open price of an order which already closed in MQL5

as i want to open a position on SL hit, I used HistoryOrderGetDouble(trans.position,ORDER_PRICE_OPEN)

the trans.position return the order number properly. but this function return 0 as open price of the order.

i tried other arguments like ORDER_SL and ORDER_VOLUME in trace mode and they return proper value without issue but open price still is zero.

to make sure i have access to proper history i used HistorySelect with wide range of date as well. but nothing has changed


do you have any idea why this issue happened. is there something wrong in this code or this is a bug in MQL5?


Also based on some conversations, I add my real requirement which I'm looking for in a sentence below :

I'm looking for the OPEN_PRICE of the original Position which its SL hit at the moment.

Documentation on MQL5: Trade Functions / HistoryOrderGetDouble
Documentation on MQL5: Trade Functions / HistoryOrderGetDouble
  • www.mql5.com
2. Returns true or false, depending on the success of the function. If successful, the value of the property is placed into a target variable passed by reference by the last parameter. Do not confuse orders of a trading history with current pending orders that...
 
ArashB :

Dears...

I'm trying to get the open price of an order which already closed in MQL5

as i want to open a position on SL hit, I used HistoryOrderGetDouble (trans.position,ORDER_PRICE_OPEN)

the trans.position return the order number properly. but this function return 0 as open price of the order.

i tried other arguments like ORDER_SL and ORDER_VOLUME in trace mode and they return proper value without issue but open price still is zero.

to make sure i have access to proper history i used HistorySelect with wide range of date as well. but nothing has changed


do you have any idea why this issue happened. is there something wrong in this code or this is a bug in MQL5?

You don't need to refer to orders - you need to refer to DEALS

Documentation on MQL5: Trade Functions / HistoryDealSelect
Documentation on MQL5: Trade Functions / HistoryDealSelect
  • www.mql5.com
Selects a deal in the history for further calling it through appropriate functions. It returns true if the function has been successfully completed. Returns false if the function has failed. For more details on error call GetLastError(). Do not confuse orders, deals and positions. Each deal is the result of the execution of an order, each...
 

Thanks Dear...


as you may be aware, deal information related to money information of closed position.

i other word, this doesn't provide you any value regarding to price.


you may see below it cannot return the open price of the closed order.

dealproperties -> enum_deal_property_double

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request. Each trade is described by properties that allow to obtain information about it. In order to read values of properties, functions of the Identifier of a position, in the opening, modification or closing of which this deal took...
 
ArashB :

Thanks Dear...


as you may be aware, deal information related to money information of closed position.

i other word, this doesn't provide you any value regarding to price.


you may see below it cannot return the open price of the closed order.

dealproperties -> enum_deal_property_double

The order cannot be closed - the order can only be DELETED. And it will be a PENDING ORDER.

If the position is closed - you need to find a DEAL with the "Market exit" type.


Please do not use the word "order". Operate only with such concepts: "Deal" and "Position".

 

Hi Again,


I checked your way and you are right. but i should use trans.position inside HistoryDealGetDouble.

i could see its result. but still i don't know why i couldn't get result with HistoryPositionGetDouble


if anyone know what is the issue would be nice to know

 
ArashB :

Hi Again,


I checked your way and you are right. but i should use trans.position inside HistoryDealGetDouble.

i could see its result. but still i don't know why i couldn't get result with HistoryPositionGetDouble


if anyone know what is the issue would be nice to know

There is another way - modern: use OnTradeTransaction. Thus, you can catch any transaction, you can also easily see that the transaction occurred as a result of the Stop Loss triggering.

 

Thanks Vlad...


Actually I'm using this history data check on this Event (OnTradeTransaction)

Main purpose is to find the the original Position information which triggered SL.

i checked your proposed way and it doesn't work again if you have more than 1 Position open and one of them hit SL


Here is the status on history :

Time             Deal      Order     Type     Direction      Price            SL          TP

2017.03.02      25          26        Sell           in           1.05195      1.5779      1.04536

2017.03.02      26          27        Buy         Out          1.05779      1.5779      1.04536


My aim is to get the price of 25 which underlined

in trace mode i can see : trans.position = 26 / trans.deal = 26  / trans.order=27

 
ArashB :

Thanks Vlad...


Actually I'm using this history data check on this Event ( OnTradeTransaction )

Main purpose is to find the the original Position information which triggered SL.

i checked your proposed way and it doesn't work again if you have more than 1 Position open and one of them hit SL


Here is the status on history :

Time             Deal      Order     Type     Direction      Price            SL          TP

2017.03.02      25          26        Sell           in           1.05195      1.5779      1.04536

2017.03.02      26          27        Buy         Out          1.05779      1.5779      1.04536


My aim is to get the price of 25 which underlined

in trace mode i can see : trans.position = 26 / trans.deal = 26  / trans.order=27

OnTradeTransaction works great - in this function, you can track the moment when Stop Loss is triggered online. The 'TRADE_TRANSACTION_DEAL_ADD' transaction type allows you to catch the 'adding a deal to history' transaction. It remains to turn to history and find out everything about this deal.
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
The MQL5 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL5 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
 

Thanks again...


I'm using the same

if (trans.type == TRADE_TRANSACTION_DEAL_ADD && trans.order_state == ORDER_STATE_STARTED)
{
  PosOpenPrice = ?
}

i couldn't find the answer and as result i tried to call the history.

the information returned in trans is related to the final deal which is "buy out". but i need the information of price for "sell in" trade.

in above comment, it would be deal 25 or order 26 in history.


do you have anything in your mind?

 
ArashB :

Thanks again...


I'm using the same

i couldn't find the answer and as result i tried to call the history.

the information returned in trans is related to the final deal which is "buy out". but i need the information of price for "sell in" trade.

in above comment, it would be deal 25 or order 26 in history.


do you have anything in your mind?

I told you before - stop using the word 'order'. You have a confusion in your head because of this.

Formulate your question already, but only without the word 'order'. Do you want to catch the moment when the position is closed by the triggered Stop Loss?

 

Dear vlad,


I know what I'm talking about and it is not my mis perception on the different trades definitions. to get aligned you may see my definitions below :

  1. Position : is a trade which is already open and profit can be changed on each tick
  2. Order : is the pending orders which you may put by LIMIT and STOP
  3. Deal : is the action for opening and closing a position or trigger a pending order


the order which i mentioned is not pending order or so... over trade history if you change the view model to deals, you may see the same titles there.

It is the MT5 and MQ5 which is using this ORDER number and return these values on TradeTransaction as well.


Finally to answer your question and clear up the requirement in a sentence:

I'm looking for the OPEN_PRICE of the original Position which its SL hit at the moment.

Reason: