API Control Panel
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.
using TSLab.Script;
using TSLab.Script.Control;
using TSLab.Script.Handlers;
using TSLab.Script.Helpers;
using TSLab.Script.Optimization;
namespace MyLib
{
public class TestControlPanel : IExternalScript
{
public OptimProperty Period = new OptimProperty(100, 100, 1000, 50);
public void Execute(IContext ctx, ISecurity sec)
{
// Create an SMA indicator
var sma = ctx.GetData("SMA", new[] { Period.ToString() }, () => Series.SMA(sec.ClosePrices, Period));
// Create a control panel
var controlPane = ctx.CreateControlPane("Control", "Control", "My control");
// Add the indicator period to the control panel
var 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 recalculated
pane.IsNeedRecalculate = true;
// Drawing the SMA indicator on the chart
ctx.First.AddList("SMA", sma, ListStyles.LINE, ScriptColors.Green, LineStyles.SOLID, PaneSides.RIGHT);
}
}
}

Last updated
Was this helpful?