Errors, bugs, questions - page 2722

 
A100:

In principle, there should be no such a case - the issue should have been solved at the compiler level (as in C++). And in this case it's kind of possible and as a consequence, the discussion on several pages

Definitely a bug... But it must be! )))

imho, constant expressions must be known at compile time and static expressions must be known during initialization of the application in the description sequence.

and this scheme in MQL, where there's a kind of constant control, but I can assign constants myself at runtime, and I can use a function call as an initialization, like this

struct A
{
   const double a;
   A():a(AccountInfoDouble(ACCOUNT_BALANCE))
   {
      Print("a = ", a); // a = 9999.290000000001
   }
};
//+------------------------------------------------------------------+
void OnStart()
{
   A a1;
}
//+------------------------------------------------------------------+

and this "constant" could be in the local visibility of.... at what point does it become a constant expression and how does it help.... i don't know, i don't understand it without manuals, there is no description of memory model - there is no point in it, well, at most, use as it should be - initialize with constant in all constructors, then the compiler will help warning if you accidentally decide to modify this field in the future

 
Igor Makanu:
But this scheme in MQL, where there is kind of control over constants, but I can assign constants in random mode myself

How many times can you shame yourself with basic ignorance of the basics of C++?

 

this example is confusing at all:

struct A
{
   const double a;
   A():a(SymbolInfoDouble(_Symbol,SYMBOL_ASK))
   {
      Print("a = ", a);
   }
};
void OnTick()
  {
   const A a;
  }
//+------------------------------------------------------------------+

2020.04.23 21:40:04.474 tst (EURUSD,H1) a = 1.07892

2020.04.23 21:40:04.546 tst (EURUSD,H1) a = 1.07893

2020.04.23 21:40:04.585 tst (EURUSD,H1) a = 1.07893

2020.04.23 21:40:05.254 tst (EURUSD,H1) a = 1.07893

2020.04.23 21:40:05.305 tst (EURUSD,H1) a = 1.07893

2020.04.23 21:40:05.306 tst (EURUSD,H1) a = 1.07892

 
Stanislav Korotky :

There are two programs working on the same file at the same time. The one that writes uses the flags FILE_READ|FILE_WRITE|FILE_BIN|FILE_SHARE_READ. The one that reads - FILE_READ|FILE_BIN|FILE_SHARE_WRITE|FILE_SHARE_READ. Although the first program periodically saves the file with FileFlush, the second program only sees the length of the file when it is opened. Tried doing FileSeek back and forth - doesn't help.

Question: how do I make the program that reads the file pick up the data that is being rewritten?

This seems to be a bug, it was reported some time ago on the English forum. I didn't have time to report it here.

Don't the developers read the English forum?

 
Stanislav Korotky:

There are two programs working on the same file at the same time. The one that writes uses theFILE_READ|FILE_WRITE|FILE_BIN|FILE_SHARE_READ flags. The one that reads - FILE_READ|FILE_BIN|FILE_SHARE_WRITE|FILE_SHARE_READ. Although the first program periodically saves the file with FileFlush, the second program only sees the length of the file when it is opened. Tried doing FileSeek back and forth - doesn't help.

Question: how do I make the program that reads the file pick up the data to be overwritten?

Are the two programmes in the same terminal or in two different ones?

 

Object methods from an object array passed by reference do not work.

Example:

//+------------------------------------------------------------------+
//| Пример: добавленный метод для расширения файла ..\Include\String\String.mqh
//|--
//| Получает из указанной строки подстроки по заданному разделителю 
//| и возвращает количество полученных объектов-подстрок
//|         НЕ РАБОТАЕТ !!!!!!!!!!
//+------------------------------------------------------------------+
int CString::Split(const string separator,      // разделитель
                   CString      &result[] )     // массив строковых объектов
  {
   string tmp_result[];               

   if(StringLen(separator)==0) return(0);

   ushort u_sep=StringGetCharacter(separator,0); 
   
   int count=StringSplit(m_string,u_sep,tmp_result);

   // временно для проверки
   result[0].Assign("Buy"); // НЕ РАБОТАЕТ !!!!!!
   Alert("ressult[0] = ",result[0].Str()); // <--- уже не отрабатывает
   // конец временно
   
   /*
   for(int i=0;i<count;i++)
     {
      result[i].Assign(tmp_result[i]); // НЕ РАБОТАЕТ !!!!!
     };
   */
   
   return(count);
  }
//+------------------------------------------------------------------+
 
Slava:

Are these two programs in the same terminal or in two different ones?

In one terminal. Expert writes the data, the indicator reads the data. Hanging on different charts, but obviously could be on the same one (if that matters). Bild 2380.

 

VS2019

#include <iostream>

int x;

struct A 
{
    const int a;
    A() :a(x) {}
};
int main()
{
    std::cout << "x = ";
    std::cin >> x;
    const A a;
    std::cout << "a.a = " << a.a;
}

x = 12345

a.a = 12345

hmm, everything works like in MQL5

OK, I take it back, it won't compile in Sharp

 
Vict:

Well, you've also got a constructor. It's up to you, of course, but structures are C entities, the model there is different - passive entities with external logic (functions).

Not necessarily. Why C? What about C#? - All talks about passive structures are archaic notions, imho. I believe that at least every type must have a constructor. Uninitialized fields are an evil, which must be avoided.

In your case, you need to make a factory method to create an array of structures, i.e. something like this:

struct A
{
  const int a;
  A(int init_value) : a(init_value) { }

  static bool CreateArray(A &array[], int count, int init_value)
  {
    //...
  }
};

And there already one of the previously suggested ways to fill array elements.

 

I have run into the following problem. The indicator draws candles

It is plotted on the chart. There is also an Expert Advisor that reads buffers of the indicator

So I logged and skimmed the stages and found out that the indicator often draws candles with a delay.

It means that several ticks ago (up to a couple of minutes exactly) it has already calculated and updated the buffers and the Expert Advisor is reading data from them

(both owls and the indicator write it in the log). But we see the old picture on the chart. For example, this screenshot is made at the moment when the red bar has broken through the low of the previous one. But on the chart we see only the previous red one and underdrawn green one (it is by fact bigger by two bars).


And here is the actual picture, it was drawn later. We see the breakdown, it initiated the capture of the screenshot. According to the logs everything is clear.



Who will tell me what is the matter and how to speed up chart refresh? I callChartRedraw function from the EA but it still has a couple of minutes delay.

Two minutes is a bit much, I can't even imagine the reason. Calculations are not so cosmic to slow down so much.