第五天:5天免费搭建个人量化平台 - 自定义功能和指标

第五天:5天免费搭建个人量化平台 - 自定义功能和指标

1. 修改图形及各式设置

设置默认:https://aitrade.ga/books/tradingview/book/Drawings-Overrides.html

e.g.

linetoolhorzline: {

linecolor: ‘rgba( 128, 204, 219, 1)’,

linewidth: 1.0,

linestyle: LINESTYLE_SOLID,

showPrice: true,

showLabel: false,

text: ‘’,

font: ‘Verdana’,

textcolor: ‘rgba( 21, 119, 96, 1)’,

fontsize: 12,

bold:false,

italic:false,

horzLabelsAlign: ‘center’,

vertLabelsAlign: ‘top’

},

颜色设置:https://tool.oschina.net/commons?type=3

其他基本设置:https://aitrade.ga/books/tradingview/book/Overrides.html

形状设置: https://aitrade.ga/books/tradingview/book/Shapes-and-Overrides.html

帮助文档: https://aitrade.ga/books/tradingview/book/Home.html

2. 自定义指标

如果想要在图表上显示一些自定义数据或指标, 例如增加持仓量:

(1) 为数据创建一个新的ticker,并设置您的服务器返回此ticker有效的SymbolInfo。

(2) 设置服务器以返回此ticker的有效历史数据。

(3) 在tv.html 的new TradingView.widget 中加入custom_indicators_getter

def symbol(request):

symbol= request.GET.get("symbol",'').upper()

dict={}

if '_OI' in symbol:

	

	dict={

			"name":symbol+'_OI',

			"exchange-traded":"",

			"exchange-listed":"",

			"timezone":"Asia/Shanghai",

			"minmov":1,

			"minmov2":0,

			"pointvalue":1,

			"session":"2100-0100,0900-1130,1330-1500",

			"has_intraday":True,

			"has_empty_bars":False,

			"has_no_volume":False,

			"description":"OI",

			"type":"",

			"supported_resolutions":["15","30","60","D","W","M","6M"],

			"pricescale":1,

			"ticker":symbol+'_OI',

			"has_daily":True

在 def history(request) 加入:

if ‘_OI’ in code.upper():

		out['o']=data['openInt'].values.tolist() 

		out['h']=data['openInt'].values.tolist()

		out['l']=data['openInt'].values.tolist() 

		out['c']=data['openInt'].values.tolist() 

		out['v']=data['openInt'].values.tolist() 

在tv.html 的new TradingView.widget 中加入:

custom_indicators_getter: function(PineJS) {

			         return Promise.resolve([

		        	 {

					    name: "OI",

					    metainfo: {

					        "_metainfoVersion": 40,

					        "id": "OI@tv-basicstudies-1",

					        "scriptIdPart": "",

					        "name": "OI",

					        "description": "OI",

					        "shortDescription": "OI",

					        '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,

					                    "trackPrice": true,

					                    "transparency": 40,

					                    "color": "#880000"

					                }

					            },

					            "precision": 1,

					            "inputs": {}

					        },

					        "styles": {

					            "plot_0": {

					                "title": "OI value",

					                "histogramBase": 0,

					            }

					        },

					        "inputs": [],

					    },

					    constructor: function() {

					        this.init = function(context, inputCallback) {

					            this._context = context;

					            this._input = inputCallback;

					            var symbol = PineJS.Std.ticker(this._context).split('"')[1]+'_OI';

					            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 v = PineJS.Std.close(this._context);

					            return [v];

					        }

					    }

					}

			             

			         ]);

			     },

			});

			

			widget.onChartReady(function() {

			     widget.chart().createStudy('OI', false, true);

			 });

这样可以随意增加自己感兴趣的自定义数据或指标。

关注公众号"期权量化adog” 、知识星球"adog量化和AI", 下载相关资料/源码和数据。
http://adog.net.cn在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿岛格

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值