在 Tradingview 平台上使用 Pine 中的 LABEL 功能获取数据的问题
Problems with getting data using the LABEL functionality in Pine on the Tradingview platform
我正在使用 Tradingview.
上 Pinescript
的一部分函数 该函数确定系列的枢轴点。我用它来 collect Pivot Points for the RSI.
功能有效;然而,我想做的是生成一个只有 Pivot Points
生成的 or a zero
的系列( 参见下面的图片 #1)。如果获取的数字(对于枢轴点)是正确的,那么我应该能够将它们绘制在图表上 - 而且 - 它们会在黄色标签下结束(见图 #2下面)
背景
为此,我正在使用 label.get_text()
,如下所示:https://kodify.net/tradingview/labels/get-text/[1]
这样做时,我遇到了以下问题:
无法验证数据是否分配正确
我需要将值转换为浮点数。当做类似 float( label.get_text()),
的事情时,我得到了一个错误
line 270: Cannot call 'float' with arguments (series[string]);
available overloads: float(const float) => const float; float(input
float) => input float; float(float) => float; float(series[float]) =>
series[float];
问题
- 如何在 Pine 中将字符串转换为浮点数
- 我想收集一系列枢轴点。理想情况下,最高分有一个系列,最低分有另一个系列。
任何帮助、提示或建议将不胜感激
TIA
图片 1
图片 2
功能:create_pivot_points
create_pivot_points(src, len, isHigh, _style, _yloc, _color, _textcolor, _offset, _plot_data) =>
[ ... snip ...]
pivot_src_len = len
p = nz(src[pivot_src_len])
isFound = true
for i = 0 to len - 1
if isHigh and src[i] > p
isFound := false
if not isHigh and src[i] < p
isFound := false
for i = len + 1 to 2 * len
if isHigh and src[i] >= p
isFound := false
if not isHigh and src[i] <= p
isFound := false
if isFound
if isHigh // printing the highest high pivots
NOTE: I am using the command below label.XXXX to try to get information about the label
pivotPointHighLabel = label.new(bar_index[pivot_src_len], int(p) + 10 , tostring(truncate(p,2)), style=_style, yloc=_yloc, color=noneColor, textcolor=noneColor)
high_kdcLabel_XCoords := label.get_x( pivotPointHighLabel )
high_kdcLabel_YCoords := label.get_y( pivotPointHighLabel )
high_kdcLabel_Data := float( label.get_text( pivotPointHighLabel ) ) <---- receiving error message here when attempting to change value from a STRING to a FLOAT
high_kdcLabel_Bool := high_kdcLabel_Data == 0.0 ? false : true
if _plot_data //make the labels visible
label.set_color(pivotPointHighLabel, _color)
label.set_textcolor(pivotPointHighLabel, _textcolor)
else // printing the lowest low pivots (assume isLow has been activated)
[ ... snip ...]
// returning information below to calling code
[high_kdcLabel_XCoords, high_kdcLabel_YCoords, high_kdcLabel_Data, high_kdcLabel_Bool, low_kdcLabel_XCoords, low_kdcLabel_YCoords, low_kdcLabel_Data, low_kdcLabel_Bool]
主要代码:
[ ... snip ...]
if plotUpperPivotPoint
[hin_x_coords, hin_y_coords, hin_label_data, hin_bool_data, lin_x_coords, lin_y_coords, lin_label_data, lin_bool_data] =
pivothl(osc, len, true , label.style_labeldown, yloc.price, color.yellow, color.black, 0, plotUpperPivotPoint)
high_x_coords := hin_x_coords
high_y_coords := hin_y_coords
high_label_data := hin_label_data
high_bool_data := hin_bool_data
f_print( tostring(high_label_data) )
// attempting to test any data retrieved to see if it will work with the labels.
// if the list of Upper Limits (Pivots) is correct, the BLUE heart-beat spikes on the picture below
// should match right under the yellow labels
testme = high_label_data == 0 ? 0 : 70
plot( testme, offset=-lbR, color=color.blue )
很难从你的代码片段中弄清楚事情,但是给定一个像 pivothigh()
这样的函数,当找到一个时,returns 是枢轴的值,否则 na
,你可以使用代码像这样:
//@version=4
study("", "", true)
i_legs = input(4)
// When a non `na` value is returned, use zero, otherwise use the value.
pHi = nz(pivothigh(i_legs, i_legs))
plot(pHi)
代码在检测到支点时构建系列,它在实际支点之后 i_legs
,这与大多数支点指标绘制支点的方式相反,即通过抵消过去的 i_legs
条柱:
我正在使用 Tradingview.
上 Pinescript
的一部分函数 该函数确定系列的枢轴点。我用它来 collect Pivot Points for the RSI.
功能有效;然而,我想做的是生成一个只有 Pivot Points
生成的 or a zero
的系列( 参见下面的图片 #1)。如果获取的数字(对于枢轴点)是正确的,那么我应该能够将它们绘制在图表上 - 而且 - 它们会在黄色标签下结束(见图 #2下面)
背景
为此,我正在使用 label.get_text()
,如下所示:https://kodify.net/tradingview/labels/get-text/[1]
这样做时,我遇到了以下问题:
无法验证数据是否分配正确
我需要将值转换为浮点数。当做类似
float( label.get_text()),
的事情时,我得到了一个错误
line 270: Cannot call 'float' with arguments (series[string]); available overloads: float(const float) => const float; float(input float) => input float; float(float) => float; float(series[float]) => series[float];
问题
- 如何在 Pine 中将字符串转换为浮点数
- 我想收集一系列枢轴点。理想情况下,最高分有一个系列,最低分有另一个系列。
任何帮助、提示或建议将不胜感激
TIA
图片 1
图片 2
功能:create_pivot_points
create_pivot_points(src, len, isHigh, _style, _yloc, _color, _textcolor, _offset, _plot_data) =>
[ ... snip ...]
pivot_src_len = len
p = nz(src[pivot_src_len])
isFound = true
for i = 0 to len - 1
if isHigh and src[i] > p
isFound := false
if not isHigh and src[i] < p
isFound := false
for i = len + 1 to 2 * len
if isHigh and src[i] >= p
isFound := false
if not isHigh and src[i] <= p
isFound := false
if isFound
if isHigh // printing the highest high pivots
NOTE: I am using the command below label.XXXX to try to get information about the label
pivotPointHighLabel = label.new(bar_index[pivot_src_len], int(p) + 10 , tostring(truncate(p,2)), style=_style, yloc=_yloc, color=noneColor, textcolor=noneColor)
high_kdcLabel_XCoords := label.get_x( pivotPointHighLabel )
high_kdcLabel_YCoords := label.get_y( pivotPointHighLabel )
high_kdcLabel_Data := float( label.get_text( pivotPointHighLabel ) ) <---- receiving error message here when attempting to change value from a STRING to a FLOAT
high_kdcLabel_Bool := high_kdcLabel_Data == 0.0 ? false : true
if _plot_data //make the labels visible
label.set_color(pivotPointHighLabel, _color)
label.set_textcolor(pivotPointHighLabel, _textcolor)
else // printing the lowest low pivots (assume isLow has been activated)
[ ... snip ...]
// returning information below to calling code
[high_kdcLabel_XCoords, high_kdcLabel_YCoords, high_kdcLabel_Data, high_kdcLabel_Bool, low_kdcLabel_XCoords, low_kdcLabel_YCoords, low_kdcLabel_Data, low_kdcLabel_Bool]
主要代码:
[ ... snip ...]
if plotUpperPivotPoint
[hin_x_coords, hin_y_coords, hin_label_data, hin_bool_data, lin_x_coords, lin_y_coords, lin_label_data, lin_bool_data] =
pivothl(osc, len, true , label.style_labeldown, yloc.price, color.yellow, color.black, 0, plotUpperPivotPoint)
high_x_coords := hin_x_coords
high_y_coords := hin_y_coords
high_label_data := hin_label_data
high_bool_data := hin_bool_data
f_print( tostring(high_label_data) )
// attempting to test any data retrieved to see if it will work with the labels.
// if the list of Upper Limits (Pivots) is correct, the BLUE heart-beat spikes on the picture below
// should match right under the yellow labels
testme = high_label_data == 0 ? 0 : 70
plot( testme, offset=-lbR, color=color.blue )
很难从你的代码片段中弄清楚事情,但是给定一个像 pivothigh()
这样的函数,当找到一个时,returns 是枢轴的值,否则 na
,你可以使用代码像这样:
//@version=4
study("", "", true)
i_legs = input(4)
// When a non `na` value is returned, use zero, otherwise use the value.
pHi = nz(pivothigh(i_legs, i_legs))
plot(pHi)
代码在检测到支点时构建系列,它在实际支点之后 i_legs
,这与大多数支点指标绘制支点的方式相反,即通过抵消过去的 i_legs
条柱: