how to recode mql4 function that retrieves a historical order's profit

 

I have an mql4 function that retrieves the last historical order and then the profit of that last order.... I can't figure out how to do that in mql5.

 

In mql5, I can retrieve historical data on Orders and Deals. Orders are useless -- to the extent I can determine -- and it appears that any one order can generate multiple deals.  I can't retrieve historical positions, there is no api call that I can determine.  So, do I retrieve the most recent historical deal, pull the position id from it, gather all other historical deals, then sum all of their profits?   If so, please shoot me in the head b/c that's ridiculous

 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
nsqtr:

I have an mql4 function that retrieves the last historical order and then the profit of that last order.... I can't figure out how to do that in mql5.

 

In mql5, I can retrieve historical data on Orders and Deals. Orders are useless -- to the extent I can determine -- and it appears that any one order can generate multiple deals.  I can't retrieve historical positions, there is no api call that I can determine.  So, do I retrieve the most recent historical deal, pull the position id from it, gather all other historical deals, then sum all of their profits?   If so, please shoot me in the head b/c that's ridiculous

 

In MQL5 there is no "order's profit". So what are you trying to do exactly, retrieve the profit of last deal ? or the profit of the last position ?
 
nsqtr:

I have an mql4 function that retrieves the last historical order and then the profit of that last order.... I can't figure out how to do that in mql5.

 

In mql5, I can retrieve historical data on Orders and Deals. Orders are useless -- to the extent I can determine -- and it appears that any one order can generate multiple deals.  I can't retrieve historical positions, there is no api call that I can determine.  So, do I retrieve the most recent historical deal, pull the position id from it, gather all other historical deals, then sum all of their profits?   If so, please shoot me in the head b/c that's ridiculous

 

What about using this: OrderCalcProfit()  ?
 
RaptorUK:
What about using this: OrderCalcProfit()  ?
raptor, yep, looked at that, but OrderCalcProfit() requires a price_close, which I guess I could use Ask/Bid, based on Buy or Sell so it gets me a little closer to the mql4 functionality b/c it approximates the profit of my actual position. I was hoping to simply recover the mql4 functionality that i use.
 
nsqtr:
raptor, yep, looked at that, but OrderCalcProfit() requires a price_close, which I guess I could use Ask/Bid, based on Buy or Sell so it gets me a little closer to the mql4 functionality b/c it approximates the profit of my actual position. I was hoping to simply recover the mql4 functionality that i use.
Why not find the last deal then use HistoryDealGetDouble with DEAL_PROFIT ?
 
angevoyageur:
Why not find the last deal then use HistoryDealGetDouble with DEAL_PROFIT ?
any one Order can produce more than one Deal, so looking at just one Deal may not give me an accurate picture, if the multiple deals got farmed out to more than one market transaction partner.  Hence, my first supposition that I'd have to first identify the Position from the Position Id of the Order, then collect the Deals and aggregate the profits from the Deals, which is a PITA
 
nsqtr:
any one Order can produce more than one Deal, so looking at just one Deal may not give me an accurate picture, if the multiple deals got farmed out to more than one market transaction partner.  Hence, my first supposition that I'd have to first identify the Position from the Position Id of the Order, then collect the Deals and aggregate the profits from the Deals, which is a PITA
If it's for forex, I doubt you ever see more than 1 deal for 1 order. Anyway even in this case, what'is so hard to made a loop and add up profit from the deals, you can use HistorySelectByPosition for that purpose.
Documentation on MQL5: Trade Functions / HistorySelectByPosition
Documentation on MQL5: Trade Functions / HistorySelectByPosition
  • www.mql5.com
Trade Functions / HistorySelectByPosition - Documentation on MQL5
 
angevoyageur:
If it's for forex, I doubt you ever see more than 1 deal for 1 order. Anyway even in this case, what'is so hard to made a loop and add up profit from the deals, you can use HistorySelectByPosition for that purpose.
this is severely tardy response but, yes, I've already coded up the deal looping but that is pretty inefficient. Also, I don't think making an assumption that one Order produces one Deal, that's just risky. My EA is for Forex only.  I feel like I'm missing an important aspect of this new API b/c I'm finding that all of my code ignores Positions altogether
 
nsqtr:
this is severely tardy response but, yes, I've already coded up the deal looping but that is pretty inefficient. Also, I don't think making an assumption that one Order produces one Deal, that's just risky. My EA is for Forex only.  I feel like I'm missing an important aspect of this new API b/c I'm finding that all of my code ignores Positions altogether
Hi, I read the topic again, and I am thinking the issue is that you are trying to reproduce with mql5 what you did with mql4. Maybe if you give an example that would be more easy to help you.
Reason: