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

 
Koldun Zloy #:

How about this?

I can't test it.

 
fxsaber #:

Don't check.

QuickSort library here

Быстрая сортировка.
Быстрая сортировка.
  • www.mql5.com
Функции для сортировки массивов. Позволяют сортировать строки и структуры по любому условию.
 
Koldun Zloy #:

The QuickSort library is here

Thanks, that's a very good option! I seem to have QuickSort too, but for some reason it's wildly slow.


Your option could be wrapped in macros somehow to make it faster to use...

 
fxsaber #:

Thanks, that's a very good option! I seem to have QuickSort as well, but for some reason the brakes are wild.


Your option could be wrapped in macros to make it faster to use....

I don't see why you need macros. It's very simple as it is.

 

how to properly format something that looks like this in C:

int sort(void *arr,size_t isize,size_t size, int (*cmp)(void *item1,void *item2)); /// типовой прототип sort с функцией сравнения

???

trying to sort through templates:

template <typename T>

int sort(T &arr[],int (*cmp)(const T &,const T&))
{

}

doesn't work - you can't put a function pointer into the argument. There must be a separate typedef

but typedef can't (or can it??) be a template.

macroms grow out of these problems :-)

 
Maxim Kuznetsov #:

how to properly format something that looks like this in C:

int sort(void *arr,size_t isize,size_t size, int (*cmp)(void *item1,void *item2)); /// типовой прототип sort с функцией сравнения

???

We're trying to use templates:

fails - you can't put a function pointer in the argument. There must be a separate typedef

but typedef cannot (or can it??) be a template....

macroms grow out of these problems :-)

template <typename T> struct SORT
  {
   typedef int       (*cmp)(const T &, const T&);
   static  int       Do(T &arr[], cmp) {return 0;}
  };

int SortInt(const int &, const int &) {return 0;}

void OnStart()
  {
   int arr[];
   SORT<int>::Do(arr, SortInt);
  }
 

I discovered an unobvious feature of MQL (and C++)

class C1
  {
public:
   virtual void      f1(int p = 1) {Print(p);}
  };
class C2: public C1
  {
public:
   virtual  void     f1(int p = 2) {Print(p);}
  };

void OnStart()
  {
   C2 obj;
   C1 *p = &obj;
   p.f1();        //Prints "1"
  }

That is, the default value is substituted into the parameter (p) at the point of method call (p.f1()) and this value is taken from the method description in class C1 - the declared type of variable ptr, not the real type of object obj.

(Which, in general, is logical).

 

Forum on trading, automated trading systems and testing trading strategies

Errors, bugs, questions

Andrey Dik, 2022.06.24 08:38

MQL_VISUAL_MODE is a special case of MQL_TESTER?

MQL_OPTIMIZATION is a special case of MQL_TESTER?

I mean, MQL_TESTER includes both MQL_VISUAL_MODE and MQL_OPTIMIZATION?

I need the EA to perform some actions when working on a chart and in visual mode, but not in all other cases. I can't figure out how to select the right flags for this case when checking MQLInfoInteger()?

I could do it very simply, for example, like this:

if (MQLInfoInteger(MQL_VISUAL_MODE) || MQLInfoInteger(MQL_CHART_MODE))

{

  //выполняем некоторые действия

}

but the MQL_CHART_MODE flag is not provided in mql5.


does anyone have any thoughts?

 
Andrey Dik #:

Anybody have any thoughts?

if (ChartID()!=0) {

    // Graphical chart presents
    // draws on it

}

 
Maxim Kuznetsov #:

if (ChartID()!=0) {

    // Graphical chart presents
    // draws on it

}

What does that mean? Can you expand on that?

Reason: