Include Files

 

A few quick questions for experienced programmers about include files, when using .mqh include files, what do you do about variables declared in the main program on global scope ? By that I mean when attempting to compile an include file that references variables declared in the main program on the global scope the compiler doesnt want to compile it and I cant find any reference on how to handle that in the book are include files not supposed to be compiled individually ?

Does the compiler compile the include files into the main program when the main program is complied ?

If this is so does that mean the include files are not used at run time ?

I kinda wanted to create a seperate file to be used with an EA to contain trade criteria which could be changed without recompiling the EA, kind of like a plugin to the EA so in other words several different trade criteria files could exist and any 1 of them could be used with the EA, are include files not the way to go about doing this ?

 
  1. SDC:
    A few quick questions for experienced programmers about include files, when using .mqh include files, what do you do about variables declared in the main program on global scope ? By that I mean when attempting to compile an include file that references variables declared in the main program on the global scope the compiler doesnt want to compile it and I cant find any reference on how to handle that in the book are include files not supposed to be compiled individually ?
    // incl.mqh
    void f(){ Print(mainVariable); }
    // Main code
    double mainVariable;
    #include "incl.mqh"
    int start(){ f(); }
    Include files are not compiled individually, they are included into the compilation unit.
  2. SDC:
    Does the compiler compile the include files into the main program when the main program is complied ?
    yes.
  3. SDC:
    If this is so does that mean the include files are not used at run time ?
    The code has been compiled into the main. The include file isn't needed, isn't used until the next compile.
  4. SDC:
    I kinda wanted to create a seperate file to be used with an EA to contain trade criteria which could be changed without recompiling the EA, kind of like a plugin to the EA so in other words several different trade criteria files could exist and any 1 of them could be used with the EA, are include files not the way to go about doing this ?
    must recompile to include an include file. The alternate, would be to create a DLL that makes decisions - no compile of the main EA would be necessary but then you're using a separate language and have to install the DLL, don't have access to global variables etc.

Write a function that decides on trade conditions. If it doesn't work, rewrite the function and recompile.

Include files are normally used to factor out common code - One include file, multiple EA's. If you have to modify the code, you do it only once in the include and then recompile all EA's.

 

OK thanks WHR I think I'll stick to recompliling the EA with different criterias, creating dll's is a little out of my league at the moment lol

 
SDC:

A few quick questions for experienced programmers about include files, when using .mqh include files, what do you do about variables declared in the main program on global scope ? By that I mean when attempting to compile an include file

You don't compile include files at all. You just write them.

They are automatically included on the fly and compiled together with the main file.

 
WHRoeder:
  1. must recompile to include an include file. The alternate, would be to create a DLL that makes decisions - no compile of the main EA would be necessary but then you're using a separate language and have to install the DLL, don't have access to global variables etc.

No need for a DLL.

You can write .ex4 libraries, they are almost like dlls and used like dlls only written in mql4.

 

Ahhh thats what i need then .. I'll do some reading up .ex4 librarieI thanks 7bit

Reason: