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

 
ANDREY:

I added square brackets void PrintArray(double &eArray[]) The compiler did not show any errors or warnings.
BUT..... the Print() function did not print a single time for some reason.

I understand your laziness, because I am like that myself. If you are not too lazy and my enthusiasm replaces it, I will be grateful to you if you tell me what else is wrong with the custom function.

Thanks for the help and sorry for the trouble.

Maybe the array is empty? Check it by changing the function a bit

void PrintArray(double &eArray)
   {
   int eSize=ArraySize(eArray);
   string eStr="Размер массива "+eSize+" : ";
   for(int i=0; i<eSize; i++)
      {
      eStr+=IntegerToString(i)+": "+DoubleToString(eArray[i],4)+", ";
      }
   Print(str);
   }
If it prints 0, look for a problem in the array filling.
 
Alexey Viktorov:

void PrintArray(double &eArray)
   {
   int eSize=ArraySize(eArray);
   string eStr="Размер массива "+eSize+" : ";
   for(int i=0; i<eSize; i++)
      {
      eStr+=IntegerToString(i)+": "+DoubleToString(eArray[i],4)+", ";
      }
   Print(str);
   }

I have found an error. In the lastPrint(str); line,you passed str instead ofestr. I fixed it and everything was OK.

Thanks to you I now have grasped this subject not only in outline, but in detail. The only unanswered question was about the plus points from my post

Thanks for your help and support.

 
Maxim Kuznetsov:

on the forum and in publications about C#, Delphi and everything else...

I've never done this, can some link for "dummies"?
 
ANDREY:

I have found an error. In the lastPrint(str); line, you passed str instead ofestr. I fixed it and everything was OK.

Thanks to you I now have grasped this subject not only in outline, but in detail. The only unanswered question was about the plus points from my post

Thanks for your help and support.

It wasn't me who passed it on,

Forum on trading, automated trading systems and testing trading strategies

Any questions from newbies on MQL4 and MQL5, help and discussion of algorithms and codes

Aleksei Stepanenko, 2021.03.13 09:04

Print("-LoY[0]-", DoubleToString(LoY[0],4), "---LoY[1]--", DoubleToString(LoY[1],4), "---LoY[2]--" , DoubleToString(LoY[2],4), "---LoY[3]--" , DoubleToString(LoY[3],4),................  "---LoY[30]--" ,  DoubleToString(LoY[30],4) );

You may want to print an array or make a separate function to print an array:

void PrintArray(double &eArray)
   {
   string eStr="";
   int eSize=ArraySize(eArray);
   for(int i=0; i<eSize; i++)
      {
      eStr+=IntegerToString(i)+": "+DoubleToString(eArray[i],4)+", ";
      }
   Print(str);
   }

And call it from anywhere

PrintArray(LoY);

I just did not pay attention to it. I just don't understand how the compilation went without error...

What's the answer if you've figured it out and written the whole sequence

ANDREY:

I think I finally figured it out ( I'm a bit of a slowpoke) ......

In the first iteration, the string variable str is empty. The characters =+ tell str to assign itself empty (without values) and to itself empty add a string with values, namely"--LoY["+IntegerToString(r)+"]--, "+DoubleToString(LoY[r],4)+",";. The value of this string is " --LoY[0]--, --1.6104-- ". After these operations , str gets the value "--LoY[0]--, --1.6104-- " on the first iteration. As I understood it in your terminology, this is called the first element.

At the second iteration str already has the first element with the value " --LoY[0]--, --1.6104-- " The characters =+ instruct str to assign itself with the value of the first element and to itself with the value of the first element, add a string with other values, namely "--LoY["+"+IntegerToString(r)+"]--, "+DoubleToString(LoY[r],4)+",";. The value of this string is already " --LoY[1]--, --1.6105--". After these operations, str gets the value"--LoY[0]-- --1.6104-- --LoY[1]-- --1.6105--" on the second iteration.That is, str has got the second element and at the thirtieth iteration str will contain 30 elements with different values of the array elements.

When the loop is over, the string variable str with 30 items will be printed outside the loop once.
It took me a long time to figure out this algorithm because when you were speaking about addition I paid attention only to the red plus sign "--LoY["+IntegerToString(r)+"]--,"+DoubleToString(LoY[r],4)+", not to str+=

So it's still a mystery to me what role those red pluses "--LoY["+IntegerToString(r)+"]--, "+DoubleToString(LoY[r],4)+" play in this algorithm

Thank you for your help.

And what a mystery it remains, if it's all timetabled correctly...
 
MakarFX:
I've never done it, can some link for "dummies?"

If you haven't written in C#, Delphi and similar before, it won't help... Windows are created like everywhere else, but first you have to learn how to do it "everywhere".

First a short course in C#, WinForms (for example). There should be a bunch of them on the internet. This goes a bit beyond the scope of the forum.

 

Alexey Viktorov .

Alexey Viktorov:


And what a mystery remains, if all is correctly written...

I did not understand this algorithm for a long time, because when you were speaking about addition I was paying attention only to the red pluses "--LoY["+IntegerToString(r)+"]--,"+DoubleToString(LoY[r],4)+", but not to str+=

That's why I still wonder what role these red pluses"--LoY["+IntegerToString(r)+"]--, "+DoubleToString(LoY[r],4)+" play in this algorithm

It unambiguously follows from the way I described my understanding that connection of strings at each iteration occurs in one place and once together with the str+= assignment operation

That is, using symbol +, value of one element in string variable str connects (plus) with value of another element of the same string variable str
And I still don't understand what these red + signify str +="--LoY["+IntegerToString(r)+"]--,"+DoubleToString(LoY[r],4)+",";. There is no summing operation performed over the values that are between these red pluses ..... as it seems to me. If I'm right, what function do these red pluses perform? And if I'm wrong, I must have failed to understand something.

By the way, in your post, in the yellow line, there is only one such red plus before +DoubleToString(LoY[r],4). But I don't see it after it.

Thank you for your help.

 
Alexey Viktorov:

Only it's not clear how compilation went without error, it's not clear...


And I initialized str inside the body of the user function myself when I saw that the compiler pointed out that str was undefined. But I forgot to tell you about it.
Then I deleted str from the user function everywhere and put eStr in brackets instead of str in the last line of the user function.

 
Maxim Kuznetsov:

If you haven't written in C#, Delphi and similar before, it won't help... Windows are created like everywhere else, but first you have to learn how to do it "everywhere".

First a short course in C#, WinForms (for example). There should be a bunch of them on the internet. This goes a little beyond the scope of the forum.

Well the form can be created.


I am more interested in how the exchange of data between my window and the Expert Advisor should be done.

 
void PrintArray(double &eArray[])
   {
   string eStr="";
   int eSize=ArraySize(eArray);
   for(int i=0; i<eSize; i++)
      {
      eStr+=string(i)+": "+DoubleToString(eArray[i],4)+", ";
      }
   Print(eStr);
   }
 

Aleksei Stepanenko:

void PrintArray(double &eArray[])
   {
   string eStr="";
   int eSize=ArraySize(eArray);
   for(int i=0; i<eSize; i++)
      {
      eStr+=string(i)+": "+DoubleToString(eArray[i],4)+", ";
      }
   Print(eStr);
   }


Thanks for the clarification.

By the way, I removed the yellow pluses and the compiler gave an error. So they play some role in this whole construction. But what.... I still don't understand. What for they are needed when string addition is performed only through the use of blue pluses. Judging by your explanations, there is nothing else in this construction ..... if I'm not mistaken.

And about string(i)... About the type conversion .... is more or less clear to me. What is not clear is that..... string is the name of a variable type. i is a counter variable denoting the index of an array element. And why isi in parentheses () ? I've been thinking so far that parentheses are a function characteristic. For example, Print( ). And different data are put inside parentheses in some functions. But what do parentheses mean or what function do parentheses perform with respect to i and this whole construct - string(i)? At first glance, it seems that before the i variable had an int type (integer), and then you changed the i variable's type from int to string (string) . But round brackets containing i do not let me think so.

Thanks for the explanation.

Reason: