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

 
Artyom Trishkin:
The help section tells you what it's for. And, yes, it is correct that a parameter entered by the user cannot be changed programmatically. At least something can belong to the user :)

If you really want to, you can)

 
Vitaly Muzichenko:

If you really want to, you can)

You can, of course, if you reassign it. But the value entered by the user will remain unchanged.
 

I often encounter a problem. The compiler swears with a "variable already defined" error on the code:

if (n<10)
 {
  int a=10;
 }
else
 {
  int a=5;
 }

The reference guide at https://docs.mql4.com/ru/basis/variables/local says:

Variables declared inside a block (on internal level) have the scope ofthe block.

If blocks are nested andthe identifier in the external block has the same name as the identifier in the internal block, the external block identifier is "invisible" (hidden) until the internal block completes.

But even the example from the same reference book does not compile with the same "variable already defined" error:

int i=5;      // локальная переменная функции
     {
      int i=10;  // переменная функции 
      Print("В блоке i = ",i); // результат  i = 10;
     }
   Print("Вне блока i = ",i);  // результат  i = 5;

Same problem with cycles:

int i=10;
for (int i=1;i<10;i++) ...

How can we get around this problem and make the directory example compile without the "variable already defined" error?

 
The_Sheikh:

I often encounter a problem. The compiler swears with a "variable already defined" error on the code:

The reference guide at https://docs.mql4.com/ru/basis/variables/local says:

Variables declared inside a block (on internal level) have the scope ofthe block.

If blocks are nested andthe identifier in the external block has the same name as the identifier in the internal block, the external block identifier is "invisible" (hidden) until the internal block completes.

But even the example from the same reference book does not compile with the same "variable already defined" error:

Same problem with cycles:

How can we get around this problem and make the directory example compile without the "variable already defined" error?

#property strict
 
The_Sheikh:

How can I get around this problem and get the directory example to compile without the "variable already defined" error?

not all examples in the reference book work correctly for a long time

by scope in your examples - visibility within a single operator is local, it should definitely work like this:

void OnStart()
  {
   for(int i=0;i<10;i++)
     {
      double x=i;
     }

   for(int i=0;i<10;i++)
     {
      double x=i;
     }
  }

i.e. visibility within a for statement is local, the i and x variables will be lost when you exit it

 

Tried to look for the last peak of Peak Repainter indicator to be processed by EA:

   GV_trendD1 = StringConcatenate(GVn," дневной тренд");
   if (!GlobalVariableCheck(GV_trendD1))
      {
      double   fUP,fDN;

      for (int f=0; f<=400 && !IsStopped(); f++)
         {
         fUP = iCustom(NULL,PERIOD_D1,"Used\\# Peak Repainter",0,f);
         if (fUP>=15) {GlobalVariableSet(GV_trendD1,1);break;}
         else {fDN = iCustom(NULL,PERIOD_D1,"Used\\# Peak Repainter",1,f); if (fDN>=15) {GlobalVariableSet(GV_trendD1,-1);break;}}
         }
      }

The result is that 1 is written to the global variable, even though it should actually be -1.

What is wrong? With the code? With the indicator?

The indicator is used with the default setting.

 
Alexey G. Smolyakov:

Tried to look for the last peak of Peak Repainter indicator to be processed by EA:

The result is that 1 is written to the global variable, even though it should actually be -1.

What is wrong? With the code? With the indicator?

The indicator is used with a default setting.

Why is the name of the indicator like that?

iCustom(NULL,PERIOD_D1,"Used\\# Peak Repainter",0,f);
 
Artyom Trishkin:

Why the name of the indicator?

I just keep indicators for different EAs in different directories. And I slightly rename them so that they are grouped.

Does the name affect anything?

 
Alexey G. Smolyakov:

I just keep the indicators for different EAs in different directories. And I slightly rename them so that they are grouped together.

Does the name affect anything?

It does, all access to files in МТ4 takes place inside MQL4 folder, exit from Expert Advisors/Scripts/Indicators outside this folder is excluded for security reasons

 
Igor Makanu:

affects, all access to files in MT4 takes place inside the MQL4 folder, exit from EAs/scripts/indicators outside this folder is excluded for security reasons

Full path of the MQL4 folder\Indicators\Used. It seems that there is no exit outside the folder. But this is an anomaly - other Expert Advisors work with their indicators in similar folders without problems. But what is the problem with this indicator - I do not understand it. I looked through its code but I did not have enough knowledge and experience to understand it. I have a suspicion that it only counts the last bar or something like that.
Reason: