Bar indicator

The bar indicator accepts single values as input and produces one value. The number of the bar also comes to the entrance (variable i).

  1. An example of an indicator that takes two numbers and displays the average value:

using TSLab.Script.Handlers;

namespace MyLib
{
    [HandlerCategory("MyLib")]
    [HandlerName("HandlerWithNumber")]
    [InputsCount(2)]
    [Input(0, TemplateTypes.DOUBLE, false, "list1")]
    [Input(1, TemplateTypes.DOUBLE, false, "list2")]
    [OutputsCount(1)]
    [OutputType(TemplateTypes.DOUBLE)]
    public class HandlerWithNumber : IValuesHandlerWithNumber
    {
        public double Execute(double value1, double value2, int i)
        {
            return (value1 + value2) / 2;
        }
    }
}

2. An example of an indicator that accepts a Source and one number. Prints close + number.

using TSLab.Script;
using TSLab.Script.Handlers;

namespace MyLib
{
    [HandlerCategory("MyLib")]
    [HandlerName("HandlerWithNumber2")]
    [InputsCount(2)]
    [Input(0, TemplateTypes.SECURITY, Name = "SECURITYSource")]
    [Input(1, TemplateTypes.DOUBLE, false, "list2")]
    [OutputsCount(1)]
    [OutputType(TemplateTypes.DOUBLE)]
    public class HandlerWithNumber2 : IValuesHandlerWithNumber
    {
        public double Execute(ISecurity security, double value1, int i)
        {
            return security.Bars[i].Close + value1;
        }
    }
}

3. An example of an indicator that has 2 overloads of the Execute method and accepts a Source and one or two numbers. Prints close + number1 + number2.

using TSLab.Script;
using TSLab.Script.Handlers;

namespace MyLib
{
    [HandlerCategory("MyLib")]
    [HandlerName("HandlerWithNumber3")]
    [InputsCount(3)]
    [Input(0, TemplateTypes.SECURITY, Name = "SECURITYSource")]
    [Input(1, TemplateTypes.DOUBLE, false, "list1")]
    [Input(2, TemplateTypes.DOUBLE, false, "list2")]
    [OutputsCount(1)]
    [OutputType(TemplateTypes.DOUBLE)]
    public class HandlerWithNumber3 : IValuesHandlerWithNumber
    {
        public double Execute(ISecurity security, double value1, int i)
        {
            return security.Bars[i].Close + value1;
        }

        public double Execute(ISecurity security, double value1, double value2, int i)
        {
            return security.Bars[i].Close + value1 + value2;
        }
    }
}

Last updated