TradingView 自定义指标
TradingView 支持自定义指标,不过是把你要定义的指标写成一个 JS 源文件(customIndex.js),放在图表库 static 文件夹下。自定义指标 JS 源代码模板如下:
__customIndicators = [
{
name: 'ShuBenRSI',
metainfo: {
'_metainfoVersion': 40,
'id': 'ShuBenRSI@tv-basicstudies-1',
'scriptIdPart': '',
'name': 'ShuBenRSI',
'description': 'ShuBenRSI',
'shortDescription': 'ShuBenRSI',
'is_hidden_study': true,
'is_price_study': true,
'isCustomIndicator': true,
'plots': [{'id': 'plot_0', 'type': 'line'}],
'defaults': {
'styles': {
'plot_0': {
'linestyle': 0,
'visible': true,
'linewidth': 1,
'plottype': 2, // 绘制类型为线形图: 2
'trackPrice': true,
'transparency': 40,
'color': '#880000'
}
},
'precision': 1, // 精度 eg:608.4
'inputs': {}
},
'styles': {
'plot_0': {
'title': 'ShuBenRSI',
'histogrambase': 0,
}
},
'inputs': [],
},
constructor: function () {
this.init = function (context, inputCallback) {
this._context = context;
this._input = inputCallback;
//var symbol = 'p1905';
var symbol = PineJS.Std.ticker(this._context); // 获取所选商品代码
this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
};
this.main = function (context, inputCallback) {
this._context = context;
this._input = inputCallback;
this._context.select_sym(1);
if(this._context['symbol']['time'] != NaN){
var c = PineJS.Std.close(this._context)-50;
var o = PineJS.Std.open(this._context)-50;
var l = PineJS.Std.low(this._context)-50;
var h = PineJS.Std.high(this._context)-50;
console.log('execute custom index!');
console.log('symbol: ', this._context['symbol']['time']);
return [o, c];
} }
}
}
];
自定义指标 JS
其中 main 方法会根据数据量(getBar 中的后台获取的数据)的多少自动进行循环遍历,在此可以对数据进行修改,以创建自己的数据曲线(个人理解)

即 new TradingView.widget() 中使用 indicators_file_name: 'customIndex.js'
onChartReady() 中将定义指标添加到页面显示中 widget.chart().createStudy('ShuBenRSI', false, false); // 自定义 RSI 曲线
自定义的曲线数据源来自 getBar 方法中回调函数中的 bar 数据,可以在自定义模板中修改此数据。
__customIndicators = [
{
name: 'ShuBenRSI',
metainfo: {
'_metainfoVersion': 40,
'id': 'ShuBenRSI@tv-basicstudies-1',
'scriptIdPart': '',
'name': 'ShuBenRSI',
//当调用createStudy方法时,它也被用作“name”参数
'description': 'ShuBenRSI',
// 该描述将显示在图表上
'shortDescription': 'ShuBenRSI',
'is_hidden_study': true,
// 指标曲线是否在主数据列窗口中显示
'is_price_study': true,
'isCustomIndicator': true,
'plots': [{'id': 'plot_0', 'type': 'line'}],
'defaults': {
'styles': {
'plot_0': {
'linestyle': 0,
'visible': true,
'linewidth': 1,
'plottype': 2, // 绘制类型为线形图: 2
'trackPrice': true,
'transparency': 40,
'color': '#880000'
}
},
'precision': 3, // 精度 eg:608.4
'inputs': {}
},
'styles': {
'plot_0': {
'title': 'ShuBenRSI',
'histogrambase': 0,
}
},
'inputs': [],
},
constructor: function () {
this.init = function (context, inputCallback) {
var host = window.location;
var host1 = host.href.split('static');
var fakeDataRSI = [];
$.ajaxSetup({ async: false });
$.post(host1[0] + 'cta_posPL_syetem/getChartData',{method:'getDataRSI'}, function (result) {
if(result.result_code == 'success'){
fakeDataRSI = result.data;
} });
this.fakeData = fakeDataRSI;
this.count = 0;
this.time = 0;
this.rsi = 0;
this.infoList = [];
//console.log('init context: ', context);
//console.log(this.count);
this._context = context;
this._input = inputCallback;
//var symbol = 'p1905';
var symbol = PineJS.Std.ticker(this._context); // 获取所选商品代码
this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
};
this.main = function (context, inputCallback) {
//this.count += 1;
//console.log('count: ',this.count);
//if(this.count<5)console.log('main fakeData: ', this.fakeData[this.count]);
this._context = context;
this._input = inputCallback;
this._context.select_sym(1);
/*
// RSI 计算
if(this.count > 1 && this.time != this._context['symbol']['time']){
//console.log(PineJS.Std.close(this._context));
this.infoList.push(PineJS.Std.close(this._context));
var upSum = 0;var downSum = 0;
if(this.count > 15){
for(var i = 1; i <= 14; i++){
var change = this.infoList[i] - this.infoList[i - 1];
change > 0 ? upSum += change : downSum -= change;
}
var rs = Math.round(upSum / 14 *1000) / downSum;
this.rsi = Math.round(rs / (1 + rs) * 100 * 1000) / 1000;
//console.log('current: ', this._context['symbol']['time'], 'pretime: ',this.time);
//console.log('infoList: ',this.infoList);
this.infoList.splice(0, 1);
this.time = this._context['symbol']['time'];
//console.log('index close: --- >', PineJS.Std.close(this._context));
return [this.rsi];
}
}
return [this.rsi];
*/
var c = this.fakeData[this.count++]['close'];
//console.log('rsi: ',this.rsi); return [c];
/*
var c = PineJS.Std.close(this._context)-50;
var o = PineJS.Std.open(this._context)-50;
var l = PineJS.Std.low(this._context)-50;
var h = PineJS.Std.high(this._context)-50;
//console.log('execute custom index!');
console.log('symbol: ', this._context['symbol']['time']);
//return [o, c];
*/
}
}
}
];
自定义指标曲线
如果你想要自定义的曲线数据并不是 K 线数据,你可以在自定义模板中,向后台请求 用后台返回的数据。eg:
__customIndicators = [
{
name: 'ShuBenRSI',
metainfo: {
'_metainfoVersion': 40,
'id': 'ShuBenRSI@tv-basicstudies-1',
'scriptIdPart': '',
'name': 'ShuBenRSI',
//当调用createStudy方法时,它也被用作“name”参数
'description': 'ShuBenRSI',
// 该描述将显示在图表上
'shortDescription': 'ShuBenRSI',
'is_hidden_study': true,
'is_price_study': false,
'isCustomIndicator': true,
'plots': [{'id': 'plot_0', 'type': 'line'}],
'defaults': {
'styles': {
'plot_0': {
'linestyle': 0,
'visible': true,
'linewidth': 1,
'plottype': 2, // 绘制类型为线形图: 2
'trackPrice': true,
'transparency': 40,
'color': '#880000'
}
},
'precision': 3, // 精度 eg:608.4
'inputs': {}
},
'styles': {
'plot_0': {
'title': 'ShuBenRSI',
'histogrambase': 0,
}
},
'inputs': [],
},
constructor: function () {
this.init = function (context, inputCallback) {
var host = window.location.href.split('static')[0];
var fakeDataRSI = [];
$.ajaxSetup({ async: false });
$.post(host + 'cta_posPL_syetem/getChartData',{method:'getDataRSI'}, function (result) {
if(result.result_code == 'success'){
fakeDataRSI = result.data;
}
});
this.fakeData = fakeDataRSI;
this.count = 0;
this.time = 0;
this.rsi = 0;
this.infoList = [];
this._context = context;
this._input = inputCallback;
var symbol = PineJS.Std.ticker(this._context); // 获取所选商品代码
this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
};
this.main = function (context, inputCallback) {
this._context = context;
this._input = inputCallback;
this._context.select_sym(1);
var c = this.fakeData[this.count++]['close'];
return [c];
}
}
}
];
数据源不是 K 线数据
TradingView 自定义指标的更多相关文章
- AWS EC2 复制实例后,自定义指标无法显示数据
从一个实例创建了一个AMI,然后通过这个AMI创建新的EC2实例,结果发票自定义指标不会显示: 系统一直在邮件中提示: print() on closed filehandle MDATA at Cl ...
- kubernetes学习笔记之十二:资源指标API及自定义指标API
第一章.前言 以前是用heapster来收集资源指标才能看,现在heapster要废弃了从1.8以后引入了资源api指标监视 资源指标:metrics-server(核心指标) 自定义指标:prome ...
- k8s-资源指标API及自定义指标API-二十三
一. 原先版本是用heapster来收集资源指标才能看,但是现在heapster要废弃了. 从k8s v1.8开始后,引入了新的功能,即把资源指标引入api: 在使用heapster时,获取资源指标是 ...
- Kubernetes 学习23 kubernetes资源指标API及自定义指标API
一.概述 1.上集中我们说到,官方文档提示说从k8s 1.11版本开始,将监控体系指标数据获取机制移向新一代的监控模型.也就意味着对于我们的k8s来讲现在应该有这样两种资源指标被使用.一种是资源指标, ...
- k8s之自定义指标API部署prometheus
1.自定义指标-prometheus node_exporter是agent;PromQL相当于sql语句来查询数据; k8s-prometheus-adapter:prometheus是不能直接解析 ...
- k8s系列---资源指标API及自定义指标API
不得不说千万不要随意更改版本,我用的1.13的版本,然后学到这一步时,还因yaml文件不同,卡住了很久,然后各种google才找到解决办法 https://www.linuxea.com/2112. ...
- 简单4步,利用Prometheus Operator实现自定义指标监控
本文来自Rancher Labs 在过去的文章中,我们花了相当大的篇幅来聊关于监控的话题.这是因为当你正在管理Kubernetes集群时,一切都会以极快的速度发生变化.因此有一个工具来监控集群的健康状 ...
- Prometheus自定义指标
1. 自定义指标 为了注册自定义指标,请将MeterRegistry注入到组件中,例如: public class Dictionary { private final List<String ...
- Kubernetes 监控:Prometheus Adpater =》自定义指标扩缩容
使用 Kubernetes 进行容器编排的主要优点之一是,它可以非常轻松地对我们的应用程序进行水平扩展.Pod 水平自动缩放(HPA)可以根据 CPU 和内存使用量来扩展应用,前面讲解的 HPA 章节 ...
随机推荐
- [IOI2011]Race
2599: [IOI2011]Race Time Limit: 70 Sec Memory Limit: 128 MBhttp://www.lydsy.com/JudgeOnline/problem ...
- SQL语句(十八)—— 存储过程
存储过程 系统存储过程 自定义存储过程 扩展存储过程 一.创建存储过程 创建存储过程 --例1 USE SU GO Create Procedure SelProc AS Select * From ...
- 六、强大的 Stream API
一.了解 Stream Java8中有两大最为重要的改变.第一个是 Lambda 表达式:另外一个则是 Stream API(java.util.stream.*).Stream 是 Java8 中处 ...
- springmvc转springboot过程中访问jsp报Whitelabel Error Page错误
前言: 虽然springboot内嵌了一个tomcat,但是这个内嵌的tomcat不支持jsp页面,所以需要引入其他包 解决: maven引入以下包即可 <dependency> < ...
- 20155227 2016-2017-2 《Java程序设计》第七周学习总结
20155227 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 认识时间与日期 时间的度量 世界时:在1972年引入UTC之前,GMT与UT是相同的. 国际 ...
- HDU 1715 大斐波数 加法高精度
解题报告:求 斐波那契数,不过这题的n的范围是1000,肯定是早就超过了的,所以要用到高精度,所以这题其实就是一个加法高精度的题. 我的做法 是写一个大数相加的函数,然后打表就是了,这里注意的就是每次 ...
- 【codeforces】【比赛题解】#872 CF Round #440 (Div.2)
链接. [A]寻找漂亮数字 题意: 给定了两列非零数字.我们说一个数是漂亮的,当它的十进制表达中有至少一个数从数列一中取出,至少有一个数从数列二中取出.最小的漂亮数字是多少? 输入: 第一行两个数\( ...
- 【四校联考】【比赛题解】FJ NOIP 四校联考 2017 Round 7
此次比赛为厦门一中出题.都是聚劳,不敢恭维. 莫名爆了个0,究其原因,竟然是快读炸了……很狗,很难受. 话不多说,来看看题: [T1] 题意: 样例: PS:1<=h[i]<=100000 ...
- 【技巧总结】Penetration Test Engineer[1]-Basic
1.渗透测试基础 1.1.渗透测试分类 黑盒测试:从远程网络位置来评估目标网络基础设施,没有任何相关信息 白盒测试:内部发起,了解到关于目标环境的所有内部与底层知识 灰盒测试:结合两者优势,根据对目标 ...
- ORACLE表空间查询和管理【转】
红色是自由指定的~~--查询表空间SELECT D.TABLESPACE_NAME, SPACE "SUM_SPACE(M)", SPACE - NVL(F ...