Errors, bugs, questions - page 436

 
Interesting:

1. Why is that? Harmful symptoms need to be treated, and decisively.

2. Variables, arrays and other things should not be named consistently or with language keywords (but the array "Symbol" is very striking, you can not tell if it's an array or something else in code).

1. Well, first you have to really establish whether the symptomology belongs to positive or negative manifestations. In my experience, there have been cases where I tried to change the value of a global variable in a function that wasn't supposed to do that (damned copypaste). It took me a few days to find this error. Since then, I have been using global variables in cases when I cannot do without them in principle.

2. I agree. But if they are used within one function, it doesn't bother me. But global variables with such names are really a source of future confusion.

Документация по MQL5: Глобальные переменные терминала / GlobalVariableGet
Документация по MQL5: Глобальные переменные терминала / GlobalVariableGet
  • www.mql5.com
Глобальные переменные терминала / GlobalVariableGet - Документация по MQL5
 

I'll repeat my question though.

Is it possible to determine the triggering of OnInit inside of OnTick?
For example, can I declare a static variable inside OnTick that stores the number of times the EA is initialized (if MQL5 has such property or a similar one)?

 
voix_kas:

I must be paranoid. I don't like public (global) variables. I consider it a muveton.

Global variables are at least visible from afar. But hiding serious cumulative variables inside functions in statics is a way of carefully spreading a rake for oneself. This is the first time I've seen an accumulative static array hidden inside a function in such a way. This is a fiery rake.

Use classes - they will leave the global level clean, hide all the guts and get rid of crutches.

Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Основы языка / Переменные / Глобальные переменные - Документация по MQL5
 
voix_kas:

I'll repeat my question though.

Is it possible to determine OnInit triggering inside of OnTick?
For example, can we declare a static variable inside OnTick that stores the number of initializations of the EA (if there is such or similar variable in MQL5)?

It is possible not only to count the number of OnInit triggers, but also to determine why the initialization occurred (implementation is another issue).

Are you familiar with _UninitReason, for example?

 
You can read it in OnInit, but I need this data in another event (without using global variables). Whichever way you look at it, it's a question of implementation. It's the same with OnDenit.
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Основы языка / Переменные / Глобальные переменные - Документация по MQL5
 
Classes I have never written. If someone can help me, I will be grateful.
Need to write a WorkSymbols class.
Methods:
string GetSymbol[];
bool UpdateSymbols(inWorkSymbols);
bool UpdateSymbolsStatus();
int GetSymbolCount();

Apologies if the request is cheeky... I'll be trying to figure it out myself too.
 
Renat:

Yes, it seems a mistake to combine the symbol change and timeframe condition.

I am also in favour of separating them into two conditions. The ticket has already been placed in the service desk.

Thank you!
 

Sort of cooked it up. Criticism is welcome.

input string inWorkSymbols  = "USDCHF; GBPUSD; EURUSD; USDJPY; USDCAD; AUDUSD; EURGBP; EURAUD; EURCHF; EURJPY; GBPJPY; GBPCHF"; // Рабочие инструменты

class CSymbolList {
  private:
    string Symbols[];

  public:
    void   CSymbolList() { SetSymbols(""); }
    void  ~CSymbolList() { ArrayFree(Symbols); }
    int    GetSymbolCount() { return ArraySize(Symbols); }
    void   SetSymbols(string);
    string GetSymbolName(int);
};

void CSymbolList::SetSymbols(string Source) {
  ArrayFree(Symbols);
  for (int count = 1, i = 0; i < SymbolsTotal(false); i++)
    if (StringFind(Source, SymbolName(i, false)) != -1) {
      if (ArrayResize(Symbols, count) != count) {
        ArrayFree(Symbols);
        return;
      }
      Symbols[count-1] = SymbolName(i, false);
      count++;
    }
}

string CSymbolList::GetSymbolName(int Item) {
  if (Item < 0 || !ArraySize(Symbols) || Item >= ArraySize(Symbols)) return "";
  return Symbols[Item];
}

void OnStart() {
  CSymbolList slMain;
  slMain.SetSymbols(inWorkSymbols);
  for (int i = 0; i < slMain.GetSymbolCount(); i++)
    Print(slMain.GetSymbolName(i));
}
 

The only thing I don't like here is the "live" resizing of the array containing the working data.
Question for the developers, is it guaranteed that the previously entered user data in the dynamic array being modified will be preserved under the following condition?

if (ArrayResize(Symbols, count) == count)
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
 
voix_kas:

The only thing I don't like here is the "live" resizing of the array containing the working data.
Question for the developers, is it guaranteed that the previously entered user data in the dynamic array being modified will be preserved under the following condition?

I'm betting it's guaranteed. At least I count on it all the time, and the problem has never arisen.