Calling other program functions

 

I have an expert running , how can i call its functions  from a script without the #import.

Expert:

void MyFunction(){
        Print("Hello");
}

void OnInit(){
        
}
void OnTick(void){
}

Script:

void OnStart(void){
        //Call MyFunction here ...

}
 

A better question i guess would be how can an expert and script share functions or even more same global variables.

Thanks for Help

 

I don't think it is possible to call an expert internal function, from a script. 

Expert and scripts have different purposes, and runs differently on the ambient. 


Global variables can be shared between them, considering they a running on the same window. 

 
rrocchi: Global variables can be shared between them, considering they a running on the same window. 

I would like to correct some semantics with your statement to prevent misunderstanding by readers.

Globally scoped variables cannot be shared between Scripts, EAs or Indicators.

However, Global Terminal Variables can be accessed by any EA, Script or Indicator running on the same terminal.

Documentation on MQL5: Global Variables of the Terminal
Documentation on MQL5: Global Variables of the Terminal
  • www.mql5.com
Global Variables of the Terminal - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro:

I would like to correct some semantics with your statement to prevent misunderstanding by readers.

Globally scoped variables cannot be shared between Scripts, EAs or Indicators.

However, Global Terminal Variables can be accessed by any EA, Script or Indicator running on the same terminal.

Thank you Fernando. I was thinking about Global Terminal when I replied.  

 
rrocchi:

I don't think it is possible to call an expert internal function, from a script. 

Expert and scripts have different purposes, and runs differently on the ambient. 


Global variables can be shared between them, considering they a running on the same window. 

Yes I know global variables can be shared but not the way I want, imagine for example I have declared : int var = 10 in some program as a global variable, how can I get access to it itself without using global functions of course 

 
Guerriex:
Yes I know global variables can be shared but not the way I want, imagine for example I have declared : int var = 10 in some program as a global variable, how can I get access to it itself without using global functions of course 

Since the program is compiled, and the variable is compiled inside it, I don't think it is possible to access the variable from the outside. 

As far as I know.. 


But if there is such a way, it is beyond my knowledge. 

 
Guerriex: Yes I know global variables can be shared but not the way I want, imagine for example I have declared : int var = 10 in some program as a global variable, how can I get access to it itself without using global functions of course 

You cannot get access to any function or variable declared within a MQL program (EA, Script or Indicator) from "outside" its scope.

MQL programs do not have any way of dynamically exporting variables or functions from within its programs.

 
Fernando Carreiro #:

You cannot get access to any function or variable declared within a MQL program (EA, Script or Indicator) from "outside" its scope.

MQL programs do not have any way of dynamically exporting variables or functions from within its programs.

What about export functions? I think the reference library says that is possible to access from outside the program that created it.

 
Boyifx Boyifx #:What about export functions? I think the reference library says that is possible to access from outside the program that created it.
Those are for use as static libraries, not from other actively running programs.
 
Boyifx Boyifx #:

What about export functions? I think the reference library says that is possible to access from outside the program that created it.

Actually, you can load any .ex5 file as a library. All functions declared with the keyword "export" are calable from your program. But just as Fernando said, you cannot get the values from a running program, the ex5 file is loaded into the context of the loading process, and has no connection to any other processes.

You will get new instances of the variables declared inside the library. This is also true for DLLs.

If you require shared access, you need to make the data available via some external mechanism like global terminal variables, files or other appropriate methods.

EDIT:

And you are required to do an "#import" declaration for the functions, you want to utilize from the ex5 file.