First Indicator (API)
Last updated
Last updated
TSLab can use indicators written in .NET and compiled into a .dll library.
For example, we write an indicator that considers the price of OHLC4 according to the formula:
Let's create a new project in Visual Studio, using the Template Class Library template and name it MyHandlers.
Important: for TSLab version 2.2 and higher, you need to use the .Net Standard2.0, .Net Standard2.1, Net6 or higher platform.
Add the libraries TSLab.Script.dll, TSLab.Script.Handlers.dll, TSLab.DataSource.dll to the project. Create a new OHLC4 class and write the following code:
We created the OHLC4 class from the IBar2DoubleHandler interface. This interface implements one Execute method, which takes a tool as an input and produces a list of numbers.
For the class, we specified the HandlerCategory attribute, called MyHandlers. This is the name of the category where our indicator will be placed in TSLab. HelperName - indicates the name of the indicator that will be displayed with TSLab, you can write any other name.
In the Execute method, we made the calculation of the OHLC4 value a simple expression:
Now you can build the project by pressing F6. If everything was done correctly, the studio will save, assemble the project and create the file MyHandlers.dll in the project folder \bin\Debug.
This file must be copied to the TSLab folder: % APPDATA% \ .. \ Local \ TSLab \ TSLab 2.0 \ Handlers
Run TSLab and in Editor mode should display our new indicator.
Connect our new indicator, select the tool and run.
We see that the blue line is displayed on the chart, this is the price of OHLC4.
In order not to manually copy the .dll file each time, you can register a command for automatic copying in the studio. The file will be copied after each build of the project.
But it should be remembered that before building, you need to close TSLab, because the file cannot be overwritten.
Command: xcopy / Y MyHandlers.dll "%APPDATA%\..\Local\TSLab\TSLab 2.0\Handlers"