Dividing open positions into groups - page 12

 
Sergey Voytsekhovsky:
It seems to have worked. I have a minus print for every TakeProfit, and a plus print for every market entry. I am sorry for colloquial slang, but I am completely self-taught and have no one to communicate with on this topic.


And I'm self-taught. Anyway, I was cutting and cutting and cutting the code... If it wasn't for the dialogue with you, I would have found these problems a bit later...

I should add to the code a choice of deal before reading properties.

    HistoryDealSelect(trans.deal);

Or to check the success of the choice.

    if(!HistoryDealSelect(trans.deal))
      Print(GetLastError());
 
Alexey Viktorov:

And I'm self-taught. Anyway, I was cutting and cutting and cutting the code... If it wasn't for the dialogue with you I would have found these problems a bit later...

It's always good to talk, and you'll find out later if the conversation is useful or not. Thus, the most talkative people increase minPolus by averaging, but decrease maxPolus. That's a bit of a mouthful.

Надо добавить в код выбор сделки перед чтением свойств.

или с проверкой успешности выбора.

Are you thinking out loud or is that what you recommend me to do?

 

With the function

bool  HistoryDealSelect( 
   ulong  ticket     // тикет сделки 
   );

I've read one thing about it, but I don't know how to use it yet

Функция HistoryDealSelect() очищает в mql5-программе список сделок, доступных для обращений, и копирует в него одну единственную сделку, если выполнение HistoryDealSelect() завершилось успешно.
 

Next task - I invite the knowledgeable to discuss.

How to have a transaction ticket(closed a position on TR) to return a position ticket that was closed by this transaction?

2020.04.12 18:15:09.620 Core 1  2018.06.19 04:52:40   take profit triggered #6571  buy 0.01 EURUSD 1.16343 tp: 1.16389 [#6572  sell 0.01 EURUSD at 1.16389]
2020.04.12 18:15:09.620 Core 1  2018.06.19 04:52:40   deal #6572  sell 0.01 EURUSD at 1.16389 done (based on order #6572)
2020.04.12 18:15:09.620 Core 1  2018.06.19 04:52:40   deal performed [#6572  sell 0.01 EURUSD at 1.16389]
2020.04.12 18:15:09.620 Core 1  2018.06.19 04:52:40   order performed sell 0.01 at 1.16389 [#6572  sell 0.01 EURUSD at 1.16389]
2020.04.12 18:15:09.620 Core 1  2018.06.19 04:52:40   Закрыта позиция ---Тикет сделки--- 6572 ---Позицию в структуре ArrayDealOut пометить на удаление ------------

The thing is, I have a structure in which actual positions have to be stored. As they leave the game, they need to be cleaned up.

???

 
Sergey Voytsekhovsky:

At least it is useful to talk about something, and you will find out later if the conversation is useful or not. So the most talkative people increase the minPolus by averaging, but decrease the maxPolus. That's a bit of a mouthful.

Are you thinking out loud or is that what you recommend me to do?

Not just recommending it, but returning a recently deleted line in my code.

 
Sergey Voytsekhovsky:

With the function

You have to be careful, I've read a feature there, I don't know how to use it yet.

It depends on where you make the selection. There is no danger of that in OnTradeTransaction. In general, we should get into the habit of selecting it before accessing properties of an order, deal or position.

And do not forget that if after the selection the execution switches to some function and another selection is made in it, then upon return the list will contain the last selected option.

 
Sergey Voytsekhovsky:

Next task - I invite the knowledgeable to discuss.

How to have a transaction ticket(closed a position on TR) to return a position ticket that was closed by this transaction?

The thing is, I have a structure in which actual positions have to be stored. As they leave the game, they need to be cleaned up.

???

Well, it's quite simple...

/*********************TradeTransaction function**********************/
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
 {
  if(trans.type == TRADE_TRANSACTION_DEAL_ADD && trans.symbol == _Symbol)
   {
    if(!HistoryDealSelect(trans.deal))
      Print(GetLastError());
    /******************** Если открылась позиция********************/
    if(HistoryDealGetInteger(trans.deal, DEAL_ENTRY) == DEAL_ENTRY_IN)
      Print("********** открытие сделка ", trans.deal, " позиция ", trans.position);
    /******************** Если закрылась позиция********************/
    if(HistoryDealGetInteger(trans.deal, DEAL_ENTRY) == DEAL_ENTRY_OUT)
     {
      if(HistoryDealGetInteger(trans.deal, DEAL_REASON) == DEAL_REASON_TP)
       {
        Print("********** закрытие по тейку сделка ", trans.deal, " позиция ", trans.position);
       }
      if(HistoryDealGetInteger(trans.deal, DEAL_REASON) == DEAL_REASON_SL)
       {
        Print("********** закрытие по стопу сделка ", trans.deal, " позиция ", trans.position);
       }
     }
   }
 }/*******************************************************************/
CN      0       19:20:27.920    !00 (GBPUSD.m,H1)       2020.02.03 12:01:20   ********** закрытие по стопу сделка 27 позиция 26
CG      0       19:20:27.920    !00 (GBPUSD.m,H1)       2020.02.03 12:01:20   ********** открытие сделка 28 позиция 28
HJ      0       19:20:28.023    Trade   2020.02.03 12:01:40   stop loss triggered #28  buy 0.1 GBPUSD.m 1.30698 sl: 1.30598 tp: 1.30798 [#29  sell 0.1 GBPUSD.m at 1.30598]
GE      0       19:20:28.023    Trades  2020.02.03 12:01:40   deal #29  sell 0.1 GBPUSD.m at 1.30598 done (based on order #29)
 JF      0       19:20:28.023    Trade   2020.02.03 12:01:40   deal performed [#29  sell 0.1 GBPUSD.m at 1.30598]
CD      0       19:20:28.023    Trade   2020.02.03 12:01:40   order performed sell 0.1 at 1.30598 [#29  sell 0.1 GBPUSD.m at 1.30598]
GI      0       19:20:28.023    Trade   2020.02.03 12:01:40   market buy 0.1 GBPUSD.m sl: 1.30512 tp: 1.30712 (1.30598 / 1.30612 / 1.30598)
FQ      0       19:20:28.023    Trades  2020.02.03 12:01:40   deal #30  buy 0.1 GBPUSD.m at 1.30612 done (based on order #30)
 QQ      0       19:20:28.023    Trade   2020.02.03 12:01:40   deal performed [#30  buy 0.1 GBPUSD.m at 1.30612]
ON      0       19:20:28.023    Trade   2020.02.03 12:01:40   order performed buy 0.1 at 1.30612 [#30  buy 0.1 GBPUSD.m at 1.30612]
KR      0       19:20:28.025    !00 (GBPUSD.m,H1)       2020.02.03 12:01:40   CTrade::OrderSend: market buy 0.10 GBPUSD.m sl: 1.30512 tp: 1.30712 [done at 1.30612]
RM      0       19:20:28.025    !00 (GBPUSD.m,H1)       2020.02.03 12:01:40   ********** закрытие по стопу сделка 29 позиция 28
FP      0       19:20:28.025    !00 (GBPUSD.m,H1)       2020.02.03 12:01:40   ********** открытие сделка 30 позиция 30
NK      0       19:20:28.295    Trade   2020.02.03 12:02:39   take profit triggered #30  buy 0.1 GBPUSD.m 1.30612 sl: 1.30512 tp: 1.30712 [#31  sell 0.1 GBPUSD.m at 1.30712]
IS      0       19:20:28.295    Trades  2020.02.03 12:02:39   deal #31  sell 0.1 GBPUSD.m at 1.30712 done (based on order #31)
 NE      0       19:20:28.295    Trade   2020.02.03 12:02:39   deal performed [#31  sell 0.1 GBPUSD.m at 1.30712]
KI      0       19:20:28.295    Trade   2020.02.03 12:02:39   order performed sell 0.1 at 1.30712 [#31  sell 0.1 GBPUSD.m at 1.30712]
IH      0       19:20:28.295    Trade   2020.02.03 12:02:39   market buy 0.1 GBPUSD.m sl: 1.30626 tp: 1.30826 (1.30712 / 1.30726 / 1.30712)
EI      0       19:20:28.295    Trades  2020.02.03 12:02:39   deal #32  buy 0.1 GBPUSD.m at 1.30726 done (based on order #32)
 LR      0       19:20:28.295    Trade   2020.02.03 12:02:39   deal performed [#32  buy 0.1 GBPUSD.m at 1.30726]
RL      0       19:20:28.295    Trade   2020.02.03 12:02:39   order performed buy 0.1 at 1.30726 [#32  buy 0.1 GBPUSD.m at 1.30726]
HR      0       19:20:28.297    !00 (GBPUSD.m,H1)       2020.02.03 12:02:39   CTrade::OrderSend: market buy 0.10 GBPUSD.m sl: 1.30626 tp: 1.30826 [done at 1.30726]
HS      0       19:20:32.663    !00 (GBPUSD.m,H1)       2020.02.03 12:02:39   ********** закрытие по тейку сделка 31 позиция 30
KP      0       19:20:32.663    !00 (GBPUSD.m,H1)       2020.02.03 12:02:39   ********** открытие сделка 32 позиция 32
 
Alexey Viktorov:

It depends on where you make the selection. There is no risk of that in OnTradeTransaction. In fact, we should get into the habit of selecting it before accessing properties of an order, deal or position.

And do not forget that if after the selection the execution goes to some function and it makes another choice, then on return in the list will be that which was selected last.

Man, how to comprehend all this is beyond abstraction for me.

I've just solved the above-mentioned problem with searching for a ticket of a position closed by a known trade - and I immediately requested it from the print, so I went right back to where I started - not all TakeProfits show up in the print.

 
Alexey Viktorov:

It's as simple as that...

My God, you've had "my precious" all this time and you've been so modestly silent???

Thank you very much.

I've learned a lot. I could have just reposted it, that's all.

 
Sergey Voytsekhovsky:

Oh my God, you've had "my precious" all this time and you've been so modestly silent???

Thank you very much.

I learned a lot, but I would have just reposted it and that was it.

Nothing happened. I just wrote it to check and ran it through debugger on historical data. Learn to use the debugger. It's a very useful skill.

I started programming in Excell in so-called VBA (visual VBA for applications) and got to know debugging there. After that it was hard for me to get used to printers to check received values... And when they introduced debugging in mql5 I was as happy as a child that my suffering was over.