Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add multi-chart support to policies in the Internet

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to add multi-chart support to the strategy on the Internet. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Especially when writing trend strategies, sometimes they are confused by the trigger conditions of various indicators, so there is an urgent need to make the data visual and easy to analyze and view. When adding a single chart to a policy, you can directly use the Line drawing Class Library template to draw a picture. However, sometimes multiple charts are required, and there are different K-line periods, and even the indicators have to use the Y axis alone. In this way, you need to implement the drawing code separately.

The following is an example that can be used as a reference. I will comment line by line on the sample code. When you finish reading the code, you will have a new understanding of adding chart support to the strategy.

/ * backteststart: 2019-07-01 00:00:00end: 2019-08-24 00:00:00period: 1hexchanges: [{"eid": "Futures_OKCoin", "currency": "BTC_USD"}] args: [["IsSynthesisDayKL", true]] * / var chart0 = {_ isStock: true, / / * extension: {layout: 'single' Height: 300,}, / / * / title: {text: 'daily K chart'}, xAxis: {type: 'datetime'} Series: [{type: 'candlestick', name:' ringing, id:'r' Data: []}} var chart1 = {_ _ isStock: true, / * extension: {layout: 'single', height: 300 }, / / * / title: {text: 'EMA'}, xAxis: {type:' datetime'}, series: [{type: 'candlestick' Name:'R1 line', id: 'R1Qing, data: []}, {type:' line' Name: 'chart1_EMA1', data: [],}, {type:' line', name: 'chart1_EMA2' Data: []}} var chart2 = {_ _ isStock: true, / * extension: {layout: 'single', height: 300,}, / / * / title: {text:' MACD'} XAxis: {type: 'datetime'}, yAxis: [{title: {text:' price'}, opposite: false} {title: {text: "indicator axis"}, opposite: true,}], series: [{type: 'candlestick', name:' R2' Id:'R2, data: []}, {type: 'line', yAxis: 1, name:' dif', data: []} {type: 'line', yAxis: 1, name:' dea', data: []} function CreatePlotter (e, chart) {var obj = {} / / declare an empty object Used to add a method in the following code, and finally return this object, that is, the constructed drawing object. The exchange object reference from the obj.e = e / / parameter is assigned to a property of the obj object obj.params = {} / / Construction parameter obj.params.EMA_param1 = 5 / / We preset some parameters of the index on the chart, which are used in the index calculation. For example, an EMA indicator line parameter obj.params.EMA_param2 = 20 / / the second EMA indicator line parameter, usually a small parameter is called a block line The one with large parameters is called slow line obj.params.MACD_fast = 12 / / MACD parameter obj.params.MACD_slow = 26 / / MACD parameter obj.params.MACD_sig = 9 / / MACD parameter obj.runTime = {} / / used to store some data at run time obj.runTime.arrPreBarTime = [0,0 0] / / the timestamp of the previous bar that stores each K-line data A method for comparing obj.GetAllRecords = function () {/ / drawing objects to obtain K-line data. In our example, three charts are displayed at the same time, so this function simultaneously obtains the K-line data of three different periods of K-line data obj.r = _ C (obj.e.GetRecords, PERIOD_H1) / / the K-line data of the first chart. It is 1 hour level K line data Sleep (1000) obj.r1 = _ C (obj.e.GetRecords, PERIOD_M15) / / the K line data of the second chart, and the 15 minute level K line data Sleep (1000) obj.r2 = _ C (obj.e.GetRecords, PERIOD_D1) / / the K line data of the third chart Is the daily K-line data} obj.Run = function () {/ / execute the function of the drawing object obj.Plot () / / execute the specific drawing code} obj.CalcMACD = function (r, fast, slow, sig) {/ / MACD indicator calculation function Returns MACD metric data if (r.length)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report