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 章节 ...
随机推荐
- HDU 5928 DP 凸包graham
给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...
- Docker查看映射卷报错
问题描述: 当查看Docker容器的映射卷时出现报错信息,如下: [root@kazihuo ~]# docker inspect -f {{.Volumes}} volume #volume指容 ...
- nginx 跨域配置
server { listen 80; server_name b.com; location /{ if ( $http_referer ~* (a.com|b.com|c.com) ) { Acc ...
- 100baseT、100baseFX、1000base-SX、100/1000base-T
100baseT.100baseFX.1000base-SX.100/1000base-T 100baseT.100baseFX都是100Mbps速率基带传输系统,唯一的不同是100baseT用的是双 ...
- Anaconda+django写出第一个web app(五)
今天开始学习网页风格和设计,就像python有Web框架一样,也有一些CSS框架.对于CSS框架,我们可以使用默认的样式,也可以在原基础上编辑修改.本教程使用的是materialize这个CSS框架[ ...
- 适配器在JavaScript中的体现
适配器设计模式在JavaScript中非常有用,在处理跨浏览器兼容问题.整合多个第三方SDK的调用,都可以看到它的身影. 其实在日常开发中,很多时候会不经意间写出符合某种设计模式的代码,毕竟设计模式就 ...
- 配置replica set的常见问题
总有人问起配置ReplicaSet不成功,总结了一下基本上的可能性就几种,检查步骤如下: 假设三台机器的IP分别是 A: 192.168.1.2 a.test.com B:192.168.1.3 b. ...
- 【逆向知识】PE ASLR
1.知识点 微软从windows vista/windows server 2008(kernel version 6.0)开始采用ASLR技术,主要目的是为了防止缓冲区溢出 ASLR技术会使PE文件 ...
- 音频增益响度分析 ReplayGain 附完整C代码示例【转】
转自:http://www.cnblogs.com/cpuimage/p/8846951.html 人们所熟知的图像方面的3A算法有: AF自动对焦(Automatic Focus)自动对焦即调节摄像 ...
- oracle11g的冷热备份
1.冷备份 如果数据库可以正常关闭,而且允许关闭足够长的时间,那么就可以采用冷备份(脱机备份),可以是归档冷备份,也可以是非归档冷备份.其方法是首先关闭数据库,然后备份所有的物理文件,包括数据文件.控 ...