Questions from a "dummy" - page 65

 
x100intraday:

When I call my function, should I pass the array by reference, via pointer or something else?

Read the section about passing parameters by value and by reference:

MQL5 Reference / Language Basics / Functions / Passing Parameters

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

Read the section in the Reference Manual about passing parameters by value and by reference:

MQL5 Reference / Language Basics / Functions / Passing Parameters

Actually, I've just come from there and the compilation errors I mentioned in my previous message have happened after reading the above section.

Now I've reread it carefully - it's all about const and where to put it.

Thanks, I've figured it out.

 
x100intraday:

InOnCalculate I can easily use array elements like high by index. Is it also possible to access the index elements of this array in ExtFunc? When calling my function, should I pass the array-argument by reference, via pointer or something else? So far I've managed to minimize the error messages to: "'high' - parameter conversion is not allowed" and "'high' - constant variable cannot be passed as reference" regarding the same line of my function call with the array argument from OnCalculate. Is it hopeless or is there a solution?

So far in OnCalculate I have resorted to copying high to another array:

and then use CopyOfHigh in ExtFunc instead of using high-array directly.

Just pass the array to your function by reference

bool ExtFunc (string str, int P, int i, double & high[])
  {
   if (high[i] < high[i-1]) return(false);
   return(true);   
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i=0;
   if ExtFunc("s",60,i,high) == 1)
     Buffer[i] = high[i];
  }
 

Greetings all!

What does the warning mean:

possible loss of data due to type conversion expert.mq5

when compiling it? It says this:

   string Symb="EURJPY";
   int DIGITS = SymbolInfoInteger(Symb,SYMBOL_DIGITS);

What's wrong?

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

Simply pass the array to your function by reference

Not exactly:

bool ExtFunc (string str, int P, int i, const double & high[])
  {
   if (high[i] < high[i-1]) return(false);
   return(true);   
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i=0;
   if ExtFunc("s",60,i,high) == 1)
     Buffer[i] = high[i];
  }
 
RomanS:

Greetings all!

What does the warning mean:

possible loss of data due to type conversion expert.mq5

when compiling? It says this:

What's wrong?

TheSymbolInfoInteger() function returns value of long type (see Reference), while DIGITS is declared as int. This is an implicit type conversion. See "Type conversion".
 
RomanS:

What the warning means:

possible loss of data due to type conversion

The meaning of this message varies, depending on the context in which it is being considered.

For example:

1. "Make an explicit type conversion!"

   int DIGITS = (int) SymbolInfoInteger(Symb,SYMBOL_DIGITS);

2. "Possible data twitching with implicit type conversion." // This is a literal translation.

This is understandable, since the long type returned by the function has a larger size and covers a wider range of values.

Another option that comes to my mind most often lately:

3. "MetaQuotes staff doesn't understand how cool, attractive, and effective it would be to learn if error messages and mql5 compiler warnings were given in the user's native language."

 
MetaDriver:

... how cool, attractive, and effective it would be to learn if mql5 compiler error messages and warnings were given in the user's native language."

Yeah it wouldn't be bad. Although I personally am already a bit savvy in English, and translators are a dime a dozen these days, but again, this takes up valuable time, which is not so much. Some people don't have enough of it to use a translator for such a complicated subject as trading on financial markets + programming. MetaTrader 5 is a multi-language platform. I wish the messages and comments in the help examples (we sometimes come across them) were in the language that has been selected in the terminal.
 

I have a suspicion that if the indicator is activated through iCustom, it is calculated on every tick. And it doesn't depend on the calls to it through the CopyBuffer. Is it correct?

If it is correct, then is it possible to disable the calculation of indicator and enable it only before calling the CopyBuffer?

 
masharov:

I have a suspicion that if the indicator is activated through iCustom, it is calculated on every tick. And it doesn't depend on the calls to it through the CopyBuffer. Is it correct?

It depends on the logic of the custom indicator. Actually, it can re-calculate its values once a day, skipping all the other ticks. So to say, according to the author's will.

masharov:

If so, is it possible to disable the recalculation of indicator and enable it only before calling the CopyBuffer?

Basically, some people try to use this monster approach: create a copy of the indicator via iCustom, copy the required data, delete the copy of the indicator. The procedure is repeated as needed.

There is also OnTimer() function, I haven't worked with it myself, but maybe you can adapt it to your task.

Reason: