Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1877

 
Mihail Matkovskij #:

And faster version:

I agree about case-insensitive comparison, I wrote a more generalized bicycle for my own enum, where I don't use lower case.

But if for ENUM_TIMEFRAMES run this variant:

bool StringToEnum(const string i_str, T &o_val) { return StringToEnum(i_str, o_val, INT_MIN, INT_MAX); } // медленный вариант
you can have time for a coffee while it picks up, e.g. for PERIOD_MN1 :)
 
Valeriy Yastremskiy #:

Get the prices from the straight lines on each bar and compare or find the difference, in places where the signs of the crossing differences change) There may be no equalities on the bar, by the way.

What function is used for that? MqlRates? And if I use ObjectGet then I have to specify the object property there, if I take OBJPROP_PRICE then how can I make it get the price before the current bar.
 
12345678902003 #:
Help please, I draw two Gann lines and they intersect at a certain point, I need to know the coordinates of the intersection point of these lines.
If you can determine the price of the second point of the Gann line, then KimIV can help you further
 
Maksim Emeliashin #:

I agree about comparison with case ignoring, I wrote a more generalized bicycle for myself, for my own enum, where I don't use lower case.

But if for ENUM_TIMEFRAMES this variant is run:

you may have time to drink coffee before it picks up, e.g. for PERIOD_MN1 :)

Well, in ENUM_TIMEFRAMES the minimum and maximum values are known. That's why they can be specified explicitly.

With the rest of the enum, it is sufficient to know their approximate range of values. If constants are not specified in the enum declaration, the values there are usually from 0. i_max_enum can be specified by any two- or three-digit number: 50, 100, 255.

 
Maksim Emeliashin #:

Right now, I need to write indicator settings and EA parameters to the database. At the same time I would like to have:

1. human-readable records

2. machine-readable records

3. stability to add new values in its custom enum, not necessarily at the end.

There is no problem with record - EnumToString, but developers did not make a reverse function, unlike all other types.

Have you ever tried to print an enumeration?

Print(PERIOD_M5);

What do you think will be printed?


But creating an enumeration programmatically... yes. That would be interesting.

 
x572intraday #:
Why can't we loop through the input parametres? Why are you punishing us like this?
This is of course a crutch, but I use it: enter all the required data into a string input variable via some given separator, and then use StringSplit to overflow it into an array.
 
Mihail Matkovskij #:

Well, in ENUM_TIMEFRAMES the minimum and maximum values are known. Therefore they can be set explicitly.

With other enum, it is enough to know their approximate range of values. If constants are not specified in the enum declaration, the values there usually start at 0. i_max_enum can be set by any two- or three-digit number: 50, 100, 255.

You can also experimentally get the minimum and maximum enum values. Write them down and specify them in StringToEnum for the most optimal speed:

int nEnum;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template <typename T>
bool enumFindMinMax(const T _enum, int &__min, int &__max, int _minEnum, int _maxEnum) {
  T enum_;
  int min, max;
  min = INT_MAX; max = INT_MIN;
  nEnum = 0;
  for(int i = _minEnum; i <= _maxEnum && !IsStopped(); i++) {
    enum_ = (T)i;
    if(StringFind(EnumToString(enum_), "::", 0) >= 0)
      continue;
    if (i < min)
      min = i;
    if (i > max)
      max = i;
    nEnum++;
  }
  if (min != INT_MAX && max != INT_MIN) {
    __min = min;
    __max = max;
    return true;
  }
  return false;
}

template <typename T>
bool enumFindMinMax(const T _enum, int &__min, int &__max) { return enumFindMinMax(_enum, __min, __max, INT_MIN, INT_MAX); }

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
  int min, max;
  if (enumFindMinMax((ENUM_ACCOUNT_INFO_DOUBLE)0, min, max, -500, 500))
    printf("enumFindMinMax ENUM_ACCOUNT_INFO_DOUBLE min: %d, max: %d, Count: %d", min, max, nEnum);
  else
    Print("enumFindMinMax Error!");
}

Result of the script:

enumFindMinMax ENUM_ACCOUNT_INFO_DOUBLE min: 37, max: 52, Count: 14

Open ENUM_ACCOUNT_INFO_DOUBLE and see. The number of constants is Count (14). Thus at the start of the application you can handle all necessary enum, write their minimum and maximum values and use StringToEnum corresponding min and max with the best speed.

P.S. The second variant of enumFindMinMax with INT_MIN and INT_MAX is really very slow. I tried it at first. Then I got tired of waiting for enumFindMinMax to finish and set values from -500 to 500.

if (enumFindMinMax((ENUM_ACCOUNT_INFO_DOUBLE)0, min, max, -500, 500))

Thus, I came to a conclusion that it is not necessary to use the whole int range at all.

Files:
 

I am facing a strange behaviour of the terminal.

The situation is as follows: an Expert Advisor is working in one chart, which at a certain moment opens another chart and sets a certain temple on the new chart. The latter template has been defined for launching the second EA on the new chart.

Everything works fine in the middle of the week, but when the market is closed, on weekends, the new templet is started on the new chart (as can be seen when changing the chart's appearance), but the second EA does not start there. The only way to "push" the second Expert Advisor is to manually start, on any chart, any script, even an absolutely empty one. Then the second expert starts working on a new chart.

I have written this code in the first Expert Advisor both using ChartOpen and ChartApplyTemplate functions and using CChart class - it always turns out the same way, in a closed market the second Expert Advisor on a new chart won't start until I manually "push" the terminal somehow.

Who may have faced with such a situation? How to cope with it, what direction to "dig"?

 
akskarabey ChartApplyTemplate functions and using CChart class - it always turns out the same way, in a closed market the second Expert Advisor on a new chart won't start until I manually "push" the terminal somehow.

Who may have faced with such a situation? How to deal with it, what way to "dig"?

How do you know it doesn't start?

P.S.

Try it like this

int OnInit()
{
....
....

 ChartRedraw();
  return(INIT_SUCCEEDED);
}
 
Mihail Matkovskij #:

You can find the constant in enum with a brute force function (same principle as), translating it with EnumToString and comparing it with the desired constant. All that remains is to return the result.

Can we have an example (or at least a key line), because nothing comes to mind? Would you also have to go through a huge list of values, sifting through all the left-handed ones or would you just look for useful ones? At the moment I don't think there's anything to sift from, there are no left-handed ones in the list... but I can't get hold of the idea.