Errors, bugs, questions - page 2796

 
Mihail Matkovskij:

Don't you have anything else to do on this forum, Alexey, other than twisting my posts to make them look like claims to the developers on my behalf...? I wonder what was the reason for such strange "enthusiasm" on your part? You'd rather help newbies with their questions in the appropriate threads, than do nonsense here...!

But still, you clearly wrote "bug". This indicates a reported flaw in the platform, not that you haven't read the documentation to its logical conclusion.

 
Artyom Trishkin:

But still, you clearly wrote "bug". This indicates a reported flaw in the platform, not that you haven't read the documentation to its logical conclusion.

Well, yes, I did. I read the note in ObjectDelete function's description, but didn't think it was the problem... Who can do that?...

But it's all going around in circles. To be more exact, it's going around in circles that I wrote it wrong or mixed up... But for some reason nobody said a word about how to solve this bug... Of course, except for suggested ObjectsDeleteAll function, for which I would have to redo the entire project, which I least want.

 
Mihail Matkovskij:

Yes, I got confused. I read the note in the description of the ObjectDelete function, but I didn't think it was the problem... Who doesn't?

It happens...

 

Mihail Matkovskij:

... Nobody said a word about how to solve this bug for some reason... Of course, except for the suggested ObjectsDeleteAll function, for which I would have to redo the entire project, which I least want.

Try to use a prefix for names of graphical objects - it's normal practice to identify your objects. Use the prefix to check for rubbish and remove it at the same time.

Adding the prefix to object names will require redoing the whole project?

Are you writing in procedural style? Well, it's not so hard to change functions of creating object names there, either.

 
Artyom Trishkin:

Try to use a prefix for names of graphical objects - it is normal practice to identify your objects. Use the prefix to check for rubbish and remove it at the same time.

Adding a prefix to object names will require redoing the whole project?

Ok, if there are no other options, I'll try.

Artyom Trishkin:

Are you writing in procedural style? It's not that hard to change the function that creates object names.

A Sisyphean task? :)


Thanks to Rashid Umarov for his help in finding the cause of my indicator bug!
 
Mihail Matkovskij:

Don't you have anything else to do on this forum, Alexey, other than twisting my posts to make them look like claims to the developers on my behalf...? I wonder what was the reason for such strange "enthusiasm" on your part? You'd rather help newbies with their questions in the appropriate threads than do nonsense here...!

That's what I'm trying to help you with. I'm trying to help you and explain what you're wrong about. Try another option for deleting graphical objects and everything will be fine. And all the bugs you were talking about will disappear. You don't have to twist your words and I'll quote you.

 
Alexey Viktorov:

That's what I'm trying to help you with. I am explaining to you what you are wrong about. Try another option to remove the graphic objects and everything will be fine. And all the bugs you were talking about will disappear. There's no need to twist your words, you said it, I quoted it.

I'm trying to help you and at the same time groundlessly accuse, don't forget to add. I asked what caused such manic enthusiasm, but for some reason you didn't answer me! Why are you evading the answer, Alexey?

 
Mihail Matkovskij:

I'm trying to help you and at the same time unapologetically accuse you, don't forget to add. I asked what prompted such manic enthusiasm, but for some reason you didn't answer me! Why are you evading an answer, Alexey?

You should have shut up a long time ago and I wouldn't have continued.

Here's my frank attempt to help without any hints of accusation.

This is the forum for trading, automated trading systems and testing of trading strategies

Mistakes, bugs, questions

Alexey Viktorov, 2020.07.11 17:12

How can it be that the loop lasts longer than the time required to execute OnDeinit?

After all, all objects in your example have the "trend" prefix why not use it and refuse the loop?

int  ObjectsDeleteAll(
   long           chart_id,   // идентификатор графика
   const string     prefix,   // префикс имени объекта
   int       sub_window=-1,   // индекс окна
   int      object_type=-1    // тип объекта для удаления
   );

What's the answer? Read your answers.
 
Alexey Viktorov:

You would have shut up a long time ago and I wouldn't have continued.

А... There's the reason for the accusations against me! I see... :)

Alexey Viktorov:
What's your response? Read your answers.

Everything is all right there. The only thing is that I initially refused to use this function. And it must have embarrassed you. Well, I'm sorry then... :)

 

Substituted the ObjectDeleteAll function first in your example:

//+------------------------------------------------------------------+
//|                                           DeleteChartObjects.mq5 |
//|                                      Copyright 2020, © Cyberdev. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, © Cyberdev."
#property version   "1.00"
#property indicator_chart_window

#property indicator_plots 0

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#include <ChartObjects\ChartObjectsLines.mqh>
#include <Arrays\ArrayObj.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//--- input parameters
input int      nBars = 100000;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int customN_Bars = 0;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CArrayObj listOfTrendLines;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
//--- indicator buffers mapping
  int totalBars = iBars(NULL, PERIOD_CURRENT);
  customN_Bars = (nBars < totalBars) ? nBars : totalBars;
//---
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]
) {
  CChartObjectTrend * trend;
  int delta = rates_total - customN_Bars;
  int shift;
  int i;
  for(i = 0; i < customN_Bars; i++) {
    shift = delta + customN_Bars - i - 1;
    trend = new CChartObjectTrend();
    if(trend.Create(0, "trend"+(string)i, 0, time[shift], low[shift], time[shift], high[shift]))
      listOfTrendLines.Add(trend);
    else
      delete trend;
  }
  return(rates_total);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
  
  ObjectsDeleteAll(0, "trend", 0, OBJ_TREND);
  
  CChartObjectTrend * trend;
  
  int i = listOfTrendLines.Total() - 1;
  for(; i >= 0; i--) {
    trend = dynamic_cast <CChartObjectTrend *> (listOfTrendLines.At(i));
    
    if(CheckPointer(trend) == POINTER_INVALID)
      continue;
    
    delete trend;
  }
}
//+------------------------------------------------------------------+

Then into the indicator.

Artyom Trishkin:

Adding a prefix to object names will require redoing the whole project?

It turned out that usingObjectDeleteAll in my project was easy. To delete all the objects, I just needed to change the prefix 3 times and call ObjectDeleteAll 3 times. The chart is clear as a result. The MQL5 language has a lot of subtleties. But at the same time it is a very well thought-out language.

Thanks to everyone who helped me in solving this problem!

Reason: