Development of a user indicator

In order to develop a user indicator, it is necessary:

  1. To create a class library project in Visual Studio.
  2. To add a link to ATAS.Indicators.dll, which is in the folder with the installed program, in the project.
  3. Redefine the Indicator class.
  4. Add the necessary DataSeries - ValueDataSeries, RangeDataSeries, CandleDataSeries or PriceSelectionDataSeries - in the constructor.
  5. Describe the logic of the indicator operation in the OnCalculate() function.
  6. Compile the library.
  7. Place the obtained dll file into the Documents/Advanced Time And Sales/Indicators folder.
  8. The developed indicator will appear in the list of indicators after the next launch of ATAS.


You can download an example of the project here. You need to add the current version of ATAS.Indicators.dll in the ‘references’ of this project.

Example of the indicator development

Create MyCustomIndicator class and inherit it from Indicator:

public class MyCustomIndicator:Indicator
{
    protected override void OnCalculate(int bar, decimal value)
    {
     
    }
} 

Identify the constructor. Add a required number of DataSeries if required. Each indicator has one ValueDataSeries by default. Add one more ValueDataSeries in this example.

public MyCustomIndicator()
{
    DataSeries.Add(new ValueDataSeries("Values"));
} 

Identify the logic of the indicator operation. For example, we need an indicator, which shows maximum values of the incoming DataSeries for 10 recent bars:

protected override void OnCalculate(int bar, decimal value)
 {
     var period=10;   
     var start = Math.Max(0, bar - Period + 1);
     var count = Math.Min(bar + 1, Period);
     var max = (decimal)SourceDataSeries[start];
     for (var i = start + 1; i < start + count; i++)
     {
         max = Math.Max(max, (decimal)SourceDataSeries[i]);
     }
     this[bar] = max;
 }

The OnCalculate method is called for each bar in the history and, further on, it is called at each tick. All bars and values of the respective DataSeries have sequence numbers. Number 0 refers to the earliest chart bar, the next bar has number 1 and so on. Value, which is passed to this method, depends on Source, which a user can select. Open, High, Low and Close of candles and value of other indicators could be used as the source.

There could be situations when an indicator doesn’t need to have a possibility to select the source (for example, these are indicators, which use only the candle data in their calculations). In such a case, the Select section could be hidden. To do it, it is necessary to call the basic constructor with the ‘true’ parameter.

public MyCustomIndicator(): base(true)
{
}

This article was helpful for 3 people. Is this article helpful for you?