MQL4 handles environment setting files for each account.
- Donwload Env.mqh and defines.mqh
- Save the file to /MQL4/Include/mql4_modules/Env/
- Make a file (.txt or .ini) in /MQL4/Files/
- Write the setting in the form of key = value in the created text file.
API_TOKEN=123456890-hogehogehoge
ACCOUNT=123
IS_DEBUG=true
- Includes Env.mqh
- Read the configuration file.
- Acquire value from environment setting file.
To get the value, execute the get method.
string api_token = Env::get<string>("API_TOKEN");
Env::get (initial value if key, key does not exist).
Initial value can be omitted.
If the initial value is omitted and a key does not exist, a value equivalent to NULL or NULL is returned.
To get the bool type value, execute the getBoolValue method.
#property strict
#include <Env.mqh>
int OnInit(){
Env::loadEnvFile("sample.ini");
Comment("API_TOKEN = ", Env::get<string>("API_TOKEN"), "\n",
"USER_NAME = ", Env::get<string>("USER_NAME", "MQL4"), "\n",
"ACCOUNT = ", Env::get<int>("ACCOUNT", 0), "\n",
"IS_DEBUG = ", Env::getBoolValue("IS_DEBUG", false));
return(INIT_SUCCEEDED);
}
void OnTick(){
}