Pre-processed indicator

Pre-processed indicator

IValuesHandlerWithPrecalc - script class interface, shows that the handler works with the current values, but requires preprocessing.

Has the following methods:

  • PreCalc - the method is executed before the main calculation.

  • Execute - the basic calculation method.

  • PostCalc - the method is executed after the main calculation.

Incoming data

The class is preceded by the input data of the indicator through the Input attribute, for example:

[InputsCount (2)] [Input (0, TemplateTypes.DOUBLE, false, "list1")] [Input (1, TemplateTypes.DOUBLE, false, "list2")]

This means that the indicator accepts two lists of data with real numbers. The number of parameters can be unlimited.

Outgoing data

[OutputsCount (1)] [OutputType (TemplateTypes.DOUBLE)]

This means that the indicator produces one list of real numbers.

Example with streaming data:

using System.Collections.Generic;
using TSLab.Script.Handlers;

namespace MyLib
{
    [HandlerCategory("MyLib")]
    [HandlerName("TestPrecalc1")]
    [InputsCount(2)]
    [Input(0, TemplateTypes.DOUBLE, false, "list1")]
    [Input(1, TemplateTypes.DOUBLE, false, "list2")]
    [OutputsCount(1)]
    [OutputType(TemplateTypes.DOUBLE)]
    public class TestPrecalc1 : IValuesHandlerWithPrecalc
    {
        public void PreCalc(IList<double> list1, IList<double> list2)
        {
            // Выполняется до расчетов
        }

        public double Execute(int i)
        {
            // Метод расчета, параметр i перебирается от 0 до n баров
            return 0;
        }

        public void PostCalc()
        {
            // Выполняется после расчетов
        }
    }
}

In this example, the PreCalc method is executed first, passing two lists of data, list1 and list2. The method returns nothing. Then the Execute method is launched one by one for each bar, here i is the bar number. The method returns a real number. After that, the PostCalc method is run, it returns nothing.

Example with non-streaming data

You can specify that the data is not streaming, then the values will be passed element by element to the Execute method, for example:

[InputsCount (2)] [Input (0, TemplateTypes.DOUBLE, true, "list1")] [Input (1, TemplateTypes.DOUBLE, true, "list2")]

using System.Collections.Generic;
using TSLab.Script.Handlers;

namespace MyLib
{
    [HandlerCategory("MyLib")]
    [HandlerName("TestPrecalc2")]
    [InputsCount(2)]
    [Input(0, TemplateTypes.DOUBLE, true, "list1")]
    [Input(1, TemplateTypes.DOUBLE, true, "list2")]
    [OutputsCount(1)]
    [OutputType(TemplateTypes.DOUBLE)]
    public class TestPrecalc2 : IValuesHandlerWithPrecalc
    {
        public void PreCalc()
        {
            // Выполняется до расчетов
        }

        public double Execute(double value1, double value2, int i)
        {
            // Метод расчета, параметр i перебирается от 0 до n баров
            return 0;
        }

        public void PostCalc()
        {
            // Выполняется после расчетов
        }
    }
}

Note that now nothing is passed to the PreCalc method.

Feature of the indicator with one list of data

If the indicator has only one incoming data list, then it can work only with streaming data and the PostCalc method will not be available.

using System.Collections.Generic;
using TSLab.Script.Handlers;

namespace MyLib
{
    [HandlerCategory("MyLib")]
    [HandlerName("TestPrecalc3")]
    [InputsCount(1)]
    [Input(0, TemplateTypes.DOUBLE, false, "list1")]
    [OutputsCount(1)]
    [OutputType(TemplateTypes.DOUBLE)]
    public class TestPrecalc3 : IValuesHandlerWithPrecalc
    {
        public void PreCalc(IList<double> list1)
        {
            // Выполняется до расчетов
        }

        public double Execute(double value1, int i)
        {
            // Метод расчета, параметр i перебирается от 0 до n баров
            return 0;
        }
    }
}

Last updated