Global Variables: what's wrong

 

Hi,


I am running the same EA on all wiindows to see its behaviour.

And to have the actual situation of all in every window I want to write a global Variable into each main Window by Comment.


So I wrote this littel function to set its value to the current state:

1. get the global-value

2. withdraw the window-old-value(oldProf => set only for this and here)

3. calc the actual value (oldProf = openPOS + recentRESULTS)

4. set new value res+oldProf


This function is called once (in all windows) when the 15 min Bar finishes an a new one is 'opened'.

It is iniciated in the init function by(your sample code):

if(!GlobalVariableCheck("globalPROFIT"))
GlobalVariableSet("globalPROFIT",0);


as a result I get different errors (?):

globResults GET: global variable not found
globResults GET: not initialized string in array
globResults GET: array index is out of range


Any suggestion where is myy fault?

Thanks in advance,

Carl


bool globalRESULT () {
if ( ENTRY > 0 ) {
double res = GlobalVariableGet("globalPROFIT");
int err = GetLastError();
if(err!=0) {
Alert("globResults GET: ",ErrorDescription(err));
return(false);
}
res -= oldProf; //
if ( POSITION > 0 ) {
oldProf = (Bid-ENTRY)/POINT + PROFIT;
} else if ( POSITION < 0 ) {
oldProf = (ENTRY-Ask)/POINT + PROFIT;
}
GlobalVariableSet("globalPROFIT",res+oldProf);
err = GetLastError();
if(err!=0) {
Alert("globResults SET: ",ErrorDescription(err));
return(false);
}
}
return(true);
}

 

GetLastError() retrieves the last known error. The errors you retrieved may or may not have anything to do

with your calling function.

Every time you call GetLastError(), it returns the last error number and then resets the last known error to zero --"no error".

Do a call to GetLastError() immediately before calling globalResult(), interpret the error code received, if any. It looks to me you have
errors in other sections of code.

That will "clear" old errors before you check for new errors in globalRESULT()

 
phy:

GetLastError() retrieves the last known error. The errors you retrieved may or may not have anything to do

with your calling function.

Every time you call GetLastError(), it returns the last error number and then resets the last known error to zero --"no error".

Do a call to GetLastError() before calling globalResult(), interpret the error code received, if any. It looks to me you have
errors in other sections of code.

That will "clear" old errors before you check for new errors in globalRESULT()

ok, thanks! Now it seems to work :)

gooly