Skip to content

Plugin file associations

The FileAssociations interface provides types that enable plugins to register, modify and handle file extensions flexibly. With those types, developers can code a plugin to manage a file association. When the plugin is enabled, cTrader recognises and directs the relevant files to the plugin for processing.

With plugins configured to handle files directly in the cTrader UI, users may no longer have to alternate between multiple applications when working with files. For example, a plugin could be created to open and manage all the files used with a specific trading strategy.

Use cases

The following are plugin examples using the FileAssociations feature:

  • A trading history converter accepts and handles CSV and TXT files containing trade history from other platforms, converting them into cTrader-compatible formats for analysis or importing them directly into its journal.
  • A trading signal processor reads XML or JSON files containing trade signals from external providers or automated trading systems, allowing users to quickly execute trades based on the signals.
  • A risk management template importer accepts and handles JSON or CSV files containing risk management configurations, allowing users to apply predefined settings in cTrader.
  • A portfolio manager processes CSV and XML files containing traders’ portfolio details, providing a streamlined view of assets, positions and performance metrics while enhancing portfolio management.
  • A chart template loader processes XML or JSON files for chart templates, allowing users to store and quickly load their preferred configuration or setup for a chart.
  • An indicator settings loader processes JSON or CSV files for custom indicator settings, allowing users to store and quickly apply their preferred configuration for an indicator.

Operations

Install a plugin

When a cTrader user installs and enables a plugin that supports a specific file type for the first time, a dialogue appears. The user is prompted to associate the file extension with the plugin.

After the user confirms the operation, their computer updates their system-wide file association settings, and the new configuration is applied immediately.

The new icon for the file type becomes visible in File Explorer. If an icon is not provided for the file type, the default plugin icon is used.

Warning

Plugins are not allowed to process restricted file extensions such as .algo.

Use the plugin

If a plugin supporting file extensions is enabled in cTrader, the plugin is called to work with files when users do any of the following:

  • Drag and drop files - users can drag a supported file and drop it into the cTrader UI.

  • Open files in File Explorer - users can double-click a file to open it or use the Open with option and select cTrader.

    • If the cTrader application is open, the plugin receives the file immediately.
    • If the cTrader application is closed, cTrader is launched first and then the plugin receives the file.

The received file is copied to the data folder for the plugin and is deleted once the plugin finishes processing it.

Path to the data folder for a plugin: …/Documents/cAlgo/Data/Plugins/{PluginName}/Temp.

In cases where a file extension is associated with several enabled plugins, each plugin processes the file independently.

When a file association is removed because the relevant plugin is disabled in a cTrader instance, the file association is automatically re-added in another cTrader instance where the same plugin is enabled.

Perform a manual override

If the user later changes the default program for a file type within their regular computer settings, cTrader automatically stops handling that file type.

To set cTrader as the default program for handling files in that format again, the user has to reestablish the file association this way:

  1. Open cTrader and disable the relevant plugin.
  2. Enable the plugin. When the dialogue appears, confirm the operation.

This setup helps plugins and the cTrader application manage file extensions while avoiding interference from other programs.

Note

A plugin can add and remove file associations at runtime without requiring a restart of the algorithm or the cTrader application.

Example plugin

The example plugin simply adds file associations for the following file types:

  • CSV
  • PNG
  • PDF
  • TXT
 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
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Plugins
{
    [Plugin(AccessRights = AccessRights.None)]
    public class FileAssociationSample : Plugin
    {
        private const string FileExtension1 = ".csv";
        private const string FileExtension2 = ".png";
        private const string FileExtension3 = ".pdf";
        private const string FileExtension4 = ".txt";

        protected override void OnStart()
        {
            AddFileAssociations();
            FileAssociations.FileOpened += FileAssociations_FileOpened;

            Print("File associations have been added.");
        }

        private void AddFileAssociations()
        {
            FileAssociations.Add(FileExtension1);
            FileAssociations.Add(FileExtension2);
            FileAssociations.Add(FileExtension3);
            FileAssociations.Add(FileExtension4);
        }

        private void FileAssociations_FileOpened(FileAssociationsFileOpenedEventArgs obj)
        {
            Print($"File opened: {obj.FilePath}");
        }

        protected override void OnException(Exception exception)
        {
            Print($"Exception: {exception}");
        }
    }
}