Skip to content

Algo Registry

If you have a large portfolio of algos you are distributing to users, you may want to also offer a custom panel or system that allows these users easily manage your algos on their local machines. Such a system would be especially valuable if you offer several products that all complement each other (e.g., two cBots and a custom indicator that all need to be installed to function properly). If a user skips installing a required product, you will be able to alert them to this fact.

In addition, when a user has access to many algorithms, sometimes it can be difficult to keep track of all of them. For example, a user may accidentally delete a valuable algorithm only to later realise that they cannot operate with it anymore.

To help you and your users, the Algo API exposes the AlgoRegistry interface, which offers a convenient means of dynamically tracking statistics about currently installed and uninstalled algos of different types.

Working With the Algo Registry

In the AlgoRegistry, each algo is represented by an AlgoType, which contains the unique name of the algorithm and its AlgoKind (e.g., an AlgoKind.CustomIndicator).

You can retrive a specific algorithm from the registry by calling the following method.

1
AlgoRegistry.Get(string name, AlgoKind algoKind);

To retrieve a count of algorithms of a particular kind, call the following method.

1
AlgoRegistry.GetCount(AlgoKind algoKind)

You can also add custom handlers to the following events.

  • AlgoTypeInstalled, which is triggered every time a new algo is installed.
  • AlgoTypeDeleted, which is triggered every time a new algo is deleted.
  • AlgoTypeChanged, which is triggered every time an installed algo is modified.

AlgoRegistry in Different Modes

AlgoRegistry works as intended in backtesting and optimisation. It does not work when using cTrader CLI.

Creating an Example Plugin

The AlgoRegistry is perfect for creating a plugin that will display information about algos directly in the cTrader UI. The below plugin does just that.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Plugins
{
    [Plugin(AccessRights = AccessRights.None)]
    public class AlgoStatsPlugin : Plugin
    {
        private TextBlock _customIndicatorsBlock = new TextBlock
        {
            FontSize = 12,
            FontWeight = FontWeight.Bold,
            TextAlignment = TextAlignment.Left,
            Padding = new Thickness(5, 5, 5, 5),
        };

        private TextBlock _indicatorsBlock = new TextBlock
        {
            FontSize = 12,
            FontWeight = FontWeight.Bold,
            TextAlignment = TextAlignment.Left,
            Padding = new Thickness(5, 5, 5, 5),
        };

        private TextBlock _robotsBlock = new TextBlock
        {
            FontSize = 12,
            FontWeight = FontWeight.Bold,
            TextAlignment = TextAlignment.Left,
            Padding = new Thickness(5, 5, 5, 5),
        };

        private TextBlock _pluginsBlock = new TextBlock
        {
            FontSize = 12,
            FontWeight = FontWeight.Bold,
            TextAlignment = TextAlignment.Left,
            Padding = new Thickness(5, 5, 5, 5),
        };

        private Grid _grid = new Grid(4, 1);

        protected override void OnStart()
        {
            var aspBlock = Asp.SymbolTab.AddBlock("Algo Registry");
            aspBlock.IsExpanded = true;
            aspBlock.Height = 200;

            _grid.AddChild(_robotsBlock, 0, 0);
            _grid.AddChild(_indicatorsBlock, 1, 0);
            _grid.AddChild(_customIndicatorsBlock, 2, 0);
            _grid.AddChild(_pluginsBlock, 3, 0);

            aspBlock.Child = _grid;

            Timer.Start(TimeSpan.FromSeconds(1));
        }

        protected override void OnTimer() 
        {
            _robotsBlock.Text = $"cBots: {AlgoRegistry.GetCount(AlgoKind.Robot)}";
            _customIndicatorsBlock.Text = $"Custom indicators: {AlgoRegistry.GetCount(AlgoKind.CustomIndicator)}";
            _indicatorsBlock.Text = $"Indicators: {AlgoRegistry.GetCount(AlgoKind.StandardIndicator)}";
            _pluginsBlock.Text = $"Plugins: {AlgoRegistry.GetCount(AlgoKind.Plugin)}";
        }

    }
}

Upon building our plugin, we should see the following block in the 'Active Symbol Panel'. The data in the block will be dynamically updated every second.

Summary

AlgoRegistry is a great feature for plugin developers but it can also be used with other types of algos. For example, you may create an indicator that references another custom indicator, in which case your algo would first need to check whether the required indicator is installed by the user. We also recommend adding the AlgoRegistry to your existing algos to simplify the management of custom indicators and other types of algos.