Features of the mql5 language, subtleties and tricks - page 270

 

const ulong KEY_LG_MCS=100; // задержка 

ulong keyBEnabledAfter=1;  // разрешена реакция на кнопку после заданного времени, или 0 запрещена вовсе

OnChartEvent(..) {

   ulong now=GetMicrosecondCount();

   if ( id==CHARTEVENT_KEYDOWN && ..) {

// нажата нужная кнопка

        if (keyBEnabledAfter!=0 && keyBEnabledAfter<now) {

             // разрешена обработка кнопки

             keyBEnabledAfter=0;  // запретим дальнейшую реакцию

             needsCalc=true;       // запустим вычиляндр

             // или прямо сразу вычиcлим Calc(); keyBEnabledAfter=GetMicrosecondCount()+KEY_LAG_MCS;

        }

   }

}

OnTimer() {

   if (needsCalc) {

      // что-то тут вычисляем

      if (calcDone) {

          // закончили вычислять

          needsCalc=false; // отметим это

          keyBEnabledAfter=GetMicrosecondCount()+KEY_LAG_MCS; // разрешим реакцию ена кнопку через KEY_LAG mcs

      }

   }

}

general principle in pseudocode...Wrap functions to taste, or spawn a class on the fly

 

What wrapping in a class is good for is the use of the RAII idiom.

The idea is as follows. When out of scope, destructors of objects with local lifetime are called in the reverse order of their declaration. Therefore, in the code:

void Foo(){
   TSomeClass something;
   ...
   DoSomething();
}

DoSomething will be called first, and only then the ~TSomeClass() destructor. Theoretically, we may not even have the TSomeClass source code on hand and not know what happens in the destructor.

If we do:

class TScoupe{
public:
   ~TScoupe() {DoSomething();}
};

void Foo(){
   TScoupe scope;
   TSomeClass something;
   ...
}

, it is guaranteed that the TSomeClass destructor will be called first and only then, when the TScoupe destructor is executed, will DoSomething be called.

 
Dominik Egert #:
If I understand correctly, we are talking about multi-threaded security?

If so, none of the proposed solutions is safe.

Atomic operation is mandatory for thread safety, only one function in MQL allows to do it, and it was not used here.

In fact, to make OnEvent multithreaded, a critical section is needed. Such a section can be built using

GlobalVariableSetOnCondition.

Or am I on the wrong track?

Using global variables in general and for synchronisation, in particular, is not a good idea, considering that they can be changed from anywhere in the terminal)

And the point of the discussion is not synchronisation of threads, but, in this case, not executing OnChartEvent queued until the end of execution of certain code.

 
Vladimir Simakov #:

Using global variables in general and for synchronisation, in particular, is not a good idea, considering that they can be changed from anywhere in the terminal)

And the point of the discussion is not synchronisation of threads, but, in this case, not executing OnChartEvent queued until the end of execution of certain code.

OK, as you say.

To me it sounds very much like multi threading.
 
Vladimir Simakov local lifetime are called in the reverse order of their declaration. Therefore, in the code:

DoSomething will be called first, and only then the ~TSomeClass() destructor. Theoretically, we may not even have the TSomeClass source code on hand and not know what happens in the destructor.

However, if we do this:

, it is guaranteed that the TSomeClass destructor will be called first and only then, when the TScoupe destructor is executed, will DoSomething be called.

All a programmer achieves with this approach is to complicate code readability.
 
It probably makes sense to replace CHARTEVENT_KEYDOWN with CHARTEVENT_KEYUP to handle keystrokes
 
Andrey Dik #:

Has anyone been able to run any optimisation using Alglib?

I would be grateful if someone could share links to examples of use.

Doesn't anyone know and hasn't seen an example of use?

 
Andrey Dik #:

Doesn't anyone know or have seen an example of use?

I have used to forecast volatility using the GARCH model. There is an article on the site
 
Evgeniy Chernish #:
I have used to forecast volatility using the GARCH model. There is an article on the site

Is it exactly the optimisation methods used there in the article? Can I have a link to the article, please?

ZЫ. If I understood correctly, this article is meant?

 
Andrey Dik #:
Is it exactly the optimisation techniques used there in the article? Can I have a link to the article please.

https://www.mql5.com/ru/articles/15223

Yes, MinBLEIC was used.

Эконометрические инструменты для прогнозирования волатильности: Модель GARCH
Эконометрические инструменты для прогнозирования волатильности: Модель GARCH
  • www.mql5.com
В статье дается описание свойств нелинейной модели условной гетероскедастичности(GARCH). На ее основе построен индикатор iGARCH для прогнозирования волатильности на один шаг вперед. Для оценки параметров модели используется библиотека численного анализа ALGLIB.