'Point' only and always returning '0.0001' for some unknown reason. - page 3

 

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

 
kennyhubbard:

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

See my answer in this thread -> https://www.mql5.com/en/forum/125907/page2#320301.
 

Aha, I got it now, thanks........brilliant little gem!

 
gordon:
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...

OrderSelect(<whatever>);
double price1 = OrderClosePrice();
Sleep(5000);
double price2 = OrderClosePrice();

... 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():

OrderSelect(<whatever>);
double price1 = OrderClosePrice();
Sleep(5000);
OrderSelect(<whatever>);   // Repeat the order selection
double price2 = OrderClosePrice();


 
jjc:

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):

gordon:
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()!
So obviously this should be taken into consideration when used.
 
gordon:
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...).
I KNOW there is a single term for it as I utilized it in previous EAs after someone posted the info here in answer to my query about finding out /getting the current price of an open trade.
 
I was right about being wrong if you get my drift.
 
jjc:

From my very limited investigation...

From my own very limited investigation, I think that article is only meant for people who have to do things the MT4 way. It's a way to get around the new position system... But I'm pretty sure eventually everybody will use the native tools to manipulate the position; the old MT4 'orders' paradigm will slowly disappear into oblivion...
 
gordon:
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.

Reason: