Initialisation: UDI.onInit()

A UDI must have a UDI.onInit() function. This returns a description of your indicator: its name; what it draws (line, histogram etc); and any user-configurable fields it wants such as a number of bars, or a colour.

An example of the UDI.onInit() function is as follows. It returns an object which must contain a caption property, a plots[] array, and a settingsFields[] array. There are also other optional properties which can be included.

UDI.onInit = function(data)
{
       return {
                   // Display-name for the indicator
                   caption: "My SMA",
                  
                   // Specifies that the indicator should be in the main panel, not its own sub-panel
                   isOverlay: true,
                  
                   // List of things which the indicator draws: just a line in this basic example
                   plots: [
                               {type: "line", caption: "avg", color: "blue", lineWidth: 2}
                   ],
                  
                   // Settings fields which the indicator wants
                   settingsFields: [
                               // The "Source" field has special meaning, and the chart automatically
                               // assigns a caption to this field
                               {id: "Source"},
                              
                               // Also require a number of bars for the average
                               {id: "period", caption: "Period", type: "int", defaultValue: 14, min: 2}
                   ]
       };
};

Last updated