How to use HQChart tutorial 30-K-line chart how to dock third party data 26-Indicator script custom function

Add system custom variable functions

JSComplier.AddFunction(obj) can add a custom function to HQChart, which is called before SetOption.

JSComplier.AddVariant({
    
     {
    
    Name:"函数名", Description:"函数描述信息", IsDownload:"是否需要下载数据true/false", Invoke:"方法回调" } );

Name

Function name

Description

Function description information

IsDownload

Whether to download data, if set to false, the NetworkFilter callback will not be triggered
true/false

Invoke

Function method implementation

Custom function data interface

Get data through NetworkFilter callback

this.NetworkFilter=function(data, callback)
{
    
    
     console.log('[KLineChart::NetworkFilter] data', data);
     switch(data.Name)
     {
    
    
         case 'JSSymbolData::GetCustomFunctionData':           //自定义函数数据下载
             this.GetCustomFunctionData(data, callback);
             break;
     }
 }

Protocol name-custom function data download

The class name and function name of the corresponding code: JSSymbolData::GetCustomFunctionData

Screenshot of protocol log

Insert picture description here

Parameter Description

Request field description

FunctionName

Function name

JobItem.Args

parameter list

daterange

K-line data date range

Return json data structure

Data

Data {Date: date, Time: time (only available on minute K-line), Value: numeric value}

DataType

Data structure type
0 = array type, data smoothing
1 = single-valued data
2 = array type data is not smoothed, the default is 0.

For specific data structure, please refer to HQChart tutorial 30-K-line chart how to connect third party data 25-indicator script custom variables

Custom function implementation

If the custom function has a calculation function, you need to implement the calculation function of the custom function, and you need to set the Invoke callback calculation function.
If Invoke is set to null, the downloaded data will be returned directly.
Function format: function(obj)

this.Create=function()  //创建图形
{
    
    
    .............

     JSComplier.AddFunction({
    
    Name:"BUYSTOCK", Description:"用户买入", IsDownload:true, 
             Invoke:(obj)=>this.BUYSTOCK(obj) 
         })

     ..............
     this.Option.NetworkFilter=function(data, callback) {
    
     self.NetworkFilter(data, callback); }; //绑定网络协议回调
     this.Chart.SetOption(this.Option);  //设置K线配置
     ........................
 }

this.BUYSTOCK=function(obj)
 {
    
    
     console.log('[KLineChart::BUYSTOCK] obj', obj);

     return {
    
     Out:10 };
 }

1. Callback function parameter description

Insert picture description here

Args

Function parameters

DownloadData

The function downloads the data, if IsDownload is set to true, the downloaded data is saved here.

KData

K line data

Name

Function name

Period

cycle

Right

Restoration

Symbol

Stock code

ThrowError

Execute exception callback function

2. Return format

{Out: Returned data}

Single value

Such as return {Out:10 };

Array

Such as: return {Out:[1,20,22…] };
The length of the returned data must be consistent with the length of the K line

Exchange QQ group

If you still have questions, you can add to the exchange QQ group: 950092318

HQChart code address

Address: github.com/jones2000/HQChart

Personal hobbies (photography/modeling)

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/jones2000/article/details/112809781