No, the last record of trading activity is in the second log.
And this is correct in terms of priority:
2021.05.0510:32:35.896 Trades '160122203': market buy 0.01 EURUSD placed for execution
2021.05.0510:32:35.931 Trades '160122203': order #2249869869 buy 0.01 / 0.01 EURUSD at market done in81.962 ms
2021.05.0510:32:35.931 Trades '160122203': deal #2240398230 buy 0.01 EURUSD at 1.19876 done (based on order #2249869869)
2021.05.0510:32:35.931 Trades '160122203': market sell 0.01 EURUSD, close #2249869868 buy 0.01 EURUSD 1.198762021.05.0510:32:35.978 Trades '160122203': accepted market sell 0.01 EURUSD, close #2249869868 buy 0.01 EURUSD 1.198762021.05.0510:32:35.978 Trades '160122203': market sell 0.01 EURUSD, close #2249869868 buy 0.01 EURUSD 1.19876 placed for execution
2021.05.0510:32:36.009 Trades '160122203': order #2249869870 sell 0.01 / 0.01 EURUSD at market done in77.026 ms
2021.05.0510:32:36.009 Trades '160122203': deal #2240398231 sell 0.01 EURUSD at 1.19876 done (based on order #2249869870)
2021.05.0510:32:36.009 Scripts script Test (EURUSD,M1) removed
Here I have reverted to the option without prints and again there is one position left after execution. It turns out that you need to hold some kind of pause after the trades are executed. Man, what a crutch.
Added prints. Now two positions remain, as expected:
Result:
Add Trade.ResultRetcodeDescription()
#include <Trade\Trade.mqh>
voidOnStart()
{
CTrade Trade;
while (!IsStopped() && (PositionsTotal() <= 1)) // Закончим, когда появится более одной позиции.if (PositionsTotal() == 1)
{
Trade.PositionClose(PositionGetTicket(0)); // Если есть позиция - закрываем.Print("Закрытие, т. к. PositionsTotal() равно 1");
}
elseif (!OrdersTotal())
{
printf("Перед открытием. PositionsTotal: %d, OrdersTotal: %d", PositionsTotal(), OrdersTotal());
Trade.Buy(0.01); // Если нет позиции и ордера - открываем позицию.Print(Trade.ResultRetcodeDescription());printf("После открытия. PositionsTotal: %d, OrdersTotal: %d", PositionsTotal(), OrdersTotal());
}
Print("Выход. PostionsTotal: ", PositionsTotal());
}
#define PRINT(A) Print(#A + " = " + (string)(A))
#include <Trade\Trade.mqh>
voidOnStart()
{
CTrade Trade;
while (!IsStopped() && (PositionsTotal() <= 1)) // Закончим, когда появится более одной позиции.if (PositionsTotal() == 1)
{
Trade.PositionClose(PositionGetTicket(0)); // Если есть позиция - закрываем.Print("Закрытие, т. к. PositionsTotal() равно 1");
}
elseif (!OrdersTotal())
{
printf("Перед открытием. PositionsTotal: %d, OrdersTotal: %d", PositionsTotal(), OrdersTotal());
Trade.Buy(0.01); // Если нет позиции и ордера - открываем позицию.
PRINT(Trade.ResultRetcodeDescription());
PRINT(Trade.ResultDeal());
PRINT(Trade.ResultOrder());
PRINT(Trade.ResultComment());
printf("После открытия. PositionsTotal: %d, OrdersTotal: %d", PositionsTotal(), OrdersTotal());
}
Print("Выход. PostionsTotal: ", PositionsTotal());
}
Result:
2021.05.0511:36:14.566 Test (EURUSD,M1) Перед открытием. PositionsTotal: 0, OrdersTotal: 02021.05.0511:36:14.646 Test (EURUSD,M1) Trade.ResultRetcodeDescription() = done at 0.000002021.05.0511:36:14.646 Test (EURUSD,M1) Trade.ResultDeal() = 02021.05.0511:36:14.646 Test (EURUSD,M1) Trade.ResultOrder() = 22498746452021.05.0511:36:14.646 Test (EURUSD,M1) Trade.ResultComment() = Request executed
2021.05.0511:36:14.646 Test (EURUSD,M1) После открытия. PositionsTotal: 2, OrdersTotal: 12021.05.0511:36:14.646 Test (EURUSD,M1) Выход. PostionsTotal: 2
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
No, the last record of trading activity is in the second log.
And this is correct in terms of priority:
Here I have reverted to the option without prints and again there is one position left after execution. It turns out that you need to hold some kind of pause after the trades are executed. Man, what a crutch.
Well, who's going to update it? ))
but when there is an open position - the script closes it and does not do anything else
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
also if i try to open a position the script closes it instantly
managed to write IsSynchronized(). The code is a bit heavy. I haven't decided yet in what form to post it.
How does it work? It is sort of found but sort of absent? What is the gist or principle of the solution?
But when there is an open position, the script closes it and does nothing else.
Not all servers will reproduce the opening of two positions. In your case, it is the third side (one side - two positions, the other - one position).
And that's about right in terms of sequencing:
Forum on trading, automated trading systems and trading strategy testing
The Great and Powerful MT4 Forever (or how to choose migration strategy)
Ihor Herasko, 2021.05.05 09:35
And it's all right here in terms of ordering:
The highlighted lines confirm the sequence.
PositionsTotal = 1 - sends an order to close.
The closing takes place after the script execution is completed. Print-cache is a bit distorted.
How so? It's sort of found but sort of not there?
I haven't gotten around to posting it yet. I will post it within 24 hours.
What is the essence or principle of the solution?
It analyzes the correspondence of the trading history to the current trading environment. In this case, there are no slows.
It also checks Result.order.
As a result, the use is as follows: IsSync() returns false - the trading environment in the Terminal is crooked, otherwise we can proceed as usual.
Added prints. Now two positions remain, as expected:
Result:
Add Trade.ResultRetcodeDescription()
Also ResultDeal / ResultOrder / ResultComment and Order.State
Surely there will be an answer there
StateAdd Trade.ResultRetcodeDescription()
And also ResultDeal / ResultOrder / ResultComment and Order.State
Surely there will be an answer there
StateDone:
Result:
Add Trade.ResultRetcodeDescription()
And also ResultDeal / ResultOrder / ResultComment and Order.State
Surely there will be an answer there.
StateThis is definitely not the case as the condition for sending a market order to open a position is PositionsTotal == OrdersTotal == 0.