For easier editing I was thinking to load default, min, max and step parameters values from a file based on trading pair. I was able to implement this and it's working, it loads params from file based on which chart I drop it (although unfortunately it doesn't update params if I then switch the trading pair).
...but now I'm having second thought about how fast this will be or if it will slow down long optimizations.
Could anyone confirm, will code bellow load the file for every optimization step?
Will it have impact on performance in any other way?
Also I'm not 100% sure, will optimization even be able to pick up the correct values for each step it has to perform?
Anyone spots anything else wrong with the code?
tradingPair = Name();
tradingAsset = StrExtract(tradingPair, 0, separator = '/');
tradingCurrency = StrExtract(tradingPair, -1, separator = '/');
optimization_folder = "optimization/";
fh = fopen(optimization_folder + "params_" + tradingAsset + "_" + tradingCurrency + ".csv", "r" );
if(!fh){
fh = fopen(optimization_folder + "params_default.csv", "r" );
if(!fh){
Error("No file");
}
}
for(i = 0; !feof(fh); i++){
line = fgets( fh );
//skip header line
if(i == 0){
continue;
}
paramName = StrExtract(line, 0);
StaticVarSet(paramName, ParamOptimize(
paramName,
StrToNum(StrExtract(line, 1)),
StrToNum(StrExtract(line, 2)),
StrToNum(StrExtract(line, 3)),
StrToNum(StrExtract(line, 3)),
StrToNum(StrExtract(line, 5))
));
}
fclose(fh);
//now we can access UI/optimization params via static variable
myParam = StaticVarGet("myParamNameInFile");
The code above is used to feed inputs of ParamOptimize function (combines native Optimize and Param functions) which then allows me to use the same code for UI and optimization parts + toggle optimization on/off with last param (optimization_enabled). Here is the code
function ParamOptimize(pname, defaultval, minv, maxv, step, optimization_enabled)
{
r = Param(pname, defaultval, minv, maxv, step);
if(optimization_enabled){
r = Optimize(
pname,
r,
minv,
maxv,
step);
}
return r;
}