Self-learning the MQL5 language from scratch - page 39

 
MrBrooklin:

Yes, the opening and closing brackets converge vertically after "Styling", but the backlight either doesn't understand what it is, or I can't see it. The level of programming skill, at the moment, is near zero.

Regards, Vladimir.

the highlighting is a lit bracket first after the title of the function, it should be lit in pair with the bottom one, i.e. each bracket should have a pair, they are lit, if not, it means there is a missing closing bracket

 
Fast235:

the highlighting is the lit bracket first after the function header, it should be paired with the bottom bracket, i.e. each bracket should have a pair, they are lit, if not, then the closing bracket is missing

Thanks for the hint. It turns out they are not highlighted on my screen, but highlighted by the thickness. Yes all the brackets are there. Now, just moved the function block behind the bottom OnStart bracket and the errors have disappeared. Thank you for your help!

Regards, Vladimir.

 
MrBrooklin:

Thanks for the tip. It turns out they are not highlighted on my screen, but stand out in thickness. Yes, all the brackets are there. Now, just moved the function block behind the bottom OnStart bracket and the errors have disappeared. Thank you for your help!

Regards, Vladimir.

All functions are declared in the global scope, i.e. outside the space of other functions, which is limited by their brackets.
 
Реter Konow:
All functions are declared in the global scope, i.e. outside the space of other functions, which is bounded by their parentheses.

Dear Peter, tell us how you managed to create your so-called markup language (), it will be useful for newcomers, and I need it to develop logical thinking, which is very important here

maybe something ate a lot, climbed a tree
 
MrBrooklin:

Good evening all!

Dear programming experts, could you please tell me what does the error the compiler generates mean:" function declarations are only allowed in global, namespace or class area", or to be more specific, what is a namespace and where should it be located in the script?

The question is related to writing function code for "Enough_time" and "Enough_patience".

Regards, Vladimir.

Global Area, the area outside of functions. It makes no difference where, you can between functions, I hope you understand where they begin and end, you can do everything you can in the global scope, declare global variables, properties or whatever. Variables declared in the global scope are visible everywhere, literally. Local scope is the area from the beginning to the end, closing curly braces, of the function. Variables declared in the local area are only visible in this area.

Please note that the code is read from top to bottom and from left to right. The compiler doesn't rearrange strings. So, the rule is that a variable is always declared above or to the left of the reference to it. And only in its own scope. In different local areas variables can have the same names. And by the way loops and if they are functions with their own areas too)

 
Valeriy Yastremskiy:

The global scope, the area outside of functions. and it makes no difference where, you can between functions, I hope you understand where they start and end, you can do everything in the global scope at the end, declare global variables, properties or whatever. Variables declared in the global scope are visible everywhere, literally. Local scope is the area from the beginning to the end, closing curly braces, of the function. Variables declared in the local area are only visible in this area.

Please note that the code is read from top to bottom and from left to right. The compiler doesn't rearrange strings. So, the rule is that a variable is always declared above or to the left of the reference to it. And only in its own scope. In different local areas variables can have the same names. (And by the way loops and if they are functions with their own scopes too)

we should write a book. together all of us

 
Реter Konow:
All functions are declared in the global scope, i.e. outside the space of other functions, which is limited by their parentheses.

Thank you, Peter! I have already been helped to understand this issue.

I am continuing my study of MQL5 programming language and today I am pasting the code of a script, which is a continuation of one of the tasks from the participants of this thread. I tested the script in all modes. Everything works as it should. I have set the input parameters to a minimum to begin with.

Regards, Vladimir.

//+------------------------------------------------------------------+
//|                                                Learning_MQL5.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
#property script_show_inputs
//--- Зададим входные параметры скрипта 
input ushort Период_обучения=500; //Полный период обучения в днях
input ushort Прошло_дней=10;      //Сколько дней прошло с начала обучения
input bool   Терпение=true;       //Терпение (true - достаточно; false - не достаточно)
//--- Зададим глобальные переменные
ushort Достаточность_времени;
bool Достаточность_терпения;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   if(Достаточно_времени()==0 && Достаточно_терпения()==true)
     {
      Print("Я выучу язык MQL5!");
     }
   else
     {
      Print("Я не выучу язык MQL5!");
     }
  }
//--- Создадим функцию Достаточно_времени
ushort Достаточно_времени()
  {
   Достаточность_времени=(Период_обучения-Прошло_дней);
   return(Достаточность_времени);
  }
//--- Создадим функцию Достаточно_терпения
bool Достаточно_терпения()
  {
   Достаточность_терпения=Терпение;
   return(Достаточность_терпения);
  }
//+------------------------------------------------------------------+
 
MrBrooklin:

Thank you, Peter! I have already been helped to understand this issue.

I continue studying the MQL5 programming language and today I am pasting the code of a script, which is a continuation of one of the tasks from the participants of this thread. I tested the script in all modes. Everything works as it should. I have set the input parameters to a minimum to begin with.

Sincerely, Vladimir.

Structurally, the functions are written correctly, but the logic is lame. Look at all the code carefully.

The result of the Sufficient_time() function should be greater than zero, which was a logical condition.
 
MrBrooklin:

Thank you, Peter! I have already been helped to understand this issue.

I am continuing my study of MQL5 programming language and today I am pasting the code of a script, which is a continuation of one of the tasks from the participants of this thread. I tested the script in all modes. Everything works as it should. I have set the input parameters to a minimum to begin with.

Regards, Vladimir.

Describe (write) what your script does. And it's always better to do it at the beginning. The target, why. What tasks can achieve the goal. How the tasks can be solved, the algorithms for solving them and then the code. And by the way, the division of tasks is decomposition)

 
Fast235:

We should write a book. Together we should all

This question is long overdue. Sergey Kovalev has written a manual for the MQL4 programming language. Now another expert has to be inspired to do this noble deed for MQL5.

Best regards, Vladimir.