【问题标题】:Tradingview : Pinescript - creating a UNION of 2 Series and isolating the last element of a SeriesTradingview : Pinescript - 创建 2 系列的 UNION 并隔离系列的最后一个元素
【发布时间】:2021-02-07 04:03:03
【问题描述】:

寻找两个问题的答案。

背景:我有标签的代码最大(和最小)枢轴点。

我要做的是“预先确定”一个枢轴点。常规枢轴点用 Source = RSI, Limit = 21 标识。正在考虑指定 Source = RSI, Limit = 5 以“预识别”可能的枢轴点(用灰色标签绘制)。

如果有更好的方法来做到这一点,我全神贯注

问题 1

在我正在处理的情况下,我做了以下操作

  1. 绘制红色标签(使用系列:结果是 OB_pivot_data - 见代码 - Source = RSI, length = 21)
  2. 绘制绿色标签(使用系列:结果是 OS_pivot_data - 见代码 - Source = RSI, length = 21)
  3. 绘制灰色标签(使用系列,源 = RSI,长度 = 5 )

对于灰色标签,我只想要 ~last~ 值(在本例中,它是 67.06)。我need to have the last value in series 形成(在本例中为upper_bound_pivot[0] = 67.06)见下图图片中之前是我现在所拥有的。 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

FUNCTION 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 )

【问题讨论】:

  • 如果您提供学习的工作场景,我会尽力帮助您。

标签: pine-script


【解决方案1】:

更新:这就是我发现对我有用的东西(似乎正在工作......):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 2013-01-19
    • 1970-01-01
    • 2019-10-10
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    相关资源
    最近更新 更多