Why GlobalVariableGet() does not work in this code?

 

Hi,

I have an array BuyClosePrice[i][x] which "x" dimension represents the symbol in this multi currency EA, and "i" dimension represents the position between that same symbol closed orders(through Buys).
I set GVs by this code:

GlobalVariableSet(("BuyClosePrice["+IntegerToString(i)+"]["+IntegerToString(x)+"]"),BuyClosePrice[i][x]);

I use two for loops to fill proper i and x into my array, and it shows no error. But when I try to retrieve those values by this code:

GlobalVariableGet(("BuyClosePrice["+IntegerToString(i)+"]["+IntegerToString(x)+"]"),BuyClosePrice[i][x]);

it returns me this error
'GlobalVariableGet' - no one of the overloads can be applied to the function call
could be one of 2 function(s)
   built-in: double GlobalVariableGet(const string)
   built-in: bool GlobalVariableGet(const string,double&)

in the MQL4 documentation it says GlobalVariableGet( string GV name, double variable), but it does not accept my GlobalVariableGet function. Where am I wrong?
It is hurting me :(

 
bool ok = GlobalVariableGet( "BuyClosePrice["+IntegerToString(i)+"]["+IntegerToString(x)+"]" , BuyClosePrice[i][x]);

This should do it. Note you don't need to put parentheses around the string expression, it works without.

Always query the return value of every function you call, if possible, and use proper error handling.


HosseinKOGO:

Your advice is greatly appreciated

It would be fair to give a nod to William's answers in your other threads, even if just to confirm that your topic was addressed.

 
lippmaje #:

This should do it. Note you don't need to put parentheses around the string expression, it works without.

I've tried it as you mentioned but it still returns same error:

         bool OK=GlobalVariableGet(("BuySL["+IntegerToString(i)+"]["+IntegerToString(x)+"]"),BuySL[i][x]);
         if(OK==true){Print("Got GV");}
         else{Print("GV get failed");}
lippmaje #:

It would be fair to give a nod to William's answers in your other threads, even if just to confirm that your topic was addressed.

Him and others in these forums have taught me whole things I know now, your effort is priceless to me and I always thankful to all of you <3
And I do agree, I will do your suggestion.

 
HosseinKOGO:

Hi,

I have an array BuyClosePrice[i][x] which "x" dimension represents the symbol in this multi currency EA, and "i" dimension represents the position between that same symbol closed orders(through Buys).

How do you declare this array? It may be obvious but bugs are often hidden under 'obvious' things. 

Always post as much code as is required for anyone to test it in their editor, and hopefully get the same error.

The forum may appear quiet sometimes but it is read by many skilled coders. 

 
lippmaje #:

How do you declare this array? It may be obvious but bugs are often hidden under 'obvious' things. 

Always post as much code as is required for anyone to test it in their editor, and hopefully get the same error.

The forum may appear quiet sometimes but it is read by many skilled coders. 

Happy to see you here again.

You exactly pointed to my mistake!
I had many GVs and the problem was from my BuyCloseTime array which was datetime rather than double.
So I've defined BuyCloseTimeDouble[i][x] = (double) BuyCloseTime[i][x];
And it worked! No error, No warning.
Now I have a question, may I lose data due to conversion from datetime to double?

Thank you for your help

 
HosseinKOGO #:

Now I have a question, may I lose data due to conversion from datetime to double?

A double will be able to hold a 52-bit integer value without rounding bits away during casting.


So this allows for all datetimes to be safely converted to/from double.

 
lippmaje #:

A double will be able to hold a 52-bit integer value without rounding bits away during casting.


So this allows for all datetimes to be safely converted to/from double.

Thank you pal <3

Reason: