Discussing the article: "Trade transactions. Request and response structures, description and logging" - page 5

 
Alexey Viktorov #:

Volodya, you and I have talked a lot about this voice. I explained everything as best I could, and you seemed to understand everything, but here we go again....

The OnTradeTransaction function is an event processing function. The transaction is an event that happened yesterday. The OnTradeTransaction function should have worked yesterday, but not today. Today there is no event of THIS transaction... Today there were and probably still will be, but different ones.

I've become very old. I'm already in my seventh decade. I forget a lot of things, and I practice from case to case! ))

It turns out that we don't need a transaction for today, we just loop through it:

   for(int i=0; i<PositionsTotal(); i++)
     {
      if(PositionGetTicket(i))
         Print(PositionGetInteger(POSITION_IDENTIFIER));
     }

and voila! Here is an open position. Is it like that? ))

Regards, Vladimir.

 
Artyom Trishkin #:

The data is stored on the server. The terminal receives them into its environment and the Expert Advisor then uses them.

Artem, good morning! Today I got up early and looked into the terminal, and there I see that at the beginning of a new trading session the Expert Advisor with the code I showed you earlier in my message"suddenly saw" the position opened the day before yesterday and worked with it as it should according to the algorithm. It's just some kind of miracles! I decided to run the Expert Advisor in the strategy tester for the day before yesterday and yesterday. In the strategy tester, the Expert Advisor worked just perfectly - it found the position opened the day before yesterday and worked with it yesterday, as if it were written in the notes. I would like to draw your attention to this fact!!! In the strategy tester the position opened the day before yesterday, the Expert Advisor found it yesterday and further on....

In the strategy tester it turns out to be one thing, but in real trading it is quite different. And yesterday this situation happened for the first time, when the Expert Advisor did not want to "see" an open position out of the blue.

Question - how can this be?

Regards, Vladimir.

 
MrBrooklin #:

Artem, good morning! Today I got up early and looked into the terminal, and there I see that at the beginning of a new trading session, the Expert Advisor with the code I showed you earlier in my message"suddenly saw" the position opened the day before yesterday and worked with it as it should according to the algorithm. It's just some kind of miracles! I decided to run the Expert Advisor in the strategy tester for the day before yesterday and yesterday. In the strategy tester, the Expert Advisor worked just perfectly - it found the position opened the day before yesterday and worked with it yesterday, as if it were written in the notes. I would like to draw your attention to this fact!!! In the strategy tester the position opened the day before yesterday, the Expert Advisor found it yesterday and further on....

Question - how can this be?

Regards, Vladimir.

I don't know. This is your code. You wrote it. It works as it is written.

 
Artyom Trishkin #:

I don't know. It's your code. You wrote it. The way it's written, the way it works.

I understand about the code. It is very simple. Artem, I edited my previous message a bit, please look at it. I added some more information. Maybe it will help you to understand it somehow.

Regards, Vladimir.

Also added: for 8 months of trading on a live account, yesterday for the first time the Expert Advisor did not "see" an open position. This is what knocked me out of my rut.

 
MrBrooklin #:

I understand about the code. It is the simplest. Artem, I edited my previous post a bit, please have a look at it. I added some more information. Maybe it will help to understand it somehow.

Regards, Vladimir.

Also added: for 8 months of trading on a live account, yesterday for the first time the Expert Advisor did not "see" an open position. This is what knocked me out of my rut.

Stress tests for such a case are necessary, take the fork out of the computer immediately after changing the trading environment, cut off the internet or make it super slow, so that the lack of internet is not fixed, and trade orders are practically not sent.... or something else to think of such a non-staff. The real trading environment and its fixation even with a small number of trade transactions can give unpredictable failures)))))

Artem's articles in the first have about it, how to record and how to monitor the real)))))

Saber has a cooler approach in general, it creates a virtual copy of the trading environment and counts everything there))))

 
Valeriy Yastremskiy #:
Stress tests for such a case are necessary, take the plug out of the computer immediately after changing the trading environment, cut off the internet or make it super slow, so that the lack of internet is not fixed, and trade orders are practically not sent.... or something else to think of such a non-standard.

Good morning, Valery! Everything that was listed in your message, all this happened repeatedly, and even repeatedly, during all eight months of trading on the real account. At the same time, the EA saw the position the next day and the day after that. The code of the OnTradeTransaction() function worked correctly during all eight months of real trading.

I have no explanation for what happened, but the only thing that comes to mind is a server failure on the forex-dealer's side. If you carefully read all my posts on this topic, you will see such a message:

Forum on trading, automated trading systems and testing trading strategies

Discussion of the article "Trading Transactions. Request and response structures, description and log output"

MrBrooklin, 2023.10.18 04:48 PM

Artem, good morning! Today I got up early and looked into the terminal, and there I see that at the beginning of a new trading session the Expert Advisor with the code that I showed you earlier in my message"suddenly saw" the position opened the day before yesterday and worked with it as it should according to the algorithm. It's just some kind of miracles! I decided to run the Expert Advisor in the strategy tester for the day before yesterday and yesterday. In the strategy tester, the Expert Advisor worked just perfectly - it found the position opened the day before yesterday and worked with it yesterday, as if it were written in the notes. I would like to draw your attention to this fact!!! In the strategy tester the position opened the day before yesterday, the Expert Advisor found it yesterday and further on....

In the strategy tester it turns out to be one thing, but in real trading it is quite different. And yesterday this situation happened for the first time, when the Expert Advisor did not want to "see" an open position out of the blue.

Question - how can this be?

Regards, Vladimir.

Regards, Vladimir.
 
Due to the fact that the TradeTransaction event can be missed for some reason, and also because it is possible to have a "race" state (for example, when an order is no longer active but not yet in history, or there is no active order but not yet an open position), I have a robot that stores all active orders and its total position (netting) in its state. The state is reset to a file at each change and at the end of work. At startup and periodically during operation, synchronisation is checked and, if necessary, the state is synchronised.
 
JRandomTrader #:
I have a robot that stores all active orders and its total position (netting) in its state. The state is reset to a file at each change and at the end of work. At startup and periodically during operation, synchronisation is checked and the state is synchronised if necessary.

Thank you for sharing an interesting solution to this problem. I will try to implement it in my EA.

Regards, Vladimir.

 
MrBrooklin #:

Thank you for sharing an interesting solution to a similar problem. I will try to implement it in my EA.

Regards, Vladimir.

It can be not only a failure, and what is a failure))))) Fixing the state of the trading environment is not exactly a simple task. And when one order on one instrument, it is not even believed that it is necessary. But in a good way, it is necessary.

In the tester the ideal execution, in real life it is almost ideal, but at times it is not ideal and even inadequate.

Therefore, in real life we need to solve the problem somehow, so that the Expert Advisor understands what is going on with the orders. And if it is clear with orders, it's more complicated with orders. At each tick or less frequently check the order status, or look at the price, if suddenly it became more or less than the price of the order to check the order status. )))

 

Good morning, Artyom! Is there a fundamental difference for the OnTradeTransaction() function where it should be located - before the OnTick() function or after it? If it is fundamental, why?

Regards, Vladimir.