Errors, bugs, questions - page 435

 
voix_kas:

In general, it's funny how it turns out.
On a hunch, I thought that the OnDenit function is a kind of destructor and the OnInit function is a constructor of an EA.

In fact, it turns out that OnInit is a multiple event (within Expert Advisor's lifetime). It is not clear then, why do we need to explicitly generate the OnDenit event if we know that the EA does not terminate its operation (for example, in case of change of chart period)?

When the symbols change, the Expert Advisor is hot-loaded for the sake of a quick start and saving the informational base of its previous life.

For example, the Expert Advisor is on the chart, it has accumulated its statistics and logic, and then it gets timeframe changed and has to work from zero on cold restart.

And there is one more question.
The reason for REASON_CHARTCHANGE deinitialization - a symbol or a chart period has been changed.
Please explain how a chart symbol can be changed without deleting an EA on it?

In the hot restart mode.
 

Yedelkin, Interesting, Renat
Thank you for the clarifications.

I think it also makes sense to include an explicit list of "hot" and "cold" restarts in the documentation.

If there is no reinitialization at every OnInit, for the multicast EA we will have to use a crutch, which is a global flag. :(
I will post the code a bit later.

 
Interesting:

The Expert Advisor in any case will not be deleted during normal initialization, it will just be allowed to trade under certain terminal settings (but for this the Expert Advisor must understand that the symbol has been changed...).

By the way, that reminds me. I've been meaning to ask the developers about those settings.

Renat, please make two different checkboxes to disable trading when changing timeframe and the symbol. These are two fundamentally different changes.

I would not like my EAs to stop trading when changing timeframe - it is absolutely unnecessary - anyway they are processing every tick and there are no problems with it.

But the change of the symbol is fundamentally important. I would like to keep this locking... but now these two adjustments are for some reason synchronized and regulated together.

I'm solving this problem programmatically (storing the original symbol in a static variable and controlling the changes in the inite). But it would be better if this could be blocked at terminal level.

Even better would be the possibility to switch timeframe or symbol with an Expert Advisor running. Why stop trading due to stupidity-forgetfulness?

I.e. it would be much better to block switching of timeframe and/or symbol (separately!), if it is specified in settings that it is forbidden when Expert Advisor is present on a chart.

// With giving a corresponding message when attempting to do so.

Actually this can also be solved programmatically (forcibly putting the symbol or timeframe back in place), but I think you yourself are interested in really user-friendly settings at terminal level.

 

MetaDriver:

Renat, please make two different checkboxes to block trading on timeframe change and symbol change. These are two fundamentally different changes.

I don't want my EAs to stop trading when they change timeframe - it is absolutely unnecessary - anyway they are processing every tick and there are no problems with that.


I support the idea, you should make two ticks and a separation in the deinitialisation reason codes (it would be convenient that way).

But blocking the possibility to change timeframe, I don't know how (about the symbol), is too much for my taste.

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

That reminds me. I've been wanting to ask the developers about these settings for a long time now.

Renat, please make two different checkboxes to block trading on change of timeframe and change of symbol. These are two fundamentally different changes.

Yes, it seems that the condition of changing the symbol and timeframe were combined for nothing.

I, too, am in favor of splitting them into two conditions. The ticket has already been placed in the Service Desk.

 

Actually, I am attaching the code for defining the working tools for the multicooker. Criticism is welcome. :)

input uint   inTimeToRescan = 3600; // Интервал времени для принудительного пересканирования рабочих инструментов, в секундах
input string inWorkSymbols  = "USDCHF; GBPUSD; EURUSD; USDJPY; USDCAD; AUDUSD; EURGBP; EURAUD; EURCHF; EURJPY; GBPJPY; GBPCHF"; // Рабочие инструменты


bool Initialize;


int OnInit() {
  //...
  Initialize = true;
  //...
}


void OnTick() {
  static ulong  LastScan = 0;
  if ((ulong)TimeCurrent() - LastScan >= inTimeToRescan) Initialize = true;

  static string Symbol[];
//  static int    Forecast[];
//  static int    Volatile[];

  if (Initialize) {
    Comment("Опрос рабочих инструментов...");
    int SymbolCount_1 = 0;
    for (int i = 0; i < SymbolsTotal(false); i++)
      if (StringFind(inWorkSymbols, SymbolName(i, false)) != -1)
        SymbolCount_1++;

    if (!SymbolCount_1) return;
    if (ArrayResize(Symbol, SymbolCount_1) != SymbolCount_1) return;

    int SymbolCount_2 = 0;
    for (int i = 0; i < SymbolsTotal(false); i++)
      if (StringFind(inWorkSymbols, SymbolName(i, false)) != -1)
        Symbol[SymbolCount_2++] = SymbolName(i, false);

    if (SymbolCount_1 != SymbolCount_2) return;

    //if (ArrayResize(Forecast, SymbolCount_1) != SymbolCount_1) return;
    //if (ArrayResize(Volatile, SymbolCount_1) != SymbolCount_1) return;

    Initialize = false;
  }
  //...
}

Every tick an Expert Advisor tries to get a list of working instruments.
The update of the list of work instruments occurs in two conditions: 1) OnInit is triggered, 2) after the time that was set in the input parameter of the EA.
As we see, a crutch in the form of a global variable(bool Initialize) is used to detect the next initialization. If there was an initialization of statics, it wouldn't be needed.

I consider global variables as evil, as well as the unconditional goto operator in its time.

 
voix_kas:

In absence of re-initialization at each OnInit, for multilaterals a "crutch" in the form of global flag must be used. :(

It is better to write the code carefully from the beginning, without leaving crutches in the form of intermediate static variables.

As a solution, hide such data inside a class. If the class is dead, the environment is dead too.

And on global level, leave a minimum of static variables.

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

Actually, I am attaching the code for defining the working tools for the multi-tool. Criticism is welcome. :)

As a tip - put Symbol on global level and zero it in OnInit. If array is empty, then it's time to initialize.

And no additional flags.

 
Renat:

As a tip, bring Symbol to global level and zero it in OnInit. If the array is empty, then it's time to initialize.

And no additional flags.

I guess I'm paranoid. I don't like public (global) variables. I consider it a muveton.
Is it possible to specify OnInit triggering inside of OnTick?
For example, can I declare a static variable inside OnTick that stores the number of initializations of the EA (if there is such or similar property in MQL5)?

 
voix_kas:

Global variables are evil, as was the unconditional goto operator back in the day.

I must be paranoid. I do not like public (global) variables. I find it a muveton.

1. Why? It is necessary to get rid of harmful symptoms, and decisively.

2. Don't name variables, arrays and other things with consonant or similar language keywords (but the "Symbol" array is very striking, you can't tell if it's an array or something else in your code).

Renat:

The solution is to hide such data inside the class. If the class dies, so does the environment.

And on a global level, leave a minimum of static variables.

Good suggestion. Time to switch to OOP already... :)