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

 
Aleksei Stepanenko:

or make a separate array print function:

And call it from any place

Alexey, I've been silent for a long time, but I can't see this quietly... Why use IntegerToString() when an explicit type conversion is much simpler and less costly...

eStr+=(string)i+": "+DoubleToString(eArray[i],4)+", ";
 

dunno, habit :)

 
Aleksei Stepanenko:

or make a separate array print function:

And call it from anywhere

Thank you very much for your understanding and clarification. I am pausing to study and understand the information that is new to me.

 
Alexey Viktorov:

Alexey, I've been silent for a long time, but I can't see it quietly... Why use IntegerToString() when an explicit type conversion in this case is much easier and less expensive...

And thank you too for your valuable additions.

 
Can you tell me where to look and read about creating an external window for an EA?
 
MakarFX:
Can you please tell me where to look and read about creating external window for EA.

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

tcl.Eval("toplevel .myWin ; wm title .myWin {Окношко}" ); // простите, не удержался
 
Aleksei Stepanenko:

or make a separate array print function:

And call it from anywhere

I've decided to make a separate custom array print function. Or rather, not make one, use the ( PrintArray() ) Which you have already done.

What have I done?

I placed the call to the user PrintArray() function inside the OnTick() function... as described in Kovalev's tutorial.

2. I placed the body of the PrintArray() function outside the OnTick() function... ... as described in Kovalev's tutorial.

All new variables from the body of this function are local. They are declared and initialized within this function.

int P1=0;
double LoY[31];
void OnTick()
{
if (P1==0)
{
for(int r=0; r<31;r++)
{
LoY[r]=1.6104+(r*2)*0.0001;
P1=1;
}
}
//*************************************************************  Б Л О К    N 2
for(int x=0; x<31;x++)
{
if (Bid < LoY[x] )
{
LoY[x]=Bid;
}
}
ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND);
PrintArray(LoY);
}
//****************************

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);
   }

I didn't make any changes to your function. But the compiler gives 6 errors for some reason. And all of them are related to the user function.

I would be very grateful to you if you could tell me what I did wrong.
Thank you.

 
ANDREY:

I've decided to make a separate custom array print function. Or rather, not make one, use the one ( PrintArray() ) which you have already done.

What have I done?

I placed the call to the user PrintArray() function inside the OnTick() function... as described in Kovalev's tutorial.

2. I placed the body of the PrintArray() function outside the OnTick() function... ... as described in Kovalev's tutorial.

All new variables from the body of this function are local. They are declared and initialized inside this function.

I haven't made any changes in your function. But the compiler produces 6 errors for some reason. And all of them relate to a user function.

I'll be very grateful to you if you tell me what I've done wrong.
Thank you.

I don't remember exactly and I'm too lazy to check it. Try adding square brackets

void PrintArray(double &eArray[])
 

Aleksei Stepanenko:

string str="";

for(int r=0; r<31;r++)
   {
   LoY[r]=1.6104+r*0.0001;
   str+="--LoY["+IntegerToString(r)+"]--, "+DoubleToString(LoY[r],4)+", ";
   }
Print(str);


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 =+ instruct 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.

After 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.

 
Alexey Viktorov:

I don't remember exactly, and I'm too lazy to check. Try adding square brackets

I added square brackets void PrintArray(double &eArray[]) The compiler has not shown 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.

Thank you for your help and sorry for the inconvenience.

Reason: