OnTradeTransaction processing - page 5

 
fxsaber:

Cretin.

I thought you meant you.

What happened to"He'll figure it out if he wants to."?

 
fxsaber:

It's easier for me to reply in one post than to make dozens with "recommendations".

If he wants to, he'll figure it out.

I used to want to... But your code is something else.
 
Alexey Viktorov:
Once upon a time I wanted to... But your code is something out of this world.

In this case you only need a little knowledge of MT4/5.

 
fxsaber:

In this case you only need a little knowledge of MT4/5.

Unfortunately I know little more than a little.

I've told you once before, you stick your code in and out like a butt plug in every barrel. Those who need it have been using it for a long time and some even advertise it. But to impose it where it is not very necessary is simply indecent. Especially when a person wants to understand and get into programming in mql5, not through tricks.

 
Alexey Viktorov:

Unfortunately I know little more than a little.

I've already told you once, you stick your code in every barrel for business and for no reason at all. Those who need it have been using it for a long time and some even advertise it. But to impose it where it is not very necessary is simply indecent. Especially when a person wants to understand and get into programming in mql5, not through tricks.

Forum on trading, automated trading systems and trading strategy testing

OnTradeTransaction processing

fxsaber, 2019.02.08 13:24

Show me the solution to the branch author's problem.

You see, when you make some assertions, it's a good idea to back them up somehow in practice. In a few pages no OnTradeTransaction solution has appeared. And if there is, it will quickly become clear why the given solution is the way it is and not the other way around. The solution should show the logic, not the hell out of it. If I remove the plug-in, the source code will not lose one bit in its logic. And you only need to understand the logic (idea), nothing more.

I agree with this statement. Once the logic is understood, goes throw out all the includes and create their own. This is exactly the way it's proposed: to master not an inlude, but to show by code and not scare off how the task whose solution is required can work.

 

Here I go back to the source of the problem. And the questions arise:

Forum on trading, automated trading systems and trading strategy testing

OnTradeTransaction processing

Ilya Child, 2019.02.07 20:08

Good evening.

Guys, please help to sort this out. The problem is probably not new, but I haven't found any unambiguous solution (neither in practice, nor on forums).

I am running 2 different robots in the terminal on 2 different instruments. The magics are different everywhere. The robot places pending limits and the procedure OnTradeTransaction allows me to detect a transaction and place pending stop orders using this transaction.

Below is the code for the trade transaction

case TRADE_TRANSACTION_DEAL_ADD:
        {
         drop_info2("TRADE_TRANSACTION_DEAL_ADD\r\n"+TransactionDescription(trans));
         if((trans.deal_type==DEAL_TYPE_BUY || trans.deal_type==DEAL_TYPE_SELL) && trans.order!=0)
           {
            if(getIsDealOfExpert(trans.deal)) //функция проверки принадлежности сделки к роботу
              {
               drop_info2("Сделка наша");
               analyzeFilledOrder(trans.order,trans.volume); //процедура по выставлению отложенных стоп ордеров
              }
           }
        }
      break;

This is the code of the function that checks whether the deal belongs to a robot

bool getIsDealOfExpert(ulong dealTicket)
     {
      if(HistoryDealSelect(dealTicket) && HistoryDealGetInteger(dealTicket,DEAL_MAGIC)==magic_number && HistoryDealGetString(dealTicket,DEAL_SYMBOL)==symbol)
         return true;
      else
         return false;
     }

This is the code of the procedure for pending stop orders

void analyzeFilledOrder(ulong orderTicket,double volume)
  {
   bool isFindOrder=false;
   string fullComment;
   ENUM_ORDER_TYPE orderType;
   if(getIsOrderOfExpert(orderTicket,true)) //Если ордер из сделки уже в истории
     {
      fullComment=HistoryOrderGetString(orderTicket,ORDER_COMMENT);
      orderType=ENUM_ORDER_TYPE(HistoryOrderGetInteger(orderTicket,ORDER_TYPE));
      isFindOrder=true; //локальная переменная, если нашли в истории
     }
   if(!isFindOrder && getIsOrderOfExpert(orderTicket,false)) //Если не нашли ордер в истории и ордер есть не в истории
     {
      fullComment=OrderGetString(ORDER_COMMENT); 
      orderType=ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE));
      isFindOrder=true; //локальная переменная, если нашли не в истории
     }
   if(isFindOrder) //если хоть где-то нашли, то выставляем отложенные стоп ордера
     {
     //выставляем стоп ордера

This is the code of the function for searching for an order in the history and out of the history

bool getIsOrderOfExpert(ulong OrderTicket,bool isHistory)
     {
      bool is_expert=false;
      //если ордер находится в истории
      if(isHistory)
        {
         if(HistoryOrderSelect(OrderTicket) && HistoryOrderGetInteger(OrderTicket,ORDER_MAGIC)==magic_number && HistoryOrderGetString(OrderTicket,ORDER_SYMBOL)==symbol)
            is_expert=true;
        }
      else
        {
         if(OrderSelect(OrderTicket) && OrderGetInteger(ORDER_MAGIC)==magic_number && OrderGetString(ORDER_SYMBOL)==symbol)
            is_expert=true;
        }
      return is_expert;
     }

I would output the information about the incoming transactions in the log files in the order they are received in the terminal. Now I have a problem that I have faced when trading on a demo account:

Sometimes transactions come in the following order TRADE_TRANSACTION_ORDER_DELETE, then TRADE_TRANSACTION_DEAL_ADD, then TRADE_TRANSACTION_HISTORY_ADD. In this case stop orders are often not placed after a trade has been executed. I suppose this happens because the order has already been deleted but has not yet been added to the history. It means that we cannot find the order from the deal either in the history or in the terminal. Although it is doubtful, the fact is that no stop order is placed because the robot does not find it after searching for the order in all dimensions(isFindOrder=false). The order of transactions may be correct, but the order is still nowhere to be found. In all cases, the robot detects the transaction correctly, but does not get to placing orders.However, it also occasionally works correctly and orders are placed.

I have tried different approaches, nothing works. I am now thinking of adding a 1-second interval at the beginning of pending order placing procedure. I do not know where else to dig.

Please share your experiences and ideas.

How can I reconcile the highlighted with the following phrase:

Forum on trading, automated trading systems, and strategy testing

OnTradeTransaction processing

Ilya Child, 2019.02.07 20:20

I forgot to add that the mode is netting. The position is the same for all robots. That is, one robot bought a position, the second bought it, TRADE_TRANSACTION_DEAL_ADD events came in reverse order and eventually the first robot did not see it.

Yes and I logically need to get a comment on the order from the trade, the position is not of much help here.

Let's not pay attention to the typo, one bought the other bought... The main thing is that it seems that two EAs work on one symbol with netting account type... Or maybe I don't understand something?

 
Alexey Viktorov:

Let's not pay attention to the typo, one bought the other bought... The main thing is that it looks as if two EAs are working on the same instrument with the account type netting... Or maybe I do not understand something?

It's normal to have several EAs on one netting symbol. For example, the netting ones. So it's quite possible that the netting position is zero, but there are two SL and two TP. The problem is clearly formulated above.

 
fxsaber:

Multiple EAs are the norm on a single netting symbol. For example, netting advisors. So it is quite possible that the netting position is zero, but there are two SLs and two TPs. The problem is clearly formulated above.

We can guess anything we like. I'd like to hear the "Transport Chief". After all, I quoted his posts.

 
Alexey Viktorov:

We can make up all we want. I'd like to hear from the transport manager. I was quoting him.

I think the boss has been so "intimidated" that he won't show up again :)

 
Илья Ребенок:

I don't quite follow you. Here is my transaction processing

About the status of the order in the transaction. You do realise that I'm not making this up myself. In all deal_add transactions this is the status of the order. Please note that it is a market order and it used to be a pending order.

Now we have another portion of incomprehension. A deal_add transaction flew in and no position appeared and pending on a non-existent position was placed.

Added.

The Deal_add transaction is sent, but the position has not been placed and a pending order for the non-existing position has been placed. The deal type is Sell, order type is Buy. Although initially the limit was Sell_limit

Apparently, either the old info isn't cleared somewhere, or uninitialized info is taken.

If I have a deal_add, the order is usually already in the history, or has already been deleted, but has not yet appeared in the history.

Although it also happens that the order is still there, and then it is in the placed state.

But it can hardly be at this time.

Check where an order or story is selected that they _are_ actually selected.