Tradingview : Pinescript - 创建 2 个系列的 UNION 并隔离系列的最后一个元素
Tradingview : Pinescript - creating a UNION of 2 Series and isolating the last element of a Series
寻找两个问题的答案。
背景:代码我有标签最大(和最小)枢轴点。
我要做的是“pre-identify”一个轴心点。常规枢轴点用 Source = RSI,Limit = 21 标识。正在查看指定 Source = RSI,Limit = 5 到“pre-identify”一个可能的枢轴点(用灰色标签绘制)。
如果有更好的方法,我全ears/eyes
问题 1
在我正在处理的案例中,我做了以下工作
- 绘制红色标签(使用系列:结果为 OB_pivot_data -
查看代码 - 源 = RSI,长度 = 21 )
- 绘制了绿色标签(使用系列:结果为 OS_pivot_data -
查看代码 - 源 = RSI,长度 = 21 )
- 绘制灰色标签(使用系列,源 = RSI,长度 = 5
)
对于 GRAY 标签,我只想要 ~last~ 值(在本例中为 67.06)。我need to have the last value in series
形式(本例upper_bound_pivot[0]=67.06)见下图图中BEFORE是我现在有什么。 AFTER 是目标。
问题 2
接下来,我想将生成的系列与另一个系列组合(充当 UNION)。话虽这么说,有没有办法实现类似 Series A UNION Series B
?
在下面的代码中列出使用:
// HOWTO : OB_pivot_data UNION testme
如何在 Pinescript 下完成这两项任务?
如有任何帮助、提示或建议,我们将不胜感激。
TIA
图片
函数轴:
pivothl(src, len, isHigh, _style, _yloc, _color, _offset, _displayResults ) =>
p = nz(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 _displayResults and isFound
label.new(bar_index[len], p , tostring( truncate(p, 2) ), style=_style, yloc=_yloc, color=_color, textcolor=color.white)
return_data = isFound == false ? na : p
功能PIVOTHL_FIRST_ONLY
pivothl_first_only(src, len, isHigh, _style, _yloc, _color, _offset, _displayResults ) =>
start_src = src
upper_bound_pivot = pivothl(start_src, len, true, _style, _yloc, _color, _offset, true )
return_data = upper_bound_pivot == false ? na : upper_bound_pivot
return_data
主要
pivot_OB_LB = input(title="Pivot Over Bought Lookback :", type=input.integer, defval=21 )
pivot_OS_LB = input(title="Pivot Over Sold Lookback :", type=input.integer, defval=21 )
pivot_OB_LB_peek = input(title="Peek Pivot Over Bought Lookback :", type=input.integer, defval=5)
lenH = pivot_OB_LB
lenL = pivot_OS_LB
OB_pivot_data = pivothl(rsi, lenH, true , label.style_labeldown, yloc.price, color.red,0, true)
OS_pivot_data = pivothl(rsi, lenL, false, label.style_labelup , yloc.price, color.green,0, true )
dbug_OB_pivot_data = OB_pivot_data >= 0 ? OB_pivot_data : 0
dbug_OS_pivot_data = OS_pivot_data >= 0 ? OS_pivot_data : 100 // just arbitrary number chosen (100)
[ ... snip ... ]
// get last value only place into series
testme = pivothl_first_only(rsi, pivot_OB_LB_peek, true , label.style_labeldown, yloc.price, color.silver,0, false)
pl_testme = testme > 0 ? testme : 0
plot( pl_testme, offset = -pivot_OB_LB_peek, color=color.purple )
更新:这是我发现对我有用的(似乎正在工作......):
pivothl_combine_upper_and_lower (src, len, oBought, oSold ) =>
combined = 0.0
if print_OBought != 0
p = src[len]
combined := p
else
if print_OSold != 0
p = src[len]
combined := p
combined
寻找两个问题的答案。
背景:代码我有标签最大(和最小)枢轴点。
我要做的是“pre-identify”一个轴心点。常规枢轴点用 Source = RSI,Limit = 21 标识。正在查看指定 Source = RSI,Limit = 5 到“pre-identify”一个可能的枢轴点(用灰色标签绘制)。
如果有更好的方法,我全ears/eyes
问题 1
在我正在处理的案例中,我做了以下工作
- 绘制红色标签(使用系列:结果为 OB_pivot_data - 查看代码 - 源 = RSI,长度 = 21 )
- 绘制了绿色标签(使用系列:结果为 OS_pivot_data - 查看代码 - 源 = RSI,长度 = 21 )
- 绘制灰色标签(使用系列,源 = RSI,长度 = 5 )
对于 GRAY 标签,我只想要 ~last~ 值(在本例中为 67.06)。我need to have the last value in series
形式(本例upper_bound_pivot[0]=67.06)见下图图中BEFORE是我现在有什么。 AFTER 是目标。
问题 2
接下来,我想将生成的系列与另一个系列组合(充当 UNION)。话虽这么说,有没有办法实现类似 Series A UNION Series B
?
在下面的代码中列出使用:
// HOWTO : OB_pivot_data UNION testme
如何在 Pinescript 下完成这两项任务?
如有任何帮助、提示或建议,我们将不胜感激。
TIA
图片
函数轴:
pivothl(src, len, isHigh, _style, _yloc, _color, _offset, _displayResults ) =>
p = nz(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 _displayResults and isFound
label.new(bar_index[len], p , tostring( truncate(p, 2) ), style=_style, yloc=_yloc, color=_color, textcolor=color.white)
return_data = isFound == false ? na : p
功能PIVOTHL_FIRST_ONLY
pivothl_first_only(src, len, isHigh, _style, _yloc, _color, _offset, _displayResults ) =>
start_src = src
upper_bound_pivot = pivothl(start_src, len, true, _style, _yloc, _color, _offset, true )
return_data = upper_bound_pivot == false ? na : upper_bound_pivot
return_data
主要
pivot_OB_LB = input(title="Pivot Over Bought Lookback :", type=input.integer, defval=21 )
pivot_OS_LB = input(title="Pivot Over Sold Lookback :", type=input.integer, defval=21 )
pivot_OB_LB_peek = input(title="Peek Pivot Over Bought Lookback :", type=input.integer, defval=5)
lenH = pivot_OB_LB
lenL = pivot_OS_LB
OB_pivot_data = pivothl(rsi, lenH, true , label.style_labeldown, yloc.price, color.red,0, true)
OS_pivot_data = pivothl(rsi, lenL, false, label.style_labelup , yloc.price, color.green,0, true )
dbug_OB_pivot_data = OB_pivot_data >= 0 ? OB_pivot_data : 0
dbug_OS_pivot_data = OS_pivot_data >= 0 ? OS_pivot_data : 100 // just arbitrary number chosen (100)
[ ... snip ... ]
// get last value only place into series
testme = pivothl_first_only(rsi, pivot_OB_LB_peek, true , label.style_labeldown, yloc.price, color.silver,0, false)
pl_testme = testme > 0 ? testme : 0
plot( pl_testme, offset = -pivot_OB_LB_peek, color=color.purple )
更新:这是我发现对我有用的(似乎正在工作......):
pivothl_combine_upper_and_lower (src, len, oBought, oSold ) =>
combined = 0.0
if print_OBought != 0
p = src[len]
combined := p
else
if print_OSold != 0
p = src[len]
combined := p
combined