Discussion of article "Implementing a Scalping Market Depth Using the CGraphic Library" - page 3

 
Konstantin Seredkin:

Don't the words I wrote in my question mean anything?

Your example

This code is published by the author of the topic in the description of the class https://www.mql5.com/en/articles/3336.

So this question should not be addressed to me at least...

These words don't mean anything to me except one thing - you haven't studied the code of the example.

you give an example of deletion through

m_book_market.SetMarketBookSymbol(Symbol())

If we open this method, we will see there a subscription to the passed ticker.

bool CMarketDepth::SetMarketBookSymbol(string symbol) {
   m_sell_deals = 0;
   m_buy_deals  = 0;
   ArrayResize(market_book, 0);
   m_available = false;
   m_best_ask_index = -1;
   m_best_bid_index = -1;
   m_depth_total = 0;

   bool _selelect = SymbolSelect(symbol, true);
   if(_selelect)
      m_symbol = symbol;
   else {
      if(!SymbolSelect(m_symbol, true) && SymbolSelect(Symbol(),true))
         m_symbol = Symbol();
   }

   if(_selelect)
      if(!MarketBookAdd(m_symbol))
         printf("%s - %d: [ %s ] can't open the glass!!!", __FUNCTION__, __LINE__, m_symbol);

   this.Refresh();
//---
   return _selelect;
}

but not subscription deletion )) subscription deletion is done through a function:

MarketBookRelease

Обеспечивает закрытие стакана цен по указанному инструменту, а также отменяет подписку на получение извещений об изменении указанного стакана.

bool  MarketBookRelease(
   string  symbol      // character name
   );

Параметры

symbol

[in]  Имя символа.

Возвращаемое значение

Значение true в случае успешного закрытия, иначе false.

Примечание

Обычно эта функция должна вызываться из функции OnDeinit() в том случае, если в функции OnInit() была вызвана соответствующая функция MarketBookAdd(). Либо должна вызываться из деструктора класса, если в конструкторе этого класса вызывается соответствующая функция MarketBookAdd().
 
TheXpert:

Must be copypasta. It happens. The author probably wrote this code partially in the browser.

Instead of

CMarketBook MarketBook.mqh

write

CMarketBook MarketBook;

it was a trick question for your namesake )) he doesn't like to read code, but waits for a ready answer ))

 
Konstantin:

it was a trick question for my namesake )) he doesn't like to read code, but waits for a ready answer ))

That's exactly what I always do, and initially I made the removal of the glass as it should be, as in your example, which is actually required when working with the glass from the help.

But when I use this method,

if(!MarketBookRelease(Symbol()))
   {
   if(Debug){Print("Error MarketBookRelease ",m_symbol.Name());}}

I get this error


P|S figured out what the problem is, it turns out that if this method is used in the class constructor, it is not necessary to use it in OnDeinit.


I withdraw my question, you can give me a candy.

 
Konstantin Seredkin:

If you don't use a destructor in a class

This construct works normally

But maybe I just don't know how to use the destructor, or maybe it is implemented in a crooked way and therefore doesn't work as it should.

The subscription function is broadcast, it is guaranteed to delete all subscriptions in OnDeinit, if you have too many objects in your code and there are delays in their deletion, there may not be enough time allocated for OnDeinit processing, which means that some objects will not be deleted.

Here you can either look for a problem in the code, which is more correct, because there is obviously a problem and it will shoot you in the foot one day, or just delete them in OnDeinit and forget about it.

ps.

Konstantin Seredkin:

That's what I always do.

you obviously didn't parse the example, or you've slipped a crooked code from the beginning, like, take it apart and I'll have a laugh ))

With such an object CMarketBook MarketBook.mqh compiler would compile the code? Well, you created an object MarketBook.mqh, the compiler missed this sacrilege, but you are working with an object MarketBook, you would have an error at the stage OnInit, because you did not have such an object.I paid attention to it at once because the example is obviously not working, so I asked you a question, but you dutifully blamed everything on the class developer and his example....

either provide a working code example where this error is reproduced or explain everything at once without unnecessary codes as you have done now, you will save your time, too.

Использование аналитических объектов - Графики котировок, технический и фундаментальный анализ - MetaTrader 5
Использование аналитических объектов - Графики котировок, технический и фундаментальный анализ - MetaTrader 5
  • www.metatrader5.com
Определение трендов, построение каналов, выявление циклов и уровней поддержки/сопротивления — все эти и многие другие задачи решаются при помощи аналитических объектов. Всего в торговой платформе доступно 46 таких инструментов. Среди них имеются геометрические фигуры, различные каналы, инструменты Ганна, Фибоначчи, Эллиотта и многое другое. В...
 
Konstantin:

The subscription function is broadcast, it is guaranteed to delete all subscriptions in OnDeinit, if you have too many objects in your code and there are delays in their deletion, there may not be enough time allocated for OnDeinit processing, which means that some objects will not be deleted.

Here you can either look for a problem in the code, which is more correct, because there is obviously a problem and it will shoot you in the foot one day, or just delete them in OnDeinit and forget about it.

ps.

you obviously didn't parse the example, or slipped in a crooked code from the beginning, as if you want me to make fun of it )).

With such an object CMarketBook MarketBook.mqh compiler would compile the code? Well, you created an object MarketBook.mqh, the compiler missed this sacrilege, but you are working with the object MarketBook, you would have an error at the stage OnInit, because you have not created such an object, I immediately gave it to you.I paid attention to it at once because the example is obviously not working, so I asked you a question, but you dutifully dumped everything on the developer of the class....

You should either provide a working code example where this error is reproduced or explain everything at once without unnecessary codes as you have done now, you will save your time, too.

You are just in your repertoire, I don't care what the author has done in the example, what misprints he has made, you need to be a complete idiot not to realise that it is just a misprint.

The question was completely different.

In his example there is initialisation - call of the glass, then there is its updating through the Refresh() method, but there is no its deletion through the

MarketBookRelease

//+------------------------------------------------------------------+
//|MarketBook.mq5 |
//| Copyright 2017, MetaQuotes Software Corp. | |
//|http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
#include "GlobalMarketBook.mqh"
#include "MBookBtn.mqh"
#include "EventNewTick.mqh"

CMBookBtn MButton;
CEventNewTick EventNewTick;
double fake_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
  {
   MarketBook.SetMarketBookSymbol(Symbol());
//--- indicator buffers mapping
   SetIndexBuffer(0,fake_buffer,INDICATOR_CALCULATIONS);
// In case the user has changed the chart on which the panel is running,
// you need to hide and then reopen the panel. 
   MButton.Hide();
   MButton.Show();
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| MarketBook change event|
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {
   if(symbol!=MarketBook.GetMarketBookSymbol())
      return;
   MarketBook.Refresh();
   MButton.Refresh();
   ChartRedraw();
  }
//+------------------------------------------------------------------+
//| Chart events|
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // event identifier 
                  const long& lparam,   // event parameter of long type
                  const double& dparam, // event parameter of double type
                  const string& sparam  // event parameter of type string
                  )
  {
   MButton.Event(id,lparam,dparam,sparam);
   ChartRedraw();
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Deinit|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   MButton.Hide();
   if(!MarketBookRelease(Symbol()))
   {
   Print("Error MarketBookRelease ",Symbol());}
  }
//+------------------------------------------------------------------+

OnDeinit or implementation of the same, but in the class destructor.

That's why I asked the author a question, how it is more correct in his opinion to kill the glass using his class because this work is missing in the main example and in the class itself and it would be good to implement it before, I'm not saying that there is something bad, etc. just this point is missing it seems to me.

The question was asked to the author and normally formulated, why ask and discuss my questions and demagogue for several pages about what I read, what I want to get from anyone, etc. I myself am able to understand everything in my code, which is exactly what I did.... The question was quite different.

Above in the code I added in yellow colour what in my opinion should be present in the attached indicator.

 
Konstantin Seredkin:

You're just in your repertoire, I don't care what the author did in the example, what misprints he made, you have to be a complete idiot not to realise that it's just a typo.

The question was completely different.

In his example, there is initialisation - call of the glass, then there is its updating through the Refresh() method, but there is no its deletion through the

OnDeinit or implementation of the same, but in the class destructor.

That's why I asked the author a question, how it is more correct in his opinion to kill the glass using his class because this work is missing in his main example and in the class itself and it would be good to implement it before, I'm not saying that there is something bad, etc. just this point is missing it seems to me.

The question was asked to the author and normally formulated, why ask and discuss my questions and demagogy for several pages about what I read, what I want to get from someone, etc. I myself am able to understand everything in my code, which is actually done... the question was completely different

Above in the code added in yellow colour what in my opinion should be present in the attached indicator.

there are no telepaths here, the example you gave in the original question does not reproduce the problem you are writing about, besides, all the mechanisms are present in the class, the solution is given to you, but I don't see anything but reproaches, the dispute is closed.

 
Konstantin:

There are no telepaths here, the example you gave in your original question does not reproduce the problem you are writing about, besides, all the mechanisms are present in the class, the solution is given to you, but I don't see anything but reproaches, the dispute is closed.

- Firstly, there was no problem at all in my question.

- Secondly, I didn't reproach anyone for anything, I just asked a simple question to the author to clarify my guesses... and from you in every message some ridiculous accusations and questions about the code, in my direction, which I didn't write at all, but took from the article description of the class as an example.

The help says:

Destructor is a special function that is called automatically when an object of a class is destroyed. The name of the destructor is written as the class name with a tilde (~). Strings, dynamic arrays and objects that require deinitialisation will be deinitialised anyway, regardless of the presence of a destructor. If a destructor is present, these actions will be performed after the destructor is called.

There is no destructor in the class that would close the price glass by the method

MarketBookRelease

Also in the indicator itself in

void OnDeinit(const int reason)

also it is not present, I was asked a simple question - How to correctly make the de-initialisation of the glass.

I expected an answer to this question,

- don't invent anything, the class itself will close everything, even if there is no destructor declared in it.

- Add

void OnDeinit(const int reason)
  {
   if(!MarketBookRelease(Symbol()))
   {Print("Error MarketBookRelease ",Symbol());}
  }

Or add a destructor to the class itself.

public:
    ~CMarketBook(void);
//--
//--

CMarketBook::~CMarketBook(void)
{
   if(!MarketBookRelease(m_symbol)){
   printf(__FUNCTION__ + "Error MarketBookRelease ",m_symbol);} 
}

And you'll be happy... and you started a dimagogy accusing me of some misprints in someone else's code, that it won't compile, which I know without you, that I can't read something there.... in Russian you signed me up as a deer.

 
Perfect ! Great  Perfect ! Great job!
 
MetaQuotes Software Corp.:

New article Implementing a Scalping Market Depth Using the CGraphic Library has been published:

Author: Vasiliy Sokolov

Thank you.  This is a great tool.  Very easy to modify.

 
The whole code, when I copy and paste it to compile, gives an error when compiling. Does anyone know of a solution?