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

 
evillive:

As a follow-up, since the others are only bitching and not going to poke their noses in...

Since variables are declared inside a function, they are not GLOBAL variables, just for future reference, in case you really need to write working code. Global variables are declared outside of functions, at the beginning of code for example.

That's what I mean:

In this form, the function does nothing and works in a vacuum. The results disappear right after the function finishes working (this is exactly what Artem and Victor hinted at above).


But after removing this function, I get a warning that expressions are not allowed in global variables. That is why I wanted to split the whole code into several include files: all variables used in the code are declared and calculated in one of them; another one sets conditions for opening orders and the rest of them separately sets closing conditions for buy and sell. Maybe, it is silly, but I thought it would be easier to find and correct errors this way.

Although they are not really global variables, will they pass their values to the if-else statement which my code is based on? And if the results disappear when the function finishes, and the compiler generates an error without the function, so can't I just move the global variables to a separate file?

And about banter - let the guys have fun: it's tiresome to read nonsense from newbies all the time, right?

 
Gentlemen programmers, is everything taught nowadays so that examples in the textbook compile with an error message? What's the use of such an example then? How can I write code correctly if the examples I'm referring to are NOT correct?
 
rapid_minus:
Gentlemen programmers, is everything taught nowadays so that examples in the textbook compile with an error message? What's the use of such an example then? How will I be able to write code correctly if examples I am guided by are NOT correct?
There are also examples in kodobase, those seem to compile without errors.
 
rapid_minus:


But when I remove this function, I get a warning that expressions are not allowed in global variables. And that is why I wanted to split the entire code into several include files: one of them declares and calculates all variables used in the code, another one sets conditions for opening orders and the rest of them separately sets closing conditions for buy and sell. Maybe, it is silly, but I thought it would be easier to find and correct errors this way.

Although they are not really global variables, will they pass their values to the if-else statement which my code is based on? And if the results disappear when the function finishes, and the compiler generates an error without the function, so can't I just move the global variables to a separate file?

And about banter - let the guys have fun: it's tiresome to read nonsense from newbies all the time, right?

No one said that the function must be removed, we should move the declaration of variables out of the function, at the beginning of the code. Or even declare them in the main file.
 
evillive:
No one said that the function should be removed, it should be declared outside the function, at the beginning of the code. Or declare them in the main file altogether.

You said above that the results disappear when the function finishes. But I can't remove assigning values to variables from the function body - the compiler generates errors. Does it turn out, that I've assigned values to variables in the function, but when I turn on the file with them, these values won't be read and the compiler frowns again? I.e., I cannot write the include file code from global variables only?
 
rapid_minus:

You said above that the results disappear when the function finishes. But I can't remove the assignment of values to variables from the body of the function - the compiler swears by errors. Does it turn out, that I've assigned values to variables in the function, but when I turn on the file with them, these values won't be read and the compiler will complain again? I.e., I cannot write the include file code from global variables only?

Here's what I wanted to say:

//|Включаемый файл "Глобальные переменные"                           |
//+------------------------------------------------------------------+
//-----Объявляем Глобальные переменные:------------------------------------------

double High_0, High_1, High_2;             // Значение верхней линии Bollinger на 0, 1 и 2 барах
   double Low_0, Low_1, Low_2;                // Значение нижней линии Bollinger на 0, 1 и 2 барах
   double Delta_0, Delta_1;                   // Разница межу значениями верхней и нижней ...
                                              // ...линий Bollinger на 0 и 1 барах

void  Variables()
{

High_0=iBands(NULL,0,10,2,0,PRICE_CLOSE,MODE_UPPER,0);
     High_1=iBands(NULL,0,10,2,0,PRICE_CLOSE,MODE_UPPER,1);
     High_2=iBands(NULL,0,10,2,0,PRICE_CLOSE,MODE_UPPER,2);
     Low_0=iBands(NULL,0,10,2,0,PRICE_CLOSE,MODE_LOWER,0);
     Low_1=iBands(NULL,0,10,2,0,PRICE_CLOSE,MODE_LOWER,1);
     Low_2=iBands(NULL,0,10,2,0,PRICE_CLOSE,MODE_LOWER,2);
     Delta_0=(High_0-Low_0);
     Delta_1=(High_1-Low_1);
}
//------------------------------------------------------------------------------------------
 
evillive:

Here's what I wanted to say:

:)

"... SOS! Here's a snippet of the included global variables file. The rest of it is exactly the same.

I did everything I could: changed parameters, removed variables from file individually and in groups to find error - all in vain:

"not all control paths return a value" warning. What is the reason then? ..."

Strictly in a spiral back to the first post of the applicant.

 
tara:

:)

"... SOS! Here's a snippet of the included global variables file. The rest of it is exactly the same.

I did everything I could: changed parameters, removed variables from file individually and in groups to find error - all in vain:

"not all control paths return a value" warning. What is the reason then? ..."

Strictly in a spiral back to the first post of the applicant.

And if you look closely? There's one little nuance that I still can't get through to him...

P.S.: int to void corrected.

 
evillive:

How about a closer look? There is one little nuance that I still can't make him understand...

P.S.: I corrected int to void.


Yes, I fixed it, but you, as far as I understood your last post, again returned int ?

ZS: I saw the correction, but now I don't understand anything... Well, you left assignment of values in function, but they disappeared (see above)?

 
evillive:

How about a closer look? There is one little nuance that I still cannot get through to him...

P.S.: corrected int on void.

He should reread the textbook by Kovalev, at least in terms of program structure and data visibility.

And no inludes and other magnetism.

Reason: