![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
I must have missed a topic like this. Where can I see the order check function from KimV?
It's for the 4th version but you may have a look at it, it may be useful. You can look through it on his site, in the "free libraries" section, the library for placing orders.
from a four will not work. I use
PositionSelect
Selects an open position for further manipulation. Returns true if the function completes successfully. Returns false if the function fails. To get the information about the error, call the GetLastError() function.
boolPositionSelect(
string symbol//tool name
);
Parameters
symbol
[Name of the financial instrument.
Returned value
Value of bool type.
Note
For each symbol, only one position can be opened at any given time, which is the result of one or several trades. Positions and active pending orders that are also displayed in the "Trade" tab of the "Toolbox" panel of the client terminal should not be mixed up.
The PositionSelect() function copies the data about the position to the program environment, and the subsequent calls PositionGetDouble(), PositionGetInteger() and PositionGetString() return the previously copied data. This means that the position itself may no longer exist (or it may have changed in volume, direction, etc.), but the data of this position can still be retrieved. In order to guarantee the acquisition of fresh position data, it is recommended to call the PositionSelect() function immediately before applying for them.
from a quadruplet will not work. I use PositionSelect to define the position
Are you analysing these situations in the prealternations of one tick or on different ticks?
OK, I'll proceed from the following:
A tick is a change in the price of an instrument. The frequency of such changes is unpredictable: from several ones per second to several ones per hour. Correspondingly, the OrderSend() and PositionSelect() functions must not depend on the ticks' activity. And since it is so, I think that we should check to avoid duplication of orders (and analyze the corresponding situations) without relation to the behavior (frequency) of ticks.
So I find it difficult to answer the question precisely :/.
That's not what I meant when I asked my question. The OnTick() event handler is triggered when the next tick arrives. Because of this, I'm rephrasing my question:
Do you analyze these situations within one OnTick() call or different ones?
Well I still can't get an answer on one tick do you execute OrderSend() and PositionSelect()?
I want to suggest you to do these queries not within one tick (triggering OnTick()), but on two ticks:
- on the first tick
i.e. if the request responds successfully, you set the flag of position opening to buy=true, and interrupt execution of OnTick() until the next tick (triggering of OnTick()) operator return.
- On the second tick - PositionSelect().
In this case you don't have duplication of position opening.
No guarantee that the position will already be opened on the next tick. Measure how much time it takes to open a position when setting an order manually,
I advise you to move the order execution control to OnTrade(), this event is generated only as a server response to a trade operation.
Although it is not very clear to me why there are 4 OnTrade() events per order ?
Well I still can't get an answer on one tick do you execute OrderSend() and PositionSelect()?
According to your terminology, it turns out that my OrderSend() and PositionSelect() functions are executed "within one tick".
...I want to suggest that these queries be executed not within a single tick (triggering of OnTick()), but within two ticks:
- on the first tick
i.e. if request replies successfully, you set flag to open position in buy=true, and interrupt execution of OnTick() until the next tick (triggering of OnTick()) operator return.
- On the second tick - PositionSelect().
In this variant you will not have duplicated positions opening.
A little earlier I wrote, that the execution of functions OrderSend() and PositionSelect() has nothing to do with coming/not coming of ticks. And I briefly explained why. Therefore, the check "on the second tick - PositionSelect()" should not save us from doubling of orders in every possible case.
Although it's not very clear to me why there are 4 OnTrade() events per order ?
There was an article about it in the past about OnTrade().
There is no guarantee that position will already be opened on the next tick...
Well I still can't get an answer on one tick do you execute OrderSend() and PositionSelect()?
I want to suggest you to do these queries not within one tick (triggering OnTick()), but on two ticks:
- on the first tick
i.e. if the request responds successfully, you set the flag of position opening to buy=true, and interrupt execution of OnTick() until the next tick (triggering of OnTick()) operator return.
- On the second tick - PositionSelect().
In this case you don't have duplication of position opening.
No - not in a tick. In the 1st second.
Here's a simplification:
so - if without a pause it will open 2 orders in a row. But I set it for 3 seconds - and I don't regret it )))) Still, it is the opening of the order.
Accounting for orders in MT5 is a whole science:Handling trade events in the Expert Advisor using the OnTrade() function
No pause will save you from reopening, a situation can always occur, in which the order will take 1 second longer to execute.
ps: And don't forget about magic.