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

 
MrBrooklin #:

So how did this event handler find an open position after one trading day?

Regards, Vladimir.

Miracles do not happen. You made the logic. You should see why ... What did you look for in the handler when it was triggered? How did you search... And what exactly triggered it.

There is an event - the handler signals. In it you need to filter these events ...

But in general, I did not rely on these handlers. I controlled the difference between the past and the current state. And based on that. I made decisions about what to do.

 
Artyom Trishkin #:
Alexei answered. It depends on the broker.

Is this a statement or an assumption? I am not asking the question because I have nothing else to do. I want to understand.

Regards, Vladimir.

 
Artyom Trishkin #:
There are no miracles.

My first electronics mentor also said the same thing when he worked in the Regional Computer Service Centre (in the USSR times). I completely agree with him and with you. So there must be some logical explanation for the problem. And once in 8 months of trading the Expert Advisor on a real account. That's why I am trying to figure it out to eliminate any possibility of such a situation.

Regards, Vladimir.

 

I will try to use this variant of OnTradeTransaction() function in real life, so that the Expert Advisor always finds an open position. I have highlighted in yellow the part of the code that should exclude "falling out of sight" the fact of an open position:

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void  OnTradeTransaction(
   const MqlTradeTransaction&    trans,   // trade transaction structure
   const MqlTradeRequest&        request, // request structure
   const MqlTradeResult&         result   // response structure
)
  {
   if(trans.type==TRADE_TRANSACTION_DEAL_ADD)
     {
      if(HistoryDealSelect(trans.deal) && HistoryDealGetInteger(trans.deal,DEAL_ENTRY)==DEAL_ENTRY_IN)
        {
         pos_ticket=trans.position;
         pos_open=trans.price;
        }
     }
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void Open_Add_Position()
  {
//--- if a position with a medjik and ticket of the last open position is selected by the current symbol
   if((PositionSelectByTicket(pos_ticket) || PositionSelect(_Symbol)) &&
      PositionGetString(POSITION_SYMBOL)==_Symbol &&
      PositionGetInteger(POSITION_MAGIC)==Magic_Number)
     {
      ....... тогда выполняем определённые действия с целью открытия дополнительной позиции
     }
  }

It works fine in the tester, I will see how it behaves in real trading.

Regards, Vladimir.

 
MrBrooklin open position. I have highlighted in yellow the part of the code that should exclude the fact of an open position from "falling out of sight":

It works fine in the tester, I will see what will happen in real trading.

Regards, Vladimir.

Vladimir, there is no connection between these functions. Remove the OpTradeTransaction() function and the code will work exactly the same way.

If the strategy involves opening several positions and hadge account, this part of the code

if((PositionSelectByTicket(pos_ticket) || PositionSelect(_Symbol)) &&

can do a lot of damage.

 
Alexey Viktorov #:

Vladimir, there is no connection between these functions. Remove the OpTradeTransaction() function and the code will work exactly the same way.

If the strategy provides for opening several positions and hadge account, then this part of the code

can do a lot of damage.

Alexey, thank you for constantly prompting and helping me in improving the EA code. Now to the point. Yes, I have a hedge account and multiple positions can be opened. The connection between OpTradeTransaction() and the part of the code you suggest deleting is direct. In OpTradeTransaction() I get the position ticket and its opening price to use for opening additional position(s). Everything worked perfectly until now. The problem arose when the Expert Advisor did not "see" an open position once. I didn't notice it before and thought that the problem occurred only once, but after running it through history and looking at the printout in more detail, I realised that it happened more than once and not twice. I just didn't notice it before, but now I realised that the problem sometimes occurred when a position was moving from one trading session to another. I emphasise - sometimes. Why? I can't figure it out myself. My forex-dealer has a rollover between trading sessions. Maybe because of it, maybe not because of it. I don't know. I have a similar situation now, but I am still missing one condition to open an additional position. I want to test the new code and see if it will do any harm or not. I am not afraid to conduct an experiment, because it will not be worse and especially since I have already learnt to "solve" bad situations with my hands. I just stop the work of both robots and open a position at the price I need.

Regards, Vladimir.

 
MrBrooklin #:

Alexey, thank you for constantly prompting and helping me in improving the EA code. Now to the point. Yes, I have a hedge account and multiple positions can be opened. The connection between OpTradeTransaction() and the part of the code you suggest deleting is direct. In OpTradeTransaction() I get the position ticket and its opening price to use for opening additional position(s). Everything was working perfectly until now. The problem arose when the Expert Advisor did not "see" an open position once. I had not noticed it before and thought that the problem occurred only once, but after running it through the history and looking at the printout in more detail, I realised that it happened more than once and not twice. I just didn't notice it before, but now I realised that the problem sometimes occurred when a position was moving from one trading session to another. I emphasise - sometimes. Why? I can't figure it out myself. My forex-dealer has a rollover between trading sessions. Maybe because of it, maybe not because of it. I don't know. I have a similar situation now, but I am still missing one condition to open an additional position. I want to test the new code and see if it will do any harm or not. I am not afraid to conduct an experiment, because it will not be worse and especially since I have already learnt to "solve" bad situations with my hands. I just stop the work of both robots and open a position at the price I need by hand.

Regards, Vladimir.

The problem is that PositionSelect(_Symbol) does not necessarily select the last position. Therefore, if you have not received a position ticket in OnTradeTransaction(), you risk making a decision based on the wrong data.

 
Alexey Viktorov #:

The problem is that PositionSelect(_Symbol) does not necessarily select the last position. Therefore, if you don't get a position ticket in OnTradeTransaction(), you risk making a decision based on the wrong data.

Thanks for the hint. I'll give it some thought and see how it can hurt in real trading. I can't agree with the idea of abandoning the OnTradeTransaction() function yet. We need to thoroughly understand the problem and then make a final decision.

Regards, Vladimir.

 
MrBrooklin #:

Thanks for the tip. I'll give it some thought and see how it can hurt in real trading. I can't agree to abandon the OnTradeTransaction() function yet. I need to thoroughly understand the problem and then make a final decision.

Regards, Vladimir.

I did not say to refuse. But the benefits of using it in this way are nil.

 
Alexey Viktorov #:
Remove the OpTradeTransaction() function and the code will work exactly the same way

In my understanding, deleting a function is like refusing to use it. It doesn't matter who and how you say it, the main thing is to figure it out. : )

Regards, Vladimir.