A user-defined indicator (UDI) for Figaro can run "remotely", outside the web/mobile platform, connecting via a hub application. This has two uses:
Remote indicators can be written in C# or Python instead of Javascript
Indicators which run remotely never have their code delivered to the web browser, and therefore the code cannot be inspected, decompiled, copied etc
There are two types of hub application:
A local hub which you download and run on your own computer, so that you can write indicators for yourself in C# or Python (instead of Javascript, inside the platform)
The FX Blue indicator hub, which lets you provide indicators remotely to other users without sharing the code (or lets you use your own C# or Python indicators on a device other than the one which is running the indicator code)
To get started with remote indicators, you need to do the following:
Download the local hub application
Download the code samples
Run one of the code samples
In the terminology of remote indicators, there are "providers" and "consumers".
A provider is a C# or Python or Node.js app which implements the code for one or more indicators.
A consumer is an instance of a UDI on a Figaro chart, requesting calculations from a provider.
A provider app is given an ID such as
ws://localhost:9115/myindicator
wss://indicators.fxblue.com/myindicator
For the FX Blue hub at
For a copy of the indicator hub running locally, the ID can be any value of your choice.
A single provider app can implement multiple indicators. In terms of code, an indicator is simply a class (in C# or Python or Javascript).
Each separate indicator in a provider app can then be requested using paths such as the following in the Add UDI dialog:
ws://localhost:9115/myindicator/sma
ws://localhost:9115/myindicator/ema
Provider apps have an indicator "factory" (for example,
You add a remote indicator to a Figaro chart as follows, telling it the location of the hub to use and the ID of the provider app:
Open the Add UDI dialog
Switch to the URL tab
Change the protocol from
Enter a URL such as
You can download and run the local copy of the indicator hub as follows:
Install .NET 8 (if not already present on your computer). Go to https://dotnet.microsoft.com/en-us/download/dotnet/8.0 and, in the ".NET Runtime 8.0.11" section, follow the instructions for your platform.
Download the hub application from https://www.fxblue.com/figaro/udi/figaroindicatorhub.zip
Extract the two files from the ZIP archive into any directory of your choice.
From the command line, run
By default, the hub listens on port 9115 (and the URL which you enter into the Figaro Add UDI dialog is therefore in the form
You can change the port number by creating an XML file called
<settings>
<httpBinding>http://localhost:9115/</httpBinding>
</settings>
If you change the port number, you will also need to change the port which the code samples expect to connect to.
There are examples of remote indicators written in C#, Python, and Javascript (Node.js). You can download the examples from:
https://www.fxblue.com/figaro/udi/remote-indicator-examples.zip
The C# and Python frameworks are, in essence, ports/conversions of the Javascript framework, and this overview should be read in conjunction with the Javascript guide at https://www.fxblue.com/figaro/udi/help.
This document does not attempt to (re-)describe the C# and Python frameworks fully, as standalone entities, without reference to the Javascript framework from which they both derive. It does not, for example, re-explain the fundamental difference between indicators which do have and do not have a
Each of the code samples consists of:
Example indicator(s)
An abstract UserDefinedIndicator class from which your indicator code inherits
Classes defining context and other data which can be passed to your indicator (such as
Framework for connecting to the indicator hub, which you can treat as "internal wiring" and shouldn't need to inspect
Configuration
The configuration consists of:
A server list, defining the hub to connect to. By default, the code examples expect to connect to the local indicator hub running at
The provider ID to use
An indicator factory which creates an instance of an indicator class depending on the path requested in the Add UDI dialog
In all the frameworks (C#, Python, and Node.js), an indicator is a class which inherits from the abstract
Your indicator must implement the initialisation function (
Your indicator will normally also implement a calculation function which receives input data and calculates the indicator's output, such as receiving bar data and calculating ATR. (However, it is possible for indicators only to create drawings, event markers etc, and not to need a calculation function.)
The
The
There are some differences between remote indicators versus indicators running inside the platform.
A key difference between remote indicators versus indicators running inside the web/mobile platform is that, by default, remote indicators cannot "re-paint". When only the current bar is changing, they can only update their current, most recent output value. Modifications of earlier, older output are ignored.
A remote indicator can temporarily change/override this by setting a repaint flag, using
In-platform indicators can be given framework access, letting them use the full Figaro programming framework, including the ability to place trades, see the account history, create dialogs etc. (In the terminology of Figaro indicators, this turns the UDI into a UDIX.)
Framework access is only available inside the platform. It is not available to remote indicators.
Javascript indicators, whether in-platform or remote, have access to an
https://www.fxblue.com/figaro/udi/help#4.6
C# and Python indicators do not have access to these resources.
To connect a provider app to the FX Blue indicator hub, at
Register with www.fxblue.com and obtain a username and password
Change the config (
Change the server configuration to connect to the FX Blue hub instead of a local hub
To change the server configuration:
In C#, edit
In Python, edit
In Node.js, edit
C# indicator code can be relatively lengthy compared to Javascript and Python because the language is strongly typed. For example,
The C# example code consists of the following:
Description | |
(root) | An example indicator ( |
UDI Framework | The UserDefinedIndicator class, plus other objects which can be passed to or from your indicator code |
Example indicators | Other example indicators |
Internal wiring | Code for connecting to the hub application |
Many of the files are partial classes, with their code split between "UDI Framework" and "Internal wiring". For example,
Your indicator must implement
While the return value from
// Create the definition object
var description = new IndicatorDefinition("My indicator caption");
// Populate with further settings
description.isOverlay = false;
…
You define user-configurable settings for your indicator, such as a number of bars for a moving average, by adding to the
description.settingsFields.Add(new IndicatorDefinitionSettingsField("Period", "period", 20, 2, 100));
The
There is a special
description.settingsFields.Add(new IndicatorDefinitionSettingsSourceField());
You define plots for an indicator by adding to the
description.plots.Add(new IndicatorDefinitionPlot("SMA", "line", "blue"));
The second parameter for the
The type of plot determines the number of different values you need to calculate from the incoming data (one for a line, two for a channel etc).
The
If the indicator has a
If the indicator does not have a
Both calculation functions receive a
Both calculation functions receive an
There are three main differences between a C# function such as
The parameter for the Javascript and Python functions is a simple object/dictionary, whereas in C# it is a strongly typed object such as IndicatorRequestDrawing
The Javascript and Python functions accept either a single object or an array/list, whereas in C# there are separate
The functions for creating drawings and event markers, which asynchronously return IDs for those objects, have a
The Python example code consists of the following:
File | Description |
Run-indicator.py | The runnable entry point for the provider app. Implements the indicator factory which creates a specific indicator class in response to a particular URL. |
MyIndicator.py | The (main) indicator implemented by the app |
ExampleIndicators.py | Other example indicators |
UserDefinedIndicator.py | |
IndicatorContext.py | Objects which can be passed to and from your indicator code, such as |
MyServerList.py | Config defining the hub application to connect to |
MyConfig.py | Config defining the provider ID to use |
HubConnection.py IndicatorProvider.py | Internal wiring of the application, which you should be able to ignore |
The code has a dependency on the
You run a Python indicator app using
Your class which inherits from
An indicator will normally have an
The
Parameter | Description |
calculation_type | The reason for the call. A textual value being one out of "update" (a change to the current bar), "new-bar" (addition of a new bar), or "full" (initial full load or reload of data) |
data | A |
output | The output into which the indicator should write its calculations: a list of lists, like the array of arrays in a Javascript indicator |
A function such as
The asynchronous result of
Indicators written in Javascript can (obviously) run inside the Figaro web/mobile platform. The only purpose in using the Node.js remote indicator framework is to keep the Javascript code private, and not have it delivered to the web browser.
The Node.js example code consists of the following:
File | Description |
Run-indicator.js | The runnable entry point for the provider app. Implements the |
My-indicator.js | The indicator implemented by the app |
Server-list.py | Config defining the hub application to connect to |
My-config.py | Config defining the provider ID to use |
Indicator-framework.js | Internal wiring of the application, replicating the in-platform framework described at https://www.fxblue.com/figaro/udi/help |
The code has a dependency on the
You run a Node.js indicator app using
Any in-platform Javascript indicator, such as any of the examples at https://www.fxblue.com/figaro/udi/help#1.2, can be converted to run within the Node.js framework by making two additions to its code: import the Node.js framework, and export the indicator class for use by the provider app:
// Import of Node.js remote indicator framework
const { UserDefinedIndicator, UDI, FXB } = require("./indicator-framework");
// The indicator code which can also run inside the platform
class MyIndicator extends UserDefinedIndicator {
…
};
// Export the indicator class for use by the app
module.exports = { MyIndicator };
Note: when running inside the platform, an indicator class must be called