Noob question.

 

hi guys.

Let say I have two files: file1 and file2. In file1, I have a value call int a. Is it possible for me to access the int a when i'm working with file2? I'm still new to coding so any help would be appreciated.

 

Hi nguye,

Where do you define a?
Are file1 and file2 include each other or vise versa?

If possible please post snippets of your code using the SRC button above.

 

uhmm For example, let say in file1.mq4 the code is:

double arrayofvalue[];

int start()

{

..........

dummie();

return(0);

}

void dummie(){

double i=0;

double a=0;

...........

arrayofvalue[i] = a;

}

Is there anyway for me to access the value of arrayofvalue[i] in the dummie() when i'm working in different file? I want to compare it with another value inside file2.mq4. I'm sorry if it sound confusing. I just learn how to code recently.

 

Hmm, I think I know what you mean.

Generally any indicator/EA/script cannot access the variables of another. But there are ways you can get around it. I know of these two ways, maybe there are more.

1) Use a global variable: https://book.mql4.com/variables/globals. Global variables are always doubles, so you can store an int like this (but not strings).

2) file1 writes the variable to a .CSV file on your harddisk using FileOpen, FileWrite ect. and file2 then opens that file and reads the variable. This is fine if the variable will not change very often, or very suddenly.