Typical mistakes and how to deal with them when dealing with the trading environment - page 3
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 right option using a simple example
I think it is better if the order has not yet been accounted for in the position, just wait for it to be accounted for.
I don't get the idea.
This diagram shows that when a market order is placed using OrderSendAsync in MetaQuotes-Demo, it is impossible to reliably catch the corresponding order being placed until the order is either executed or rejected. I.e. there are no simple mechanisms in MT5 for evaluating intermediate results of their OrderSendAsync.
seems to be in theme,
I would like to point out that this code :
works flawlessly on the DEMO (result=request),
but on REAL - it's impossible to get a result (result=0.0). ... Unless you wait a few seconds.
Seems to be in the subject,
I would like to point out that such code :
On DEMO it works flawlessly (result=request),
but on REAL - it's impossible to get result (result=0.0). ... Unless you wait a few seconds.
Data is missing - logs, structure field values after OrderSend, trade server name.
The point in a nutshell is this: if there is a market order, consider it a 'position' as well. In inverted commas because it is a wrapped position. The highlighted code usually does not appear anywhere. But it avoids re-opening positions. The most interesting thing here is highlighted in red. The need for this chip is not immediately apparent.
There may not be a trade signal on the next tick. I use MT4-style myself, so I can't help but see such "positions" without getting in trouble.
Data is missing - logs, structure field values after OrderSend, trade server name.
2018.02.20 15:20:35.845 Trades order #66745055 buy 0.01 / 0.01 EURUSDeur at market done in 610.625 ms
2018.02.20 15:20:35.935 Trades deal #5461453 buy 0.01 EURUSDeur at 1.23403 done (based on order #66745055)
2018.02.20 15:20:35.845 TestBUY (EURUSDeur,M15) retcode=10009 deal=0 order=66745055
If the request is met (10009) , why deal=0
If the request is done (10009) , why deal=0
That's almost where the discussion started. The links have all the details.
There is a solution for OrderSend to work perfectly, but that would be advertising.
The right option using a simple example
The point in a nutshell is this: if there is a market order, consider it a "position" as well. In quotes, because it's a wrapped position. The highlighted code usually doesn't appear anywhere. But it avoids re-opening positions. The most interesting thing here is highlighted in red. The need for this chip is not immediately apparent.
The matter is that there are so-called closing market orders. The same SL/TP. Obviously, we would not like to see such market orders as "positions". And we would not like to see those orders that we have placed to close as well. So the highlighted condition is the appropriate filter.
for (int i = OrdersTotal() - 1; i >= 0; i--) if (OrderGetTicket(i) && (OrderGetInteger(ORDER_TYPE) <= ORDER_TYPE_SELL) && !OrderGetInteger(ORDER_POSITION_ID) && (OrderGetString(ORDER_SYMBOL) == Symb)) Res++;
SZY Insert this code here and check the result on the demo server.
I invite all interested to discuss this question. My opinion on this matter is as follows:
for (int i = OrdersTotal() - 1; i >= 0; i--) if (OrderGetTicket(i) && (OrderGetInteger(ORDER_TYPE) <= ORDER_TYPE_SELL) && !OrderGetInteger(ORDER_POSITION_ID) && (OrderGetString(ORDER_SYMBOL) == Symb)) Res++;
This loop adds one position if an order is found that does not have a position identifier (the ID is zero).
We have returned one more position.
What if the order is cancelled by the server?
...
I think that when calculating market orders, we should return WRONG_VALUE, for example, if we have found one - positions cannot be less than zero. This will be a signal that there is an unrecorded market order. But not to add the number of positions.