The control panel can accommodate indicator values, buttons, text.
Create control panel:
var controlPane = ctx.CreateControlPane("Control", "Control", "My control");
The first "Control" element is the unique id of the element.
The second "Control" element is the name of the panel
The third element "My control" is the panel title, if it is not specified, the value will be taken from the panel title.
Add item to control panel:
var pane =controlPane.AddControl("SMA","",ControlParameterType.NumericUpDown,true,0,0,double.NaN,double.NaN,false,false,null, Period);
"SMA" - item name
"" - property name, if empty, the name of the last variable will be taken, in this case Period.
ControlParameterType.NumericUpDown - the type of the item, in this case the number with the control.
Period - OptimProperty script parameter
Example:
Let's add an SMA indicator and a control panel. Display the indicator value on the control panel. When the value changes, the script will be recalculated and the SMA indicator will change.
usingTSLab.Script;usingTSLab.Script.Control;usingTSLab.Script.Handlers;usingTSLab.Script.Helpers;usingTSLab.Script.Optimization;namespaceMyLib{publicclassTestControlPanel:IExternalScript {publicOptimProperty Period =newOptimProperty(100,100,1000,50);publicvoidExecute(IContext ctx,ISecurity sec) { // Create an SMA indicatorvar sma =ctx.GetData("SMA",new[] { Period.ToString() }, () =>Series.SMA(sec.ClosePrices, Period)); // Create a control panelvar controlPane =ctx.CreateControlPane("Control","Control","My control"); // Add the indicator period to the control panelvar pane =controlPane.AddControl("SMA","",ControlParameterType.NumericUpDown,true,0,0,double.NaN,double.NaN,false,false,null, Period); // When you change the indicator on the control panel, the script will be recalculatedpane.IsNeedRecalculate=true; // Drawing the SMA indicator on the chartctx.First.AddList("SMA", sma,ListStyles.LINE,ScriptColors.Green,LineStyles.SOLID,PaneSides.RIGHT); } }}