TradingTerminalWidgetOptions
Properties
additional_symbol_info_fields
OptionalAn optional field containing an array of custom symbol info fields to be shown in the Symbol Info dialog.
Refer to Symbology for more information about symbol info.
additional_symbol_info_fields: [
{ title: 'Ticker', propertyName: 'ticker' }
]
Type
auto_save_delay
OptionalA threshold delay in seconds that is used to reduce the number of onAutoSaveNeeded
calls.
auto_save_delay: 5,
Type
number
autosize
OptionalBoolean value showing whether the chart should use all the available space in the container and resize when the container itself is resized.
Default
false
autosize: true,
Type
boolean
brokerConfig
OptionalDefines the configuration flags for the Trading Platform.
Type
broker_config
OptionalDefines the configuration flags for the Trading Platform.
Type
charts_storage_api_version
OptionalA version of your backend. Supported values are: "1.0"
| "1.1"
. Study Templates are supported starting from version "1.1"
.
charts_storage_api_version: "1.1",
Type
charts_storage_url
OptionalSet the storage URL endpoint for use with the high-level saving/loading chart API. Refer to Save and load REST API for more information.
charts_storage_url: 'http://storage.yourserver.com',
Type
string
client_id
OptionalSet the client ID for the high-level saving / loading charts API. Refer to Saving and Loading Charts for more information.
client_id: 'yourserver.com',
Type
string
compare_symbols
Optionalan array of custom compare symbols for the Compare window.
Example:
compare_symbols: [
{ symbol: 'DAL', title: 'Delta Air Lines' },
{ symbol: 'VZ', title: 'Verizon' },
...
];
Type
container
The container
can either be a reference to an attribute of a DOM element inside which the iframe with the chart will be placed or the HTMLElement
itself.
container: "tv_chart_container",
or
container: document.getElementById("tv_chart_container"),
Type
string | HTMLElement
context_menu
OptionalUse this property to override the context menu. You can also change the menu on the fly using the IChartingLibraryWidget.onContextMenu method.
Type
custom_chart_description_function
OptionalUse this property to set your own chart description function. context
will be passed to the function.
This description is read aloud by screen readers when a chart within the layout is selected via the Tab
key.
The function should return either a string with a description or null
to fallback to the default description.
custom_chart_description_function: (context) => {
return Promise.resolve(`Chart ${context.chartIndex + 1} of ${context.chartCount}. ${context.chartTypeName} chart of ${context.symbol}.`);
}
Type
custom_css_url
OptionalAdds your custom CSS to the chart. url
should be an absolute or relative path to the static
folder.
custom_css_url: 'css/style.css',
Type
string
custom_font_family
OptionalChanges the font family used on the chart including the time scale, price scale, and chart's pane. If you want to customize fonts outside the chart, for example, within Watchlist or another widget, you should use the ChartingLibraryWidgetOptions.custom_css_url property to provide custom CSS styles.
Specify custom_font_family
in Widget Constructor as follows:
custom_font_family: "'Inconsolata', monospace",
The custom_font_family
value should have the same format as the font-family
property in CSS.
To use a font that is not available by default on your system, you should first add this font to your custom CSS.
For example, the code sample below imports a Google font into your custom CSS:
@import url('https://fonts.googleapis.com/css2?family=Inconsolata:wght@500&display=swap');
Type
string
custom_formatters
OptionalCustom formatters for adjusting the display format of price, date, and time values.
Example:
custom_formatters: {
timeFormatter: {
format: (date) => {
const _format_str = '%h:%m';
return _format_str
.replace('%h', date.getUTCHours(), 2)
.replace('%m', date.getUTCMinutes(), 2)
.replace('%s', date.getUTCSeconds(), 2);
}
},
dateFormatter: {
format: (date) => {
return date.getUTCFullYear() + '/' + (date.getUTCMonth() + 1) + '/' + date.getUTCDate();
}
},
tickMarkFormatter: (date, tickMarkType) => {
switch (tickMarkType) {
case 'Year':
return 'Y' + date.getUTCFullYear();
case 'Month':
return 'M' + (date.getUTCMonth() + 1);
case 'DayOfMonth':
return 'D' + date.getUTCDate();
case 'Time':
return 'T' + date.getUTCHours() + ':' + date.getUTCMinutes();
case 'TimeWithSeconds':
return 'S' + date.getUTCHours() + ':' + date.getUTCMinutes() + ':' + date.getUTCSeconds();
}
throw new Error('unhandled tick mark type ' + tickMarkType);
},
priceFormatterFactory: (symbolInfo, minTick) => {
if (symbolInfo?.fractional || minTick !== 'default' && minTick.split(',')[2] === 'true') {
return {
format: (price, signPositive) => {
// return the appropriate format
},
};
}
return null; // this is to use default formatter;
},
studyFormatterFactory: (format, symbolInfo) => {
if (format.type === 'price') {
const numberFormat = new Intl.NumberFormat('en-US', { notation: 'scientific' });
return {
format: (value) => numberFormat.format(value)
};
}
if (format.type === 'volume') {
return {
format: (value) => (value / 1e9).toPrecision(format?.precision || 2) + 'B'
};
}
if (format.type === 'percent') {
return {
format: (value) => `${value.toPrecision(format?.precision || 4)} percent`
};
}
return null; // this is to use default formatter;
},
}
Remark: tickMarkFormatter
must display the UTC date, and not the date corresponding to your local timezone.
Type
custom_indicators_getter
OptionalFunction that returns a Promise object with an array of your custom indicators.
PineJS
variable will be passed as the first argument of this function and can be used inside your indicators to access internal helper functions.
Refer to Custom indicators for more information.
custom_indicators_getter: function(PineJS) {
return Promise.resolve([
// *** your indicator object, created from the template ***
]);
},
Type
(PineJS: PineJS) => Promise<readonly CustomIndicator[]>
Type declaration
Function that returns a Promise object with an array of your custom indicators.
PineJS
variable will be passed as the first argument of this function and can be used inside your indicators to access internal helper functions.
Refer to Custom indicators for more information.
custom_indicators_getter: function(PineJS) {
return Promise.resolve([
// *** your indicator object, created from the template ***
]);
},
Signature
(PineJS: PineJS) => Promise<readonly CustomIndicator[]>
Parameters
Name | Type |
---|---|
PineJS | PineJS |
Returns
Promise<readonly CustomIndicator[]>
custom_timezones
OptionalList of custom time zones.
Refer to Timezones for more information.
Type
custom_translate_function
OptionalUse this property to set your own translation function. key
and options
will be passed to the function.
You can use this function to provide custom translations for some strings.
The function should return either a string with a new translation or null
to fallback to the default translation.
For example, if you want to rename "Trend Line" shape to "Line Shape", then you can do something like this:
custom_translate_function: (key, options, isTranslated) => {
if (key === 'Trend Line') {
// patch the title of trend line
return 'Line Shape';
}
return null;
}
Type
datafeed
JavaScript object that implements the datafeed interface (IBasicDataFeed) to supply the chart with data. See Connecting Data for more information on the JS API.
datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com")
Type
IBasicDataFeed | IDatafeedChartApi & IExternalDatafeed & IDatafeedQuotesApi
debug
OptionalSetting this property to true
will make the chart write detailed API logs into the browser console.
Alternatively, you can use the charting_library_debug_mode
featureset to enable it, or use the setDebugMode
widget method (IChartingLibraryWidget.setDebugMode) .
debug: true,
Type
boolean
disabled_features
OptionalThe array containing names of features that should be disabled by default. Feature
means part of the functionality of the chart (part of the UI/UX). Supported features are listed in Featuresets.
Example:
disabled_features: ["header_widget", "left_toolbar"],
Type
drawings_access
OptionalYou can hide some drawings from the toolbar or add custom restrictions for applying them to the chart.
This property has the same structure as the studies_access
argument. Use the same names as you see in the UI.
Remark: There is a special case for font-based drawings. Use the "Font Icons" name for them. Those drawings cannot be enabled or disabled separately - the entire group will have to be either enabled or disabled.
Example
drawings_access: {
type: 'black',
tools: [
{
name: 'Trend Line',
grayed: true
},
]
},
Type
enabled_features
OptionalThe array containing names of features that should be enabled by default. Feature
means part of the functionality of the chart (part of the UI/UX). Supported features are listed in Featuresets.
Example:
enabled_features: ["move_logo_to_main_pane"],
Type
favorites
OptionalSee ChartingLibraryWidgetOptions.favorites
Type
Favorites<TradingTerminalChartTypeFavorites>
fullscreen
OptionalBoolean value showing whether the chart should use all the available space in the window.
Default
false
fullscreen: true,
Type
boolean
header_widget_buttons_mode
OptionalAn additional optional field to change the look and feel of buttons on the top toolbar.
By default (if option is omitted) header will be in adaptive mode (fullsize if the window width allows and icons on smaller windows).
Example:
header_widget_buttons_mode: 'fullsize',
Type
height
OptionalThe desired height of a widget. Please make sure that there is enough space for the widget to be displayed correctly.
height: 600,
Remark: If you want the chart to use all the available space use the fullscreen
parameter instead of setting it to '100%'.
Type
number
interval
The default interval for the chart.
Example:
interval: '1D',
Type
library_path
OptionalA path to a static
folder.
library_path: "charting_library/",
- If you would like to host the library on a separate origin to the page containing the chart then please view the following guide: Hosting the library on a separate origin.
Type
string
load_last_chart
OptionalSet this parameter to true
if you want the library to load the last saved chart for a user. You should implement save/load first to make it work.
load_last_chart: true,
Type
boolean
loading_screen
OptionalCustomization of the loading spinner. Value is an object with the following possible keys:
backgroundColor
foregroundColor
Example:
loading_screen: { backgroundColor: "#000000" }
Type
locale
Locale to be used by the library. See Localization section for details.
locale: 'en',
Type
news_provider
OptionalUse this property to set your own news getter function. Both the symbol
and callback
will be passed to the function.
The callback function should be called with an object. The object should have two properties: title
which is a optional string, and newsItems
which is an array of news objects that have the following structure:
title
(required) - the title of news item.published
(required) - the time of news item in ms (UTC).source
(optional) - source of the news item title.shortDescription
(optional) - Short description of a news item that will be displayed under the title.link
(optional) - URL to the news story.fullDescription
(optional) - full description (body) of a news item.
NOTE: Only title
and published
are the main properties used to compare what has already been published and what's new.
NOTE 2: When a user clicks on a news item a new tab with the link
URL will be opened. If link
is not specified then a pop-up dialog with fullDescription
will be shown.
NOTE 3: If both news_provider
and rss_news_feed
are available then the rss_news_feed
will be ignored.
See News API examples for usage examples.
Type
numeric_formatting
OptionalThe object containing formatting options for numbers. The only possible option is decimal_sign
currently.
numeric_formatting: { decimal_sign: "," },
Type
overrides
OptionalOverride values for the default widget properties
You can override most of the properties (which also may be edited by user through UI)
using overrides
parameter of Widget Constructor. overrides
is supposed to be an object.
The keys of this object are the names of overridden properties.
The values of these keys are the new values of the properties.
Example:
overrides: {
"mainSeriesProperties.style": 2
}
This code will change the default series style to "line". All customizable properties are listed in separate article.
Type
Partial<WidgetOverrides>
restConfig
OptionalConnection configuration settings for Rest Broker API
Type
rss_news_feed
OptionalUse this property to change the RSS feed for news. You can set a different RSS for each symbol type or use a single RSS for all symbols. The object should have the default
property, other properties are optional. The names of the properties match the symbol types. Each property is an object (or an array of objects) with the following properties:
url
- is a URL to be requested. It can contain tags in curly brackets that will be replaced by the terminal:{SYMBOL}
,{TYPE}
,{EXCHANGE}
.name
- is a name of the feed to be displayed underneath the news.
Example
rss_news_feed: {
default: [ {
url: "https://articlefeeds.nasdaq.com/nasdaq/symbols?symbol={SYMBOL}",
name: "NASDAQ"
}, {
url: "http://feeds.finance.yahoo.com/rss/2.0/headline?s={SYMBOL}®ion=US&lang=en-US",
name: "Yahoo Finance"
} ]
},
Example
rss_news_feed: {
"default": {
url: "https://articlefeeds.nasdaq.com/nasdaq/symbols?symbol={SYMBOL}",
name: "NASDAQ"
}
}
Example
rss_news_feed: {
"default": {
url: "https://articlefeeds.nasdaq.com/nasdaq/symbols?symbol={SYMBOL}",
name: "NASDAQ"
},
"stock": {
url: "http://feeds.finance.yahoo.com/rss/2.0/headline?s={SYMBOL}®ion=US&lang=en-US",
name: "Yahoo Finance"
}
}
Type
rss_news_title
OptionalTitle for the News Widget
Type
string
save_load_adapter
OptionalAn object containing the save/load functions. It is used to implement a custom save/load algorithm. Refer to API handlers for more information.
Type
saved_data
OptionalJS object containing saved chart content.
Use this parameter when creating the widget if you have a saved chart already.
If you want to load the chart content when the chart is initialized then use load()
method (IChartingLibraryWidget.load) of the widget.
Type
object
saved_data_meta_info
OptionalJS object containing saved chart content meta info.
Type
settings_adapter
OptionalAn object that contains set/remove functions. Use it to save user settings to your preferred storage, including the server-side one.
Example:
settings_adapter: {
initialSettings: { ... },
setValue: function(key, value) { ... },
removeValue: function(key) { ... },
}
Type
settings_overrides
OptionalThe object that contains new values for values saved to the settings. These overrides will replace any matching values from the settings, regardless of where the settings are loaded from (i.e. local storage or a custom settings adapter). The object is similar to the overrides object.
overrides will not affect values that have been saved to settings so this option can be used instead.
settings_overrides: {
"linetooltrendline.linecolor": "blue"
}
Type
snapshot_url
OptionalThis URL is used to send a POST request with binary chart snapshots when a user presses the snapshot button.
This POST request contains multipart/form-data
with the field preparedImage
that represents binary data of the snapshot image in image/png
format.
This endpoint should return the full URL of the saved image in the response.
snapshot_url: "https://myserver.com/snapshot",
Type
string
studies_access
OptionalYou can hide some studies from the toolbar or add custom restrictions for applying them to the chart.
Example
studies_access: {
type: "black" | "white",
tools: [
{
name: "<study name>",
grayed: true
},
< ... >
]
}
Type
studies_overrides
OptionalUse this option to customize the style or inputs of the indicators.
You can also customize the styles and inputs of the Compare
series using this argument.
Refer to Indicator Overrides for more information.
Overrides for built-in indicators are listed in StudyOverrides.
studies_overrides: {
"volume.volume.color.0": "#00FFFF",
},
Type
Partial<StudyOverrides>
study_count_limit
OptionalMaximum amount of studies allowed at one time within the layout. Minimum value is 2.
study_count_limit: 5,
Type
number
symbol
OptionalThe default symbol for the chart.
Example:
symbol: 'AAPL',
Type
string
symbol_search_complete
OptionalUse this property to set a function to override the symbol input from the Symbol Search.
For example, you may want to get additional input from the user before deciding which symbol should be resolved.
The function should take two parameters: a string
of input from the Symbol Search and a optional search result item. It should return a Promise
that resolves with a symbol ticker and a human-friendly symbol name.
NOTE: This override is not called when adding a symbol to the watchlist.
{
// `SearchSymbolResultItem` is the same interface as for items returned to the Datafeed's searchSymbols result callback.
symbol_search_complete: (symbol: string, searchResultItem?: SearchSymbolResultItem) => {
return new Promise((resolve) => {
let symbol = getNewSymbol(symbol, searchResultItem);
let name = getHumanFriendlyName(symbol, searchResultItem)
resolve({ symbol: symbol, name: name });
});
}
}
Type
SymbolSearchCompleteOverrideFunction
symbol_search_request_delay
OptionalA threshold delay in milliseconds that is used to reduce the number of search requests when the user enters the symbol name in the Symbol Search.
symbol_search_request_delay: 1000,
Type
number
theme
OptionalSet predefined custom theme color for the chart. Supported values are: "light"
| "dark"
.
theme: "light",
Type
time_frames
OptionalList of visible time frames that can be selected at the bottom of the chart. See Time frame toolbar for more information. Time frame is an object containing the following properties:
Example:
time_frames: [
{ text: "50y", resolution: "6M", description: "50 Years" },
{ text: "3y", resolution: "1W", description: "3 Years", title: "3yr" },
{ text: "8m", resolution: "1D", description: "8 Month" },
{ text: "3d", resolution: "5", description: "3 Days" },
{ text: "1000y", resolution: "1W", description: "All", title: "All" },
]
Type
time_scale
OptionalAn additional optional field to add more bars on screen.
Example:
time_scale: {
min_bar_spacing: 10,
}
Type
timeframe
OptionalSets the default time frame of the chart.
The time frame can be relative to the current date, or a range.
A relative time frame is a number with a letter D for days and M for months:
timeframe: '3M',
A range is an object with to and from properties. The to and from properties should be UNIX timestamps:
timeframe: { from: 1640995200, to: 1643673600 } // from 2022-01-01 to 2022-02-01
Note: When using a range the chart will still request data up to the current date. This is to enable scrolling forward in time once the chart has loaded.
Type
timezone
OptionalDefault time zone of the chart. The time on the timescale is displayed according to this time zone.
See the list of supported time zones for available values. Set it to exchange
to use the exchange time zone. Use the ChartingLibraryWidgetOptions.overrides section if you wish to override the default value.
timezone: "America/New_York",
Type
"exchange" | Timezone
toolbar_bg
OptionalBackground color of the toolbars.
toolbar_bg: '#f4f7f9',
Type
string
trading_customization
OptionalOverride customizations for trading
Type
user_id
OptionalSet the user ID for the high-level saving / loading charts API. Refer to Saving and Loading Charts for more information.
user_id: 'public_user_id',
Type
string
widgetbar
OptionalSettings for the widget panel on the right side of the chart.
Watchlist, news, details and data window widgets on the right side of the chart can be enabled using the widgetbar
field in Widget Constructor
Type
width
OptionalThe desired width of a widget. Please make sure that there is enough space for the widget to be displayed correctly.
width: 300,
Remark: If you want the chart to use all the available space use the fullscreen
parameter instead of setting it to '100%'.
Type
number
Methods
broker_factory
OptionalUse this field to pass the function that returns a new object which implements Broker API. This is a function that accepts the Trading Host (IBrokerConnectionAdapterHost).
Example
broker_factory: function(host) { ... }
Signature
broker_factory(host: IBrokerConnectionAdapterHost) => IBrokerTerminal | IBrokerWithoutRealtime
Parameters
Name | Type | Description |
---|---|---|
host | IBrokerConnectionAdapterHost | Trading Host |