ChartChange() has an optional callback which fires with a response from each applicable/affected chart. For example:
// Some change to all visible charts…
Framework.ChartChange({
mode: "all",
…
}, function (MsgResponse) {
// Will be called with a separate MsgResponse from each visible chart.
// If there are no visible charts, there will be no callback(s)!
});
The response object has a
// Load EMA(10) onto the active chart
Framework.ChartChange({
mode: "active",
command: "load-indicator",
indicator: "EMA",
indicatorSettings: {period: 10}
}, function (MsgResponse) {
// (Note: no callback if there is no active chart)
if (MsgResponse.result.success) {
// EMA has been loaded onto the chart
} else {
// EMA failed to load
// Error condition is in MsgResponse.result.error
}
});
The callback can also provide information which is required for subsequent calls to
// Add a horizontal-line drawing to the chart, and get its ID for later use
Framework.ChartChange({
mode: "active",
command: "create-drawing",
drawing: {
type: "horizontalLine",
points: [{value: 1.17}],
text: "Hello",
style: {line: {color: "red"}}
}
}, function (MsgResponse) {
// (Note: no callback if there is no active chart)
if (MsgResponse.result.success) {
// Drawing has been created
// ID of the new drawing is in MsgResponse.result.drawingId
} else {
// Failed to create drawing
// Error condition is in MsgResponse.result.error
}
});