gpt4 book ai didi

javascript - 如何在reactjs中的交易 View 图表库中添加自定义指标

转载 作者:行者123 更新时间:2023-12-05 00:33:01 25 4
gpt4 key购买 nike

我有交易 View 图表库,我正在研究它,但现在我想在其中添加自定义指标,但我不知道该怎么做。

最佳答案

我找到了解决方案
将 Prop 中的 custom_indicators_getter 传递给交易 View 默认 Prop
像这样

 custom_indicators_getter: function (PineJS) {
return Promise.resolve([
{
name: "Bar Colorer Demo",
metainfo: {
_metainfoVersion: 51,

id: "BarColoring@tv-basicstudies-1",
name: "BarColoring",
description: "Bar Colorer Demo",
shortDescription: "BarColoring",

isCustomIndicator: true,
isTVScript: false,
isTVScriptStub: false,

format: {
type: "price",
precision: 4,
},

defaults: {
palettes: {
palette_0: {
// palette colors
// change it to the default colors that you prefer,
// but note that the user can change them in the Style tab
// of indicator properties
colors: [{ color: "#FFFF00" }, { color: "#0000FF" }],
},
},
},
inputs: [],
plots: [
{
id: "plot_0",

// plot type should be set to 'bar_colorer'
type: "bar_colorer",

// this is the name of the palette that is defined
// in 'palettes' and 'defaults.palettes' sections
palette: "palette_0",
},
],
palettes: {
palette_0: {
colors: [{ name: "Color 0" }, { name: "Color 1" }],

// the mapping between the values that
// are returned by the script and palette colors
valToIndex: {
100: 0,
200: 1,
},
},
},
},
constructor: function () {
this.main = function (context, input) {
this._context = context;
this._input = input;

var valueForColor0 = 100;
var valueForColor1 = 200;

// perform your calculations here and return one of the constants
// that is specified as a key in 'valToIndex' mapping
var result =
(Math.random() * 100) % 2 > 1 // we randomly select one of the color values
? valueForColor0
: valueForColor1;

return [result];
};
},
},
]);
},

And after this onChartReady
tvWidget.onChartReady(() => {
//Bar Colorer Demo是我们在description中传入的名字
widget.activeChart().createStudy("Bar Colorer Demo", false, true);
})

关于javascript - 如何在reactjs中的交易 View 图表库中添加自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70528210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com