ChangeParameters()

Brief

The notification that the parameter set has been changed on the fly.

Details

Since SDK 2.0 the strategy parameters may be changed without the restarting of the strategy instance. In order to support this feature, the strategy must define two functions: CheckParameters and ChangeParameters().

The function is called to notify the strategy instance that the new parameter set has been applied. This function will be called before any other method, but only in case the previous call of the CheckParameters() function was successful.

At the moment when the function is called, the instance.parameters property is set to the new parameters. Please note that in case the function failed, the old parameter set will be restored.

The function must act as a Prepare() function, i.e. set the new name of the instance and prepare all the global variables, subscriptions and so on for further calls of the strategy instance with the new parameter set.

CheckParameter and ChangeParameters example [hide]

function Init()
    ...
    strategy.parameters:addInteger("T", "Test", "", 14, 2, 1000);
end
 
local T;
 
function Prepare(onlyName)
    instance:name(CheckParameters(instance.parameters));
    T = instance.parameters.T;
end
 
function CheckParameters(params)
    assert(params.T >= 2, "T must be greater than 2");
    return profile:id() .. "(" .. params.T .. ")";
end
 
function ChangeParameters()
    Prepare(false);
end
 
function Update()
    ...
end

back