Subscription to OnBookEvent sometimes falls off - is there such a thing? - page 11

 
Stanislav Korotky:

Yeah, and in response to that, you first claimed for a long time that there was no problem, then you started offering different solutions, but they don't work in the general case. You are doing a disservice to people by claiming to have provided a solution. There is no need for an apology. It would be better to get to the bottom of it from now on.

But you need to apologize, because you didn't read anything and I wrote:

"I ran these indicators in different windows of the same symbol and it worked fine,

but when I ran both indicators in one symbol window ,it really

subscription "fell off" when one indicator was removed.

Write to the SD (maybe they will have time to make a fix in the new build)"

Added

Please, Stanislav, don't continue this polemics, don't want to apologize - don't.

 
Slava:

Subscription increases the counter by 1.

Unsubscribe decreases the counter by 1.

If your EA needs tumblr events, he should not depend on other EAs that someone will enable him to subscribe. He should subscribe himself in OnInit. And in OnDeinit - unsubscribe

What you have written - everyone does.

But the problem is that if 2 subscriptions have been called in one window, when one subscription is deleted - the other (second) one is deleted.

 
prostotrader:

What you wrote - everyone does.

But the problem is that if a subscription has been called 2 times in one window, then deleting one subscription deletes the other (the second).

No. It shouldn't be like that. 2 subscriptions - 2 AddRef. 1 unsubscribe - 1 Release. As a result, the counter is 1.

Subscription is destroyed only after the counter becomes 0

 
prostotrader:
But the problem is that if 2 subscriptions have been called in one window, then when one subscription is deleted, the other (second) one is deleted.

In other words, there is expert/expert counter (but only one expert can be on ONE chart), but there is no expert/indicator counter or indicator/indicator counter

 
A100:
In other words, there is an expert/expert counter, but no expert/indicator counter

There can only be one expert in one window.

 
prostotrader:

There can only be one assessor in one window.

Exactly right... between windows/charts counts... but inside - NO

 
Slava:

No, it shouldn't be like that. 2 Subscriptions - 2 AddRef. 1 unsubscribe - 1 Release. As a result, the counter is 1.

Subscription is destroyed only after the counter becomes 0

This thread has the code for the indicators, run them in the same window on the same symbol (forts) and you will see for yourself

Added

Checking takes 2 minutes

1 indicator

//+------------------------------------------------------------------+
//|                                                   Test_ind_1.mq5 |
//|                                      Copyright 2018 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
#define  on_call -111
#property indicator_separate_window
bool is_book = false;
double Buff[];
int event_cnt =0;
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Test_1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrAqua
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- Set buffers 
   IndicatorSetInteger(INDICATOR_DIGITS,0);
   IndicatorSetString(INDICATOR_SHORTNAME,"Test_ind_1");
//---Set buffers
   SetIndexBuffer(0,Buff,INDICATOR_DATA);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   ArraySetAsSeries(Buff,true); 
   is_book = MarketBookAdd(Symbol());
   if(is_book == true)
    { 
      Print(__FUNCTION__, ": Подписка на стакан добавлена. Символ ", Symbol());
    }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
    if(is_book == true)
    { 
      MarketBookRelease(Symbol());
      Print(__FUNCTION__, ": Подписка на стакан удалена. Символ ", Symbol());
    }  
  }  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
    if(prev_calculated == 0)
    {
      ArrayInitialize(Buff, EMPTY_VALUE);
    }
   Buff[0] = 2;
//--- return value of prev_calculated for next call
   event_cnt = rates_total;
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {
   if(symbol == Symbol())
   {
     Print(__FUNCTION__, ": Подписка работает. Символ ", symbol);
      double price[];
      OnCalculate(event_cnt,event_cnt,on_call,price);
   }
   
  }  
//+------------------------------------------------------------------+

2 indicator

//+------------------------------------------------------------------+
//|                                                   Test_ind_1.mq5 |
//|                                      Copyright 2018 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
#define  on_call -111
#property indicator_separate_window
bool is_book = false;
double Buff[];
int event_cnt =0;
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Test_2"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- Set buffers 
   IndicatorSetInteger(INDICATOR_DIGITS,0);
   IndicatorSetString(INDICATOR_SHORTNAME,"Test_ind_2");
//---Set buffers
   SetIndexBuffer(0,Buff,INDICATOR_DATA);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   ArraySetAsSeries(Buff,true); 
   is_book = MarketBookAdd(Symbol());
   if(is_book == true)
    { 
      Print(__FUNCTION__, ": Подписка 2 на стакан добавлена. Символ ", Symbol());
    }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
    if(is_book == true)
    { 
      MarketBookRelease(Symbol());
      Print(__FUNCTION__, ": Подписка 2 на стакан удалена. Символ ", Symbol());
    }  
  }  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
    if(prev_calculated == 0)
    {
      ArrayInitialize(Buff, EMPTY_VALUE);
    }
   Buff[0] = 2;
//--- return value of prev_calculated for next call
   event_cnt = rates_total;
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {
   if(symbol == Symbol())
   {
     Print(__FUNCTION__, ": Подписка 2 работает. Символ ", symbol);
      double price[];
      OnCalculate(event_cnt,event_cnt,on_call,price);
   }
   
  }  
//+------------------------------------------------------------------+
 

I understand the problem.

Not ready to answer yet

 
Slava:

I understand the problem.

Not ready to answer yet

Thanks, very much looking forward to solving it!

 
prostotrader:

But you, on the other hand, need to apologise, because it's you who doesn't read anything, and I wrote:

"I ran these indicators in different windows of the same symbol and it works fine,

but when I ran both indicators in one symbol window ,it really

subscription "fell off" when one indicator was removed.

Write to the SD (maybe they will have time to make a fix in the new build)"

Added

Please, Stanislav, do not continue this argument, do not want to apologize - do not.

You started it, you should finish it. I have nothing to apologize for. I wrote everything to the point, unlike you.

I've seen all your posts. You quoted only what was relevant to you and just ignored what was before that, as if you didn't write it. Indeed from the een time you managed to reproduce the problem. And in general, you came to this thread with your problem, which has nothing to do with the topic.

Reason: