Chart Methods - mmmy/css3demos GitHub Wiki
Here is a list of supported chart's methods.
Before 1.4 version. You can call these methods using widget object returned to you by widget's constructor.
Since 1.5 version. You can call these methods using chart object returned to you by widget's methods chart(index) or activeChart().
- Subscribing To Chart Events
- Chart Actions
- Studies And Shapes
- Study Templates
- Trading Primitives
- Getters
You can subscribe using Subscription object returned by this function to be notified when new history bars are loaded and unsubscribe from the event.
You can subscribe using Subscription object returned by this function to be notified when the symbol is changed and unsubscribe from the event.
-
callback
: function(interval)
The Charting Library will call the callback provided immediately if bars are already loaded or when the bars are received.
The function returns true
if bars are already loaded and false
otherwise.
Since 1.5 version.
-
callback
: function({time, price})
The Charting Library will call the callback every time the crosshair position is changed.
-
range
: object,{from to}
-
from
,to
: unix timestamps, UTC -
callback
:function()
. The Library will call it after it's done with the viewport setup.
Forces the chart to adjust its parameters (scroll, scale) to make the selected time period fit the view port.
Neither from
, nor to
must not be in future. This method was introduced in version 1.2
.
-
symbol
: string -
callback
: function()
Makes the chart to change its symbol. Callback is called after new symbol's data arrived.
-
resolution
: string -
callback
: function()
Makes the chart to change its resolution. Callback is called after new data arrived.
deprecated, use executeActionById instead
-
action
: string
Executes any action from chart's context menu (the menu which is popped up when one right-clicks the empty space on a main pane) by its name. Use names as you see them in English localization. Examples:
// < ... >
widget.chart().executeAction("Insert Indicator..."); // calling this will show `Insert Study` dialog
// < ... >
widget.chart().executeAction("Hide All Drawing Tools"); // this will toggle all shapes visibility
// < ... >
since version 1.3
-
actionId
: string
Executes an action by its id.
Showing a dialog
chartProperties
compareOrAdd
scalesProperties
tmzProperties
paneObjectTree
insertIndicator
symbolSearch
changeInterval
Other actions
timeScaleReset
chartReset
seriesHide
studyHide
lineToggleLock
lineHide
showLeftAxis
showRightAxis
scaleSeriesOnly
drawingToolbarAction
magnetAction
stayInDrawingModeAction
lockDrawingsAction
hideAllDrawingsAction
hideAllMarks
showCountdown
showSeriesLastValue
showSymbolLabelsAction
showStudyLastValue
showStudyPlotNamesAction
undo
redo
takeScreenshot
paneRemoveAllStudiesDrawingTools
Examples:
// < ... >
widget.chart().executeActionById("undo");
// < ... >
widget.chart().executeActionById("drawingToolbarAction"); // hides or shows the drawing toolbar
// < ... >
Calling this method makes the Library to request visible marks once again.
Calling this method makes the Library to remove all visible marks.
-
type
:TradingView.BARS
|TradingView.CANDLES
|TradingView.AREA
|TradingView.LINE
|TradingView.HEIKEN_ASHI
|TradingView.HOLLOW_CANDLES
Sets the main series style.
Calling this method closes a context menu or a dialog if it is shown.
-
name
: string, a name of an indicator as you can see it inIndicators
widget -
forceOverlay
: forces the Charting Library to place the created study on main pane -
lock
: boolean, shows whether a user will be able to remove/change/hide your study or not -
inputs
: (since version1.2
) an array of study inputs. This array is expected to contain just inputs values in the same order they are printed in study's properties page. -
callback
: function(entityId
) -
overrides
: (since version1.2
) an object containing properties you'd like to set for your new study. Note: you should not specify study name: start a property path with a plot name.
Creates the study on a main symbol. Examples:
createStudy('MACD', false, false, [14, 30, 9])
createStudy('Moving Average Exponential', false, false, [26])
createStudy('Stochastic', false, false, [26], null, {"%d.color" : "#FF0000"})
Remark: Compare
study has 2 inputs: [dataSource, symbol]
. Supported dataSource
values: ["close", "high", "low", "open"]
.
Remark 2: You actually use Overlay
study when choose to Add
a series on the chart. This study has the single input -- symbol
. Here is an example how to add a symbol:
widget.chart().createStudy('Overlay', false, false, ['AAPL']);
Remark 3: You actually also use Compare
study when choose to compare a series. This study has two inputs -- source
and symbol
. Here is an example how to add a compare series:
widget.chart().createStudy('Compare', false, false, ["open", 'AAPL']);
-
point
: object{time, [price], [channel]}
-
time
: unix time. The only mandatory argument. -
price
: If you specifyprice
, then your icon will be placed on its level. If you do not, then the icon sticks to bar at respective time. -
channel
: The price level to stick to is specified bychannel
argument (open
,high
,low
,close
). If no channel is specified, 'open' is a default. -
options
: object{shape, [text], [lock], [overrides]}
-
shape
may be one of the ['arrow_up', 'arrow_down', 'flag', 'vertical_line', 'horizontal_line']. 'flag' is the default value. -
text
is an optional argument. It's the text that will be assigned to shape if it can contain a text. -
lock
shows whether a user will be able to remove/change/hide your shape or not. -
disableSelection
(since1.3
) prevents selecting of the shape -
disableSave
(since1.3
) prevents saving the shape with a chart -
disableUndo
(since1.4
) prevents adding of the action to the undo stack -
overrides
(since1.2
). It is an object containing properties you'd like to set for your new shape. -
zOrder
(since1.3
) may be one of the [top
,bottom
].top
puts the line tool on top of all other sources,bottom
puts the line tool below all other sources. If it is not specified the line tool is placed above all existing line tools. -
callback
: function(entityId
)
Since 1.4 the function returns the result immediately. Callback is kept for compatability.
This call creates a shape at specified point on main series.
-
points
: an array of objects[{time, [price], [channel]},...]
-
time
: unix time. The only mandatory argument. -
price
: If you specifyprice
, then your icon will be placed on its level. If you do not, then the icon sticks to bar at respective time. -
channel
: The price level to stick to is specified bychannel
argument (open
,high
,low
,close
). If no channel is specified, 'open' is a default. -
options
: object{shape, [text], [lock], [overrides]}
-
shape
may be one of the identifiers -
text
is an optional argument. It's the text that will be assigned to shape if it can contain a text. -
lock
shows whether a user will be able to remove/change/hide your shape or not. -
disableSelection
(since1.3
) prevents selecting of the shape -
disableSave
(since1.3
) prevents saving the shape with a chart -
disableUndo
(since1.4
) prevents adding of the action to the undo stack -
overrides
. It is an object containing properties you'd like to set for your new shape. -
zOrder
(since1.3
) may be one of the [top
,bottom
].top
puts the line tool on top of all other sources,bottom
puts the line tool below all other sources. If it is not specified the line tool is placed above all existing line tools. -
callback
: function(entityId
)
Since 1.4 the function returns the result immediately. Callback is kept for compatability.
Look Shapes and Overrides for more information.
This call creates a shape with specified points on main series.
-
entityId
: object. Value which was passed to your callback after the entity (shape of study) was created.
Removes the specified entity.
-
point
: object{time}
-
options
: obejct{lock}
This function is a synonym for createShape
with shape = 'vertical_line'. It is treated as obsolete.
Removes all shapes (drawings) from the chart.
Removed all studies from the chart.
-
options
: object{saveInterval}
-
saveInterval
: boolean -
callback
: function(data)
Since 1.4 the function returns the result immediately. Callback is kept for compatability.
Saves the study template to JS object. Charting Library will call your callback and pass the state object as argument. This call is a part of low-level save/load API.
-
template
: object
Loads the study template from state object. This call is a part of low-level save/load API.
Creates a new order on the chart and returns an API-object which you can use to control the order properties and behavior. It's strongly recommended to read this article before using this call.
Arguments (since 1.4):
options
is an object with one possible key: disableUndo
which can be true
or false
. For compatability reasons the default value is false
.
API object methods:
-
remove()
: Removes the position from the chart. You can’t use API-object after this call. -
onModify(callback)
/onModify(data, callback)
-
onMove(callback)
/onMove(data, callback)
API object has a set of properties listed below. Each property should be used through respective accessors. I.e., if you want to work with Extend Left
property, use getExtendLeft()
of setExtendLeft()
methods.
General properties:
Property | Type | Supported Values | Default Value |
---|---|---|---|
Price | Double | Double | 0.0 |
Text | String | String | "" |
Tooltip | String | String | "" |
Quantity | String | String | "" |
Connection line properties:
Property | Type | Supported Values | Default Value |
---|---|---|---|
Extend Left | Boolean | "inherit" or Boolean | True |
Line Length | Integer | "inherit" or 0 .. 100 | 0 |
Line Style | Integer | "inherit" or 0 .. 2 | 2 |
Line Width | Integer | "inherit" or 1 .. 4 | 1 |
Fonts:
Property | Type | Default Value |
---|---|---|
Body Font | String | "bold 7pt Verdana" |
Quantity Font | String | "bold 7pt Verdana" |
Colors:
Property | Type | Default Value |
---|---|---|
Line Color | String | "rgb(255, 0, 0)" |
Body Border Color | String | "rgb(255, 0, 0)" |
Body Background Color | String | "rgba(255, 255, 255, 0.75)" |
Body Text Color | String | "rgb(255, 0, 0)" |
Quantity Border Color | String | "rgb(255, 0, 0)" |
Quantity Background Color | String | "rgba(255, 0, 0, 0.75)" |
Quantity Text Color | String | "rgb(255, 255, 255)" |
Cancel Button Border Color | String | "rgb(255, 0, 0)" |
Cancel Button Background Color | String | "rgba(255, 255, 255, 0.75)" |
Cancel Button Icon Color | String | "rgb(255, 0, 0)" |
Example:
widget.chart().createOrderLine()
.onMove(function() {
this.setText("onMove called");
})
.onModify("onModify called", function(text) {
this.setText(text);
})
.onCancel("onCancel called", function(text) {
this.setText(text);
})
.setText("STOP: 73.5 (5,64%)")
.setQuantity("2");
Creates a new position on the chart and returns an API-object which you can use to control the position properties and behavior. It's strongly recommended to read this article before using this call.
Arguments (since 1.4):
options
is an object with one possible key: disableUndo
which can be true
or false
. For compatability reasons the default value is false
.
API object methods:
-
remove()
: Removes the position from the chart. You can’t use API-object after this call. -
onClose(callback)
/onClose(data, callback)
-
onModify(callback)
/onModify(data, callback)
-
onReverse(callback)
/onReverse(data, callback)
API object has a set of properties listed below. Each property should be used through respective accessors. I.e., if you want to work with Extend Left
property, use getExtendLeft()
of setExtendLeft()
methods.
General properties:
Property | Type | Supported Values | Default Value |
---|---|---|---|
Price | Double | Double | 0.0 |
Text | String | String | "" |
Tooltip | String | String | "" |
Quantity | String | String | "" |
Connection line properties:
Property | Type | Supported Values | Default Value |
---|---|---|---|
Extend Left | Boolean | "inherit" or Boolean | True |
Line Length | Integer | "inherit" or 0 .. 100 | 0 |
Line Style | Integer | "inherit" or 0 .. 2 | 2 |
Line Width | Integer | "inherit" or 1 .. 4 | 1 |
Fonts:
Property | Type | Default Value |
---|---|---|
Body Font | String | "bold 7pt Verdana" |
Quantity Font | String | "bold 7pt Verdana" |
Colors:
Property | Type | Default Value |
---|---|---|
Line Color | String | "rgb(0, 113, 224)" |
Body Border Color | String | "rgb(0, 113, 224)" |
Body Background Color | String | "rgba(255, 255, 255, 0.75)" |
Body Text Color | String | "rgb(0, 113, 224)" |
Quantity Border Color | String | "rgb(0, 113, 224)" |
Quantity Background Color | String | "rgba(0, 113, 224, 0.75)" |
Quantity Text Color | String | "rgb(255, 255, 255)" |
Reverse Button Border Color | String | "rgb(0, 113, 224)" |
Reverse Button Background Color | String | "rgba(255, 255, 255, 0.75)" |
Reverse Button Icon Color | String | "rgb(0, 113, 224)" |
Close Button Border Color | String | "rgb(0, 113, 224)" |
Close Button Background Color | String | "rgba(255, 255, 255, 0.75)" |
Close Button Icon Color | String | "rgb(0, 113, 224)" |
Example:
widget.chart().createPositionLine()
.onModify(function() {
this.setText("onModify called");
})
.onReverse("onReverse called", function(text) {
this.setText(text);
})
.onClose("onClose called", function(text) {
this.setText(text);
})
.setText("PROFIT: 71.1 (3.31%)")
.setQuantity("8.235")
.setPrice(15.5)
.setExtendLeft(false)
.setLineStyle(0)
.setLineLength(25);
Creates a new execution on the chart and returns an API-object which you can use to control the execution properties. It's strongly recommended to read this article before using this call.
Arguments (since 1.4):
options
is an object with one possible key: disableUndo
which can be true
or false
. For compatability reasons the default value is false
.
API object has a set of properties listed below. Each property should be used through respective accessors. I.e., if you want to work with Extend Left
property, use getExtendLeft()
of setExtendLeft()
methods.
API object methods:
-
remove()
: Removes the execution shape from the chart. You can’t use API-object after this call.
General properties:
Property | Type | Supported Values | Default Value |
---|---|---|---|
Price | Double | Double | 0.0 |
Time | Integer | Unix time | 0 |
Direction | String | "buy" or "sell" | "buy" |
Text | String | String | "execution" |
Tooltip | String | String | |
Arrow Height | Integer | Integer | 8 |
Arrow Spacing | Integer | Integer | 1 |
Fonts:
Property | Type | Default Value |
---|---|---|
Font | String | "8pt Verdana" |
Colors:
Property | Type | Default Value |
---|---|---|
Text Color | String | "rgb(0, 0, 0)"" |
Arrow Color | String | "rgba(0, 0, 255)" |
Example:
widget.chart().createExecutionShape()
.setText("@1,320.75 Limit Buy 1")
.setTooltip("@1,320.75 Limit Buy 1")
.setTextColor("rgba(0,255,0,0.5)")
.setArrowColor("#0F0")
.setDirection("buy")
.setTime(1413559061758)
.setPrice(15.5);
Returns chart's symbol.
Returns chart's resolution.
Returns object {from, to}
. from
and to
are Unit timestamps in the timezone of chart.
Returns object with format
function that you can use to format prices. Introduced in 1.5.