2021年2月6日星期六

Tradingview : Pinescript - creating a UNION of 2 Series and isolating the last element of a Series

Looking for an answer to two questions.

QUESTION 1

In the case I am working on, I did the following

  1. plotted the RED labels (used Series : result is OB_pivot_data - see code - with Source = RSI, length = 21 )
  2. plotted the GREEN labels (used Series : result is OS_pivot_data - see code - with Source = RSI, length = 21 )
  3. plotted the GRAY labels (used Series with Source = RSI, length = 5 )

For the GRAY labels, I just want the ~last~ value (in this case, it is 67.06). I need to have the last value in series form (in this case upper_bound_pivot[0] = 67.06) See picture below In the picture BEFORE is what I have now. AFTER is what the target is.

QUESTION 2

Next, I want to combine the resulting series with another (acting like a UNION). With that being said, is there a way to implement something like Series A UNION Series B?

It is listed in the code below using:

// HOWTO : OB_pivot_data UNION testme   

How can one accomplish these two tasks under Pinescript?

Any help, hint or advice would be greatly appreciated.

TIA

Picture enter image description here

FUNCTION PIVOTHL:

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        

MAIN

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 )  
https://stackoverflow.com/questions/66084437/tradingview-pinescript-creating-a-union-of-2-series-and-isolating-the-last-e February 07, 2021 at 12:03PM

没有评论:

发表评论