Structures and errors

Adriano Gigliuto
1105
Adriano Gigliuto  

Hello, 

I have some trouble with MQL4's structures. I tried to write a code with structure and I took as example the following:

https://docs.mql4.com/basis/operations/other#operation_dot

  struct SessionTime
     {
      string sessionName;
      int    startHour;
      int    startMinutes;
      int    endHour;
      int    endMinutes;
     } st;
   st.sessionName="Asian";
   st.startHour=0;
   st.startMinutes=0;
   st.endHour=9;
   st.endMinutes=0;

I wrote my code in the same way, but if I try to compile, I get the following error: "declaration without type". Here there's the source:

struct EAsGV{
   int param1;
   double price;
   bool IsStopButtonPressed;
}file;

file.IsStopButtonPressed = false;
file.price = 0.0;
file.param1 = 10;

And here there're the errors that gaves me the compiler

Errors

Where is the problem?

Other Operations - Operations and Expressions - Language Basics - MQL4 Reference
Other Operations - Operations and Expressions - Language Basics - MQL4 Reference
  • docs.mql4.com
-1. In particular case, for a one-dimensional array consisting of 50 elements, the reference to the first element will look like array [0], that to the last element will be array [49]. Calling Function with x1, x2 ,..., xn Arguments Each argument can represent a constant, variable, or expression of the corresponding type. The arguments passed...
Anthony Garot
5427
Anthony Garot  
Usernamelessss:

I wrote my code in the same way, but if I try to compile, I get the following error: "declaration without type". Here there's the source:

Move the assignments into OnStart() or OnInit().

By assignments I mean:

file.IsStopButtonPressed = false;
file.price = 0.0;
file.param1 = 10;
William Roeder
25088
William Roeder  
Either do the assignments inside a function, or define a constructor
struct EAsGV{
   EAsGV(int p1, double pr, bool st) : param1(p1), price(pr), IsStopButtonPressed(st){}
   int param1;
   double price;
   bool IsStopButtonPressed;
} file(10, 0, false);
Adriano Gigliuto
1105
Adriano Gigliuto  

That's great! Thanks both of you for the replies. Now I have no error