In the script, you can get the parameters by referring to the script fields (OptimProperty). Or through the ctx.Runtime.GetParameters () method, it returns the entire list of parameters. But it works correctly with a normal script run. During optimization, there will be parameters with irrelevant data. Value is always equal to the initial value of the parameter.
If you need to get script parameters from the code of another indicator, you can proceed as follows: The context has a script object (ctx.ScriptObject through the ContextExecutor class), so you can get the parameters through reflection.
Sample code:
usingSystem.ComponentModel;usingTSLab.Script;usingTSLab.Script.Handlers;usingTSLab.Script.Handlers.Options;usingTSLab.Script.Optimization;namespaceMyLib.Handlers{ [HandlerCategory("MyLib")] [HelperName("TraceScriptParameters", Language =Constants.En)] [HelperName("TraceScriptParameters", Language =Constants.Ru)] [InputsCount(1)] [Input(0,TemplateTypes.SECURITY, Name ="SECURITYSource")] [OutputsCount(0)] [OutputType(TemplateTypes.DOUBLE)] [Description("Lists parameters")]publicclassTraceScriptParameters:IStreamHandler,ISecurityInputs,IContextUses {publicIContext Context { get; set; }publicvoidExecute(ISecurity source) {var ctx = Context asTSLab.ScriptEngine.ContextExecutor;if (ctx ==null)return;Context.Log("=== Parameters ===",MessageType.Info,true);var fields =ctx.ScriptObject.GetType().GetFields();foreach (var field in fields) {var obj =field.GetValue(ctx.ScriptObject);var value =GetValue(obj);Context.Log($"{field.Name}={value}",MessageType.Info,true); } }privateobjectGetValue(object obj) {switch (obj) {caseOptimProperty pDouble:returnpDouble.Value;caseIntOptimProperty pInt:returnpInt.Value;caseBoolOptimProperty pBool:returnpBool.Value;default:returnnull; } } }}