Errors, bugs, questions - page 742

 
TheXpert:
So make a factory. That would solve the problem.

It's easy enough to work in there as it is. The object is quite rigidly structured. It calls a virtual Load method of each of its members, they in turn do the same. At the beginning of each data block (object) the ID of type is written (for control when loading). That's all there is to it. It is a kind of a self-made factory.

It makes sense to make a factory if previously unknown type can be in the file. Then the factory and type register table will be needed. While the problem was not so solved, I have managed with paper clips and adhesive tape. :)

 

Gunn's fan.

If the second anchor point is in the future, the angle changes.

Also, this object has some problems with copying (with Ctrl pressed). Very often it doesn't copy, but drags the original, and it takes the third or fifth tries to copy.

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Способы привязки объектов
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Способы привязки объектов
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы объектов / Способы привязки объектов - Документация по MQL5
 
MetaDriver:

OK, great.

Slava, can I ask (for general development) why you can't initialize virtual method table at the beginning of constructor (after ancestor initialization)?

I've already told you. Constructors work in a hierarchy. While an ancestor is being constructed, there is no information about descendants.
 
stringo:
I've told you before. Constructors work out the hierarchy. While an ancestor is being built, there is no information about descendants.

I've already read it. And I understood it very well. And I asked a question based on my understanding of what I've read. I'll try to make it clearer, with pictures.

class MySecond: MyFirst
{
  void  MySecond(MyArg arg): 
    MyFirst(arg)
   { // Можно код инициализации VMT добавлять здесь. Тогда не будет проблем с виртуальными вызовами.
     ...............
     MyVirtualFunc();
      ...........
     return;
   } // Сейчас код инициализации VMT добавляется здесь.

};

I understand everything, it is more difficult to do, there are all sorts of subtleties. It's much easier and versatile (for you) to write all the implicit initialization at the end. And I even believe beforehand that "no one does that" and that "it's not customary in C++" etc.

But for us ( users ), it is simpler, more universal, reasonable and logical to consider MySecond() constructor as a territory of MySecond class and not MyFirst. Think about what's easier: making virtual functions work in constructors or expressing important and serious restrictions on constructor code in documentation in several places, and, despite that, regularly receiving important and serious messages from newbies to Service Desk and the Forum "about the virtual bugs in constructors". This is also a serious factor - newbies are expected a lot soon...

 
struct SDaylyRange {double min, max, open, close;};
void OnStart()
  {
//---
   SDaylyRange tmp, tmp2;
   tmp = 2+3 ? tmp : tmp2;
   if (2+3) tmp = tmp; else tmp = tmp2;
  }

The tensor operator with structures leads to Code Generation Error (although if you replace it with if, it works)

 

I get error 4401 regularly

ERR_HISTORY_NOT_FOUND

The following indicator code

datetime prevTime[22];
MqlRates _Rates[];

bool IsNewBar(ENUM_TIMEFRAMES period) {
   datetime currentTime[1];
   CopyTime(Symbol(), period, 0, 1, currentTime);
   int _;
   switch (period) {
      case PERIOD_M1  : _= 1;
         break;
      case PERIOD_M2  : _= 2;
         break;
      case PERIOD_M3  : _= 3;
         break;
      case PERIOD_M4  : _= 4;
         break;
      case PERIOD_M5  : _= 5;
         break;
      case PERIOD_M6  : _= 6;
         break;
      case PERIOD_M10 : _= 7;
         break;
      case PERIOD_M12 : _= 8;
         break;
      case PERIOD_M15 : _= 9;
         break;
      case PERIOD_M20 : _= 10;
         break;
      case PERIOD_M30 : _= 11;
         break;
      case PERIOD_H1  : _= 12;
         break;
      case PERIOD_H2  : _= 13;
         break;
      case PERIOD_H3  : _= 14;
         break;
      case PERIOD_H4  : _= 15;
         break;
      case PERIOD_H6  : _= 16;
         break;
      case PERIOD_H8  : _= 17;
         break;
      case PERIOD_H12 : _= 18;
         break;
      case PERIOD_D1  : _= 19;
         break;
      case PERIOD_W1  : _= 20;
         break;
      case PERIOD_MN1 : _= 21;
         break;  
      default         : _= 0;    
   } 
   if(currentTime[0]== prevTime[_]) return(false);
   else {
      prevTime[_] = currentTime[0];
      return(true);
   }
}

int OnInit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[]) 
if (IsNewBar(_Period)) {
    int err = CopyRates(Symbol(), PERIOD_D1, 0, 2, _Rates);
   Print("Count:", err);
   if (err < 1) {
       Print("ERROR:", GetLastError());
       Print("__Symbol:", Symbol());
       return(rates_total);
   }

}
return(rates_total); 
}

will produce an error immediately on startup (if not on D1). Or rather, once after the start of the terminal and opening of the chart - to put the indicator on, we will get an error. If the terminal is not closed, then there will not be such an error at start.

But after some time (a couple of hours - 2 hours were enough for me) we will see that we will get the error on the already open chart. (I ran it on m30)

 

Hello, gentlemen developers!

Can we make changes in the MQL5 compiler to at least give us a warning?

for errors of this kind in the code.

if(Flag_Exitl=true) {break;}


The comparison condition here is not correct (it should be == ), that's why it will always be break.

How to address this situation in the compiler (if it's possible at all), so that I could get less bumpy when writing code?

(I thought it won't work, it seems to separate assignment and comparison in if, then the question is removed).

 
Fia:

Hello, gentlemen developers!

Is it possible to change the MQL5 compiler to at least give a warning?

for errors of this kind in the code.

if(Flag_Exitl=true) {break;}


The comparison condition is not correct (it should be == ), that's why it will always be break.

How to address this situation in the compiler (if at all possible), so that I could get less bumpy when writing code?

(I've thought it won't work, I may split assignment and comparison in if, so the question is removed).

The condition may be written incorrectly but it is allowed in MQL5.

I will translate what you have coded: Flag_Exitl variable must be set to true and then checked if Flag_Exitl is true, then break.

The sequence of actions is exactly like this.

 

I don't quite understand how to work with buffers that don't need to be shown on the screen.

According to the code below for some reason

1) does not draw anything

2) both buffers are called Label1

although they contain the right data

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   2

//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_color1  clrRed, clrWhite
#property indicator_type1   DRAW_COLOR_LINE

//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_color2  clrRed, clrGreen
#property indicator_type2   DRAW_COLOR_LINE

//--- indicator buffers
double         L1_1[];
double         L2_1[];
double         Colors_1[];

//--- indicator buffers
double         L1_2[];
double         L2_2[];
double         Colors_2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0,L1_1,INDICATOR_DATA);
   SetIndexBuffer(1,L1_2,INDICATOR_DATA);
   SetIndexBuffer(2, Colors_1,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(3, Colors_2,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4, L2_1, INDICATOR_CALCULATIONS);
   SetIndexBuffer(5, L2_2, INDICATOR_CALCULATIONS);
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[])
{
   for (int i = 0; i < rates_total; i++)
   {
      L1_1[i] = i;
      L1_2[i] = i + 1;
   }
   return(rates_total);
}
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования - Документация по MQL5
 

Hello. I may be writing in the wrong direction, but I hope you can point me in the right direction. Where to go with a question on Web API for mt5? )

I will try to explain the situation just in case. I have МТ manager and WEB API with php... Invoice in russian is created, data is sent and even is displayed in МТ manager, but there is a problem - data in МТ manager is displayed in unicode ("044404300c0438043b0438044f" - that's how user name looks like). When sending data nothing is encoded or decoded, from MT client everything is created normally... At least which way to look? (

Reason: