Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 929

 
Why can't I add friends?
 
Hello. I'm trying to learn shared hosting following the instructions, but the EA won't open.
 

Can you tell me which of the pillars of Classical TA is the author of this picture?

This picture is in Elder's"Fundamentals of Trading". I am, in fact, interested in the same picture, but with CONVERGENCES, if it exists at all.


 

Help, please. A simple script and it doesn't work. I can't figure out why.

int awd1[];
void OnStart()
  {
   for(int i=0;i<=5;i++)
   {
   awd1[i]=i+10;
   }
   Alert("первый=");
  }

The loop has to iterate 6 times. At each iteration, a value should be assigned to the awd1 array. After the loop is finished, a window should pop up with the entry "first=". But it won't pop up. What is wrong?

 
silachara:

Help, please. A simple script and it doesn't work. Can't figure out why.

int awd1[];
void OnStart()
  {
   for(int i=0;i<=5;i++)
   {
   awd1[i]=i+10;
   }
   Alert("первый=");
  }

The loop has to scroll 6 times. At each iteration, a value should be assigned to the awd1 array. When the loop finishes, a box should pop up with the entry "first=". But it doesn't pop up. What is wrong?

This will also help to get rid of the following messages in the terminal: array out of range in ...:

#property strict
#define  ARRAY_SIZE  6
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
 int j=0, awd1[];
   ArrayResize(awd1,ARRAY_SIZE,ARRAY_SIZE+1);
//---
   for(int i=0;i<ARRAY_SIZE;i++)
     {
      j=i+10;
      //j=j+10;//или, к примеру, такой вариант вместо строки выше, чтобы вы посмотрели, что присваиваться будет
      awd1[i]=j;
     }
   Alert("первый = ");
  }
//+------------------------------------------------------------------+


P./S.: Here's a variant with a check:

#property strict
#define  ARRAY_SIZE  6
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
 int j=0, count=0, awd1[];
   ArrayResize(awd1,ARRAY_SIZE,ARRAY_SIZE+1);
//---
   for(int i=0;i<ARRAY_SIZE;i++)
     {
      j=i+10;
      //j=j+10;//или, к примеру, такой вариант вместо строки выше, чтобы вы посмотрели, что присваиваться будет
      awd1[i]=j;
      count++;
      Print("count = ",count,", awd1[",i,"] = ",awd1[i],", j = ",j);
     }
   Alert("первый = ");
  }
//+------------------------------------------------------------------+
 
silachara:
Slightly corrected the codes above so that the same value awd1[i] does not come out.
 
DiPach:
I slightly corrected the codes above to avoid the same value awd1[i].

Thank you!

So the array had to be declared by specifying the number of cells in it? Did this requirement appear after MT4 moved to build 600? Or it was like that before?

And I have one more problem: I cannot find the file where information from Print() is written. Please, advise me the way. I searched all directories of MT4, but have not found it.

 
silachara:

Thank you!

So the array had to be declared by specifying the number of cells in it? Did this requirement appear after MT4 moved to build 600? Or it was like that before?

The function for setting the size of a dynamic array ArrayResize also existed before the 600th build.

And so... with the updated MQL4 language the compiler has become stricter. If necessary, you may view the interesting information "at first hand", instead of the retelling of it with possible intentional distortion, including incomplete presentation, here. You may see it in the "Table of differences between compilers" of previous and updated MQL4 languages (the table is at the end of the first page of this thread) or use a search. As I remember, there was a lot of material on the transition to the updated MQL4 language.

 

silachara:

And one more problem: I can't find the file where the information from Print() is written to. Please, tell me the way. I searched all directories of MT4, but have not found it.

A quick way: Go to the"Experts" tab of the terminal -> right click on the tab -> click on"Open" in the menu that appears.

This will open a folder with log files containing entries from this tab, including those outputted via Print(). Below is a picture (I remembered, that I have this information in the form of visualisation):


P./S.: The same way you can quickly open a folder on your computer with log files of records from the terminal's"Log" tab (they are in a different folder).

 

DiPach , thanks again for your help. I have analysed your examples. Made some changes to my startup code. The result is this:

void OnStart()
  {
int awd1[];
ArrayResize(awd1,6,7);
   for(int i=0;i<=5;i++)
   {
   awd1[i]=i+10;
   Print("awd1[", i, "]=", awd1[i]);
   }
   Alert("awd1[0]=", awd1[0], ", awd1[1]=", awd1[1], ", awd1[2]=", awd1[2], 
   ", awd1[3]=", awd1[3], ", awd1[4]=", awd1[4], ", awd1[5]=", awd1[5]);
  }

What was changed:

1. I moved the line containing int awd1[]; array declaration inside OnStart() function

2. Added the ArrayResize(awd1,6,7) function;

3. The script works.

I will try to draw some conclusions. In scripts, it is correct to declare arrays inside the OnStart() function. After the array is declared, it must be necessarily defined in its size using the ArrayResize() function; otherwise the compiler will swear. Are my conclusions correct? If not, please give the correct interpretation.

Reason: