TradingView 自定义指标

TradingView 允许用户通过编写 JS 源文件(customIndex.js)来创建自定义技术指标。用户在 main 函数中处理 getBar 返回的数据,然后在 onChartReady 中调用 createStudy 添加到图表上。例如,创建自定义 RSI 曲线。自定义数据源可以从 getBar 的回调或通过向后台请求获取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TradingView 支持自定义指标,不过是把你要定义的指标写成一个 JS 源文件(customIndex.js),放在图表库 static 文件夹下。自定义指标 JS 源代码模板如下:

 1 __customIndicators = [
 2     {
 3         name: 'ShuBenRSI',
 4         metainfo: {
 5             '_metainfoVersion': 40,
 6             'id': 'ShuBenRSI@tv-basicstudies-1',
 7             'scriptIdPart': '',
 8             'name': 'ShuBenRSI',
 9             'description': 'ShuBenRSI',
10             'shortDescription': 'ShuBenRSI',
11             'is_hidden_study': true,
12             'is_price_study': true,
13             'isCustomIndicator': true,
14             'plots': [{'id': 'plot_0', 'type': 'line'}],
15             'defaults': {
16                 'styles': {
17                     'plot_0': {
18                         'linestyle': 0,
19                         'visible': true,
20                         'linewidth': 1,
21                         'plottype': 2, // 绘制类型为线形图: 2
22                         'trackPrice': true,
23                         'transparency': 40,
24                         'color': '#880000'
25                     }
26                 },
27                 'precision': 1, // 精度 eg:608.4
28                 'inputs': {}
29             },
30             'styles': {
31                 'plot_0': {
32                     'title': 'ShuBenRSI',
33                     'histogrambase': 0,
34                 }
35             },
36             'inputs': [],
37         },
38         constructor: function () {
39             this.init = function (context, inputCallback) {
40                 this._context = context;
41                 this._input = inputCallback;
42                 //var symbol = 'p1905';
43                 var symbol = PineJS.Std.ticker(this._context); // 获取所选商品代码
44                 this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
45             };
46             this.main = function (context, inputCallback) {
47                 this._context = context;
48                 this._input = inputCallback;
49                 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值