Skip to content

Custom Indicators

It is possible to add any custom indicators you create to your local reference library, allowing you to reuse them across any number of other custom indicators.

Follow these steps to reference a custom indicator.

Image title

  • In the 'Indicators' section of the 'Reference Manager' window, select the required indicators and click 'Apply'. Use the search bar to find the required indicators.

Image title

Referenced custom indicators are defined in the Initialize() method similarly to nested indicators; however, the syntax is slightly different.

Specifically, the name of a custom indicator should be enclosed in angle brackets following the GetIndicator() directive. Analogously to nested indicators, the parameters of referenced indicators should be enclosed in parentheses as shown in the below snippets.

1
sma = Indicators.GetIndicator(Source, SmaPeriod);

The GetIndicator() directive can be integrated into an indicator as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class SampleReferenceSMA : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 14)]
        public int SmaPeriod { get; set; }

        [Output("Referenced SMA Output")]
        public IndicatorDataSeries refSMA { get; set; }

        private SampleSMA sma;

        protected override void Initialize()
        {
            sma = Indicators.GetIndicator(Source, SmaPeriod);
        }

        public override void Calculate(int index)
        {
            refSMA[index] = sma.Result[index];
        }
    }

Alternatively, you can reference the indicator project file from your cTrader indicator/cBot project file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="cTrader.Automate" Version="1.*" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\..\Indicators\Another Indicator\Another Indicator\Another Indicator.csproj" />
  </ItemGroup>
</Project>

However, the recommended approach is to use the 'Reference Manager' window.