![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
If you are talking about open trades, there is no single term to return the current price. Buys are valued at Bid and Sells are valued at Ask
If you are talking about open trades, there is no single term to return the current price. Buys are valued at Bid and Sells are valued at Ask
Aha, I got it now, thanks........brilliant little gem!
For a selected trade - OrderClosePrice() returns the current price for closing it (this is not necessarily the actual close price if OrderClose() is attempted, due to possible slippage/requotes/other errors...).
FYI, I've only recently realised that this isn't 100% true. For example, in the following code...
... price1 will always equal price2. The value of OrderClosePrice() doesn't get updated, and is out of date at the time of the second call. In other words, if you perform lengthy calculations between doing an OrderSelect() and then trying to use OrderClosePrice(), the price potentially becomes stale.
It turns out that OrderSelect() is doing something along the lines of copying the selected order details into a cache. Therefore, repeating the OrderSelect() updates the value of OrderClosePrice():
FYI, I've only recently realised that this isn't 100% true. For example, in the following code...
Yeah, I should have mentioned that, but that's a 'known' general property of OrderSelect()... Quoting myself (https://www.mql5.com/en/forum/124632):
To solve your problem it's important to understand how OrderSelect() works: when u select a ticket using OrderSelect() a buffer is filled with all order details (the ones u get when u call OrderTicket(), OrderCloseTime(), etc.). This buffer is NOT a dynamic buffer. The values in it will remain constant until the next time u call OrderSelect()!
For a selected trade - OrderClosePrice() returns the current price for closing it (this is not necessarily the actual close price if OrderClose() is attempted, due to possible slippage/requotes/other errors...).
From my very limited investigation...
I think that article is only meant for people who have to do things the MT4 way.
I'm not sure you're right about that. Such a VOM is indeed not the only way of establishing per-system positions, but the article makes the following claim:
2.3 More than one EA of any type per symbol per account
This presents the most complex trading and coding requirement, and is the reason for the development of the Virtual Order Manager (VOM) library. This library is intended to simplify greatly the development of robust EA code which is fully sociable with other EAs.
In other words, the article is claiming much wider applicability than just transition from MT4.
What are the alternative options for an MT5 EA which wants to play nicely with other EAs on the same symbol and account? Of the top of my head, there are only two: have the EA track its own current position by storing data on disk (...more backup issues); or have it download and scan the entire account order history to see which orders it's placed in the past, and what its current position therefore is. I've recently done some work with NinjaTrader for the first time in a couple of years, and my current feeling - albeit based on substantial ignorance - is that MT5 has regressed backwards past NinjaTrader in this crucial respect, because Ninja at least has a go at calculating pseudo-positions for each strategy rather than making the strategy itself jump through hoops to do its own calculation.