Download MetaTrader 5

How to store values of variables to reuse after a reboot...

To add comments, please log in or register
Volcanbleu
92
Volcanbleu  

Hi guys,


I would like to to store values of certain variables to be able to reuse them in case of event of a reboot ...


The extern variables can be modified, but aparently they dont stay..


Thanks for your help

Yohana Parmi
3402
Yohana Parmi  
Volcanbleu:

Hi guys,


I would like to to store values of certain variables to be able to reuse them in case of event of a reboot ...


The extern variables can be modified, but aparently they dont stay..


Thanks for your help


Hi,

You can store it to the file https://docs.mql4.com/files

Good luck :)

File Functions - MQL4 Reference
File Functions - MQL4 Reference
  • docs.mql4.com
File Functions - MQL4 Reference
Kaleem Haider
140492
Kaleem Haider  
Volcanbleu:

Hi guys,


I would like to to store values of certain variables to be able to reuse them in case of event of a reboot ...


The extern variables can be modified, but aparently they dont stay..


Thanks for your help


You can also use global variables

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

Hi,

You can store it to the file https://docs.mql4.com/files

Good luck :)

Thanks Yohana,


Can you tell me what kind of file is easier to use for storind few variable numeric values for example. MQL4 file or CSV, or text file. How do you create a file from an EA.

Would you have an example of just create write new file and stroind 2 variables in it, and read it.

THANKS

Yohana Parmi
3402
Yohana Parmi  
Volcanbleu:

Thanks Yohana,

Can you tell me what kind of file is easier to use for storind few variable numeric values for example. MQL4 file or CSV, or text file. How do you create a file from an EA.

Would you have an example of just create write new file and stroind 2 variables in it, and read it.

THANKS


We can use any text file types, e.g CSV

Btw, you can find many examples there :)

One of them :

https://docs.mql4.com/files/filewrite

//--- open the file for writing the indicator values (if the file is absent, it will be created automatically)
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s file is available for writing",InpFileName);
      PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      //--- first, write the number of signals
      FileWrite(file_handle,sign_size);

Good luck :)

FileWrite - File Functions - MQL4 Reference
FileWrite - File Functions - MQL4 Reference
  • docs.mql4.com
FileWrite - File Functions - MQL4 Reference
Victor Ziborov
1922
Victor Ziborov  
Volcanbleu:

Hi guys,

I would like to to store values of certain variables to be able to reuse them in case of event of a reboot ...

The extern variables can be modified, but aparently they dont stay..

Thanks for your help

Yes, you can save your variables in a file. But there is another way, you can try to use global variables (do not confuse with external variables): GlobalVariableSet (), GlobalVariableGet (). Global variables are not destroyed on reboot. Global variables exist in the client terminal for 4 weeks after the last access. Best wishes.
Volcanbleu
92
Volcanbleu  
Victor Ziborov:
Yes, you can save your variables in a file. But there is another way, you can try to use global variables (do not confuse with external variables): GlobalVariableSet (), GlobalVariableGet (). Global variables are not destroyed on reboot. Global variables exist in the client terminal for 4 weeks after the last access. Best wishes.

Thanks Victor very much,


This much nicer. So it means that the global variables are stored somewere, right ?

To add comments, please log in or register