How to add a custom config setting?

NQuotes has a built-in XML config file - nquotes.config - that is located at “%TERMINAL_DATA_PATH%\MQL4\nquotes.config”. Read more about it here.

It is possible to use this file to add your own custom settings for your EA such as a database connection string.

Steps

Consider the MovingAverageExpert example. Let’s say you’d like to have the MovingPeriod and MovingShift values in a config file that can be modified after compilation.

1. Add the settings to the nquotes.config file inside the appSettings section:

...
<add key="MovingPeriod" value="12" />
<add key="MovingShift" value="6" />
...

2. Create a helper method in your EA class that will load the contents of your config file:

private static NQuotes.Config LoadConfig()
{
	string libDirPath = NQuotes.ConfigSettings.SharedSettings.LibraryDirPath;
	string configFilePath = NQuotes.Config.FindFilePath(libDirPath);
	return new NQuotes.Config(configFilePath);
}

3. Parse values from the config file in the EA init() method:

int MovingPeriod = 12;
int MovingShift = 6;

public override int init()
{
	var config = LoadConfig();
	this.MovingPeriod = int.Parse(config.Get("MovingPeriod"));
	this.MovingShift = int.Parse(config.Get("MovingShift"));
	return 0;
}

You can then pass these variables to the iMA() function.