I might want to calculate the value of all closed positions within a given period.
It might look something like the above. It seems an incredibly expensive way to calculate for instance, the value of trades so far today if I had restarted an EA.
I say this because my understanding is that just about every operation on an order/position market/pending order involvers a deal. If you are running broker side trailing stop loss, there might be a lot of deals.
I haven't seen a state diagram showing the relationships & flows between deals, orders & positions.
So is there a better way of doing this? I can see I can use CHistoryOrderInfo in cahoots with HistorySelect() and I could check the state to see if it is in state ORDER_STATE_FILLED, but I still only have access to PriceOpen() & PriceCurrent(), and their meaning/content is not extensively described (IMHO).
What am I missing? is it the case that I just parse every deal as above?
Yours a little frustrated, ESB.
Have a look at looping through positions, orders, and deals in the following indicator (utility). The code can be readily copied into an EA, and you merely have to insert your desired times therein... and tally up your deal history accordingly. It's deals loop is substantially the same as your code, but this utility shows positions and orders code for purposes of contrasting with deals.
Show Positions on Custom Chart (or standard chart) for MT5
Ryan L Johnson, 2025.06.02 14:02
This indicator is a utility that shows labelled trade levels on any chart. If you want to replace your native trade levels on a native chart, then turn off "Show trade levels" in your F8 Chart Properties and attach this indicator. If you want to show trade levels on a Custom Chart (where native trade levels cannot be shown), then simply attach this indicator. BaseSymbol - specify the Symbol from which the trade level data will be pulled--handy for unique Custom Symbols. TextBarsBack - specify the number of bars back in history from the current bar where the level labels will be drawn. Note: Although magic number is referenced in the code, it is not presently included in the trade lines. If you're running multiple EA's on the same Symbol, you can edit the code to show magic numbers and then run multiple instances of the indicator on one chart. You can also edit the font sizes and text spacing in the object properties as needed for different display resolutions.And a brief description of positions, orders, and deals:
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I might want to calculate the value of all closed positions within a given period.
It might look something like the above. It seems an incredibly expensive way to calculate for instance, the value of trades so far today if I had restarted an EA.
I say this because my understanding is that just about every operation on an order/position market/pending order involvers a deal. If you are running broker side trailing stop loss, there might be a lot of deals.
I haven't seen a state diagram showing the relationships & flows between deals, orders & positions.
So is there a better way of doing this? I can see I can use CHistoryOrderInfo in cahoots with HistorySelect() and I could check the state to see if it is in state ORDER_STATE_FILLED, but I still only have access to PriceOpen() & PriceCurrent(), and their meaning/content is not extensively described (IMHO).
What am I missing? is it the case that I just parse every deal as above?
Yours a little frustrated, ESB.