Error in GlobalVariableSet function

 

Hello every one,

I have a error in MQL5 and i would like to get the helpful.

I make the code to save the global variable in MQL5 and it have an error #5040 by the function GetLastError(). In MQL4 i don't have any problem.

This is the code:

string GVar_Info;

double Fibo_Signal;

int OnInit()

{

//---

 //Take SYMBOL_GLOBAL VARIABLES VALUE

      GlobalVariableGet(GVar_Info,Fibo_Signal);

      Print("Get GlobalVariable error #",GetLastError());

//---

   return(INIT_SUCCEEDED);
}


void OnTick()

  {

 //Setup SYMBOL_GLOBAL VARIABLES VALUE
 
      GlobalVariableSet(GVar_Info,Fibo_Signal);
      Print("Set GlobalVariable error #",GetLastError());

   return;

  }

I don't know why this function have the problem. Please help me how can i set the global variable in MQL5?

Thank you.

Regards,

Tran Le


 
Tran Le: I have a error in MQL5 and i would like to get the helpful. I make the code to save the global variable in MQL5 and it have an error #5040 by the function GetLastError(). In MQL4 i don't have any problem. This is the code: I don't know why this function have the problem. Please help me how can i set the global variable in MQL5?

In your code above, you never assign any text to the variable "GVar_Info", so obviously you can't get any Global Terminal Variable for it, and hence the wrong/damaged string parameter.

Always look up the error number to find out what the meaning of it (and remember to reset the error code before the function you want to check) ...

ERR_WRONG_STRING_PARAMETER

5040

Damaged parameter of string type

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors
  • www.mql5.com
Runtime Errors - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

In your code above, you never assign any text to the variable "GVar_Info", so obviously you can't get any Global Terminal Variable for it, and hence the wrong/damaged string parameter.

Always look up the error number to find out what the meaning of it (and remember to reset the error code before the function you want to check) ...Hi 

Hi Fernando,

Thanks for your helping soon. I has seen the guide that you showed. But my problem is i don't know the right function to get the global variable in MQL5. In my code, what is wrong? i can't find it. Please tell me the right code in the GlobalVariableSet and GlobalVariableget functions

 
Tran Le #:Hi Fernando, Thanks for your helping soon. I has seen the guide that you showed. But my problem is i don't know the right function to get the global variable in MQL5. In my code, what is wrong? i can't find it. Please tell me the right code in the GlobalVariableSet and GlobalVariableget functions

I've already answered that in your code you don't assign any value to "GVar_Info". It is empty. How do you expect to find something that is unknown?

string GVar_Info = "Give_it_a_name"; // Give the global variable a name
 
Fernando Carreiro #:

I've already answered that in your code you don't assign any value to "GVar_Info". It is empty. How do you expect to find something that is unknown?

Hi Fernando,

Thank you so much, finally i got it.

That only is  don't have the name, but it took me 1 week. 

Thanks so much again for your supported.

Best Regards,

Tran Le