3.9Interacting with trading charts

The ChartChange() function allows any widget, script, or UDIX to make changes either to all open charts or just to a single chart. For example, changing the market of the active chart in the platform:

Framework.ChartChange({

// Chart(s) to act on

mode: "active",

// Action to carry out

command: "set-market",

// Further parameters required by the type of action

instrumentId: "GBP/USD"

});

ChartChange() requires a mode setting, telling it which chart(s) to act on. The mode can be one of the following values:

mode setting

Description

all

Acts on all visible charts in the platform

active

Acts on the active chart; the one which the user last clicked on. (In a chart widget, loaded into a chart's sidebar/dock, mode: "active" always refers to the chart which the widget is loaded onto.)

single

Acts on a single chart, specified by a chartId setting. This can be used to modify a chart which has been displayed in a dialog or in an iframe. The chartId value is provided by the callback from CreateDialog() or CreateSubWidget(). - see the example above.

For example, using ChartChange() with mode: "single" after creating a chart as a dialog:

Framework.CreateDialog({

type: "chart",

}, function (MsgResponse) {

if (MsgResponse.widgetId) {

// Initial response, on dialog creation.

// MsgResponse.widgetId contains the ID which can be used in

// calls to ChartChange(). For example, use ChartChange() to add

// 20-bar EMA to the chart:

Framework.ChartChange({

mode: "single",

chartId: MsgResponse.widgetId,

command: "load-indicator",

indicator: "EMA",

indicatorSettings: {period: 20}

});

} else {

// Subsequent dialog update, such as closure

}

});

ChartChange() also requires a command value, telling it what change to make. Further optional and/or compulsory parameters for ChartChange() then depend on the type of command.

Note: the calls for creating drawings, event markers, bar highlights, and HTML require version 3 of the framework or higher.

command value

Description

set-market

Changes the market of a chart

set-timeframe

Changes the timeframe of a chart

load-indicator

Loads an indicator

remove-indicator

Removes a type of indicator

remove-all-indicators

Removes all indicators

create-drawing

Adds a drawing

change-drawing

Modifies a drawing (including moving it)

remove-drawing

Removes a drawing

remove-all-drawings

Removes all drawings

create-event-marker

Adds an event marker

remove-event-marker

Removes an event marker

remove-all-event-markers

Removes all event markers

create-bar-highlight

Adds a bar highlight

remove-bar-highlight

Removes a bar highlight

remove-all-bar-highlights

Removes all bar highlights

create-html

Adds HTML to the chart

send-html-message

Sends a message to the HTML

remove-html

Removes HTML from the chart

populate-deal-ticket

Populates the chart's deal ticket

hide-deal-ticket

Hides the chart's deal ticket

get-chart-data

Retrieves data and information from the chart

ChartChange() has an optional callback which receives responses from the affected charts.

Note on dates/times: the calls below for creating objects such as drawings are similar to the features which are available in a UDI. However, there is one key difference. All date parameters which are passed to ChartChange() should be the framework's standard UTC date/time values in milliseconds. In a UDI, such values are instead specified in terms of chart time (such as UTC+2/3). The expectation is that a widget or script which is calling ChartChange() will want to be able to specify dates based on UTC values such as the openTime or closeTime of an order.