API Control Panel
var pane = controlPane.AddControl("SMA", "", ControlParameterType.NumericUpDown, true, 0, 0, double.NaN, double.NaN, false, false, null, Period);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?