Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 502
![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
The function goes through and selects the newest one by time, i.e. the last one
Next, we have a selected one, and we substitute it in the functioniBarShift(sym, tf, oot ,true);
The function returns the bar number by time. That's all.
Unfortunately I can't check it, but when I used it, it worked perfectly, as well as all functions published here by I. Kim
Writes error indicatingif( iOpen[0] != time_open )'iOpen' - undeclared identifie
I wrote something a little wrong, a little in the other direction of thought. Change iOpen[0] to Open[0]. Corrected. To put it simply though. When I open a bar, I remember the time of bar opening and no orders are already taken on this bar.
It is also written in the function description that
The selection of positions to be taken into account is set by external parameters:
It is also written in the function description that
The selection of positions to be taken into account is set by external parameters:
Enough. In the external parameters you can enter the values you need: MagicNumber, which positions you are looking for, if you want BUY(0) and SELL(1) - then write "-1".
I wrote something a little wrong, a little in the other direction of thought. Change iOpen[0] to Open[0]. Corrected. To put it simply though. When I open a bar, it will remember the time of bar opening and no orders will be opened on this bar.
a lot of orders are opened and it looks like the condition if(NumberOfBarOpenLastPos(Symbol(),0,-1,-1)>0) before the opening of a non-order is fulfilled since NumberOfBarOpenLastPos returns -1
a lot of orders are opened, and it seems that the condition if(NumberOfBarOpenLastPos(Symbol(),0,-1,-1)>0) is met before a non-order is opened, because NumberOfBarOpenLastPos returns -1
You are looking for orders, then you need to use the function in its full version, namely, with the ability to search by orders, not only by positions:
This is sufficient. In the external parameters you can enter the required values: Majik, what positions are looked for, maybe only BUY, if BUY(0) and SELL(1) are needed - then we write "-1".
when I start in the tester, there are no open orders, maybe that's why -1 is returned, which is why the condition if(NumberOfBarOpenLastPos(Symbol(),0,-1,-1)>0) does not hold?
When starting in the tester, there are no open orders, maybe that's why -1 is returned and therefore the condition if(NumberOfBarOpenLastPos(Symbol(),0,-1,-1)>0) is not met?
I will check it now.
You are looking for orders, then you need to use the function in its full version, namely with the ability to search by orders, not just by positions:
still returns -1
still returns -1
It works perfectly!
From two positions it has chosen the last one, which is on bar 11, as you can see in the screenshot:
Check code: