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