How to pass variables from and to (Exported Library)?

 

Hi.

I am building my everyday functions library, so I will include it in all my projects ( I dont know which one I should choose:  include or library filetype)...

However, many functions need to use some specific GLOBAL variables from the main indicator....


For example, in my main indicator i have:

double my_Day, my_Session, my_Endtime ......and many different variables..

void OnInit(){

double my_Day= SymbolInfoDouble(......);

double my_Session= SymbolInfoDouble(......);

......and many different declarations..

}

#import "stdlib.ex5" 

string MyFunc(bool StartTredline); 

#import



and in MyFunc function (inside Library file) I use those variables (my_Sessionmy_Endtime, and many others).


Is there any way to pass GLOBAL variables directly, without passing them as parameters everytime, like :


MyFunc(StartTrendline, my_Day, my_Session....... and many more)


instead, I called MyFunc(StartTrendline)

and it could read the GLOBAL variables from main indicator?



(In contrary, how can I access global variable, set in library file..)

 
selnomeria: Is there any way to pass GLOBAL variables directly, without passing them as parameters everytime,
Pass them once, have the library remember the values.
 
If your library is for internal use only, you can implement it completely in a header file. Then there will be no need to have a library as an external compiled file. Then you can just include the header, and all common variables will be available in the global context.
 
Stanislav Korotky:
If your library is for internal use only, you can implement it completely in a header file. Then there will be no need to have a library as an external compiled file. Then you can just include the header, and all common variables will be available in the global context.

Thanks guys.


To clarify again,  I decided to make 1 single file (where I combine my functions), and include that in every indi, instead of putting those functions one-by-one in all my indis..

how to do that? I mean coding part.  

 
selnomeria:

Thanks guys.


To clarify again,  I decided to make 1 single file (where I combine my functions), and include that in every indi, instead of putting those functions one-by-one in all my indis..

how to do that? I mean coding part.  


Create an include file i.e. MyVariables.mqh

int var1 = 3;
double var2 = 10.2;
double func() { return(var1*var2); }

Then in your code (scripts, indicators, EAs):

#include <MyVariables.mqh>

void OnStart()
  {
   Print(var1);
   Print(var2);
   Print(func());
  }
 
honest_knave:


Create an include file i.e. MyVariables.mqh

Then in your code (scripts, indicators, EAs):


THANKSSSSSSSSSSSSSSSSSS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Reason: