OrderSend() questions - page 2

 
Yedelkin:
I must have missed a topic like this. Where can I see the order check function from KimV?
It's for 4, but you can check it out, it might come in handy. You can check it out on his website under: "free libraries", order placing library.
 
-Alexey-:
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.

 
sergey1294:

from a quadruplet will not work. I use PositionSelect to define the position

When using the PositionSelect() function, it is alarming that it "...returns false if the function fails". That is, false is returned if the PositionSelect() functionfails , not only if there is no position. In other words, the situation cannot be excluded if the OrderSend() function returns true, the PositionSelect() function returns false, and the position still opens.
 
papaklass:
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 :/.

 
papaklass:

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?

If after the arrival of a new tick(user event) it is necessary to send a trade request to the server, then the check of successful execution of this request is performed "within the processing" of the arrived tick (event). I.e., according to your terminology, "within a single call OnTick()". [and regardless of how many ticks (events) arrived (must have arrived) during this processing].
 
papaklass:

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 ?

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок - Документация по MQL5
 
papaklass:

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".

papaklass:

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

 
Urain:

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

Urain:

There is no guarantee that position will already be opened on the next tick...

That's about what I'm saying.
 
papaklass:

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.


void OnTimer()
{
  while(true)
  {
     zOrderSend (_Symbol,0.1,ORDER_TYPE_BUY);

     Sleep (1); 

   if (PositionSelect(_Symbol)==true) {break;} 
  }
}
 

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.

Reason: