pine-scriptpine-script-v5pine-script-v4

Pine Script: I want to plot bomax value on data window


Iam very new to pinescript, in the given code i want to plot bomax level on data window, so i can see the data there in trading view, here's my code:

//@version=5
indicator('Breakout Finder', 'BF', overlay=true, max_bars_back=500, max_lines_count=400)
prd = input.int(defval=5, title='Period', minval=2)
bo_len = input.int(defval=200, title='Max Breakout Length', minval=30, maxval=300)
cwidthu = input.float(defval=3., title='Threshold Rate %', minval=1., maxval=10) / 100
mintest = input.int(defval=2, title='Minimum Number of Tests', minval=1)
bocolorup = input.color(defval=color.blue, title='Breakout Colors', inline='bocol')
bocolordown = input.color(defval=color.red, title='', inline='bocol')
lstyle = input.string(defval=line.style_solid, title='Line Style', options=[line.style_solid, line.style_dashed, line.style_dotted])

// width
lll = math.max(math.min(bar_index, 300), 1)
float h_ = ta.highest(lll)
float l_ = ta.lowest(lll)
float chwidth = (h_ - l_) * cwidthu

// check if PH/PL
ph = ta.pivothigh(prd, prd)
pl = ta.pivotlow(prd, prd)

// keep Pivot Points and their locations in the arrays
var phval = array.new_float(0)
var phloc = array.new_int(0)
var plval = array.new_float(0)
var plloc = array.new_int(0)

// keep PH/PL levels and locations
if ph
    array.unshift(phval, ph)
    array.unshift(phloc, bar_index - prd)
    if array.size(phval) > 1  // cleanup old ones
        for x = array.size(phloc) - 1 to 1 by 1
            if bar_index - array.get(phloc, x) > bo_len
                array.pop(phloc)
                array.pop(phval)

if pl
    array.unshift(plval, pl)
    array.unshift(plloc, bar_index - prd)
    if array.size(plval) > 1  // cleanup old ones
        for x = array.size(plloc) - 1 to 1 by 1
            if bar_index - array.get(plloc, x) > bo_len
                array.pop(plloc)
                array.pop(plval)

// check bullish cup
float bomax = na
int bostart = bar_index
num = 0
hgst = ta.highest(prd)[1]
if array.size(phval) >= mintest and close > open and close > hgst
    bomax := array.get(phval, 0)
    xx = 0
    for x = 0 to array.size(phval) - 1 by 1
        if array.get(phval, x) >= close
            break
        xx := x
        bomax := math.max(bomax, array.get(phval, x))
        bomax
    if xx >= mintest and open <= bomax
        for x = 0 to xx by 1
            if array.get(phval, x) <= bomax and array.get(phval, x) >= bomax - chwidth
                num += 1
                bostart := array.get(phloc, x)
                bostart
        if num < mintest or hgst >= bomax
            bomax := na
            bomax

if not na(bomax) and num >= mintest
    line.new(x1=bar_index, y1=bomax, x2=bostart, y2=bomax, color=bocolorup, style=lstyle)

// Plot bomax for visibility in Data Window
plot(not na(bomax) and num >= mintest ? bomax : na, color=color.green, linewidth=2, title="Bomax Line", display=display.data_window)

// Plot bostart for visibility in Data Window
plot(bostart, color=color.blue, linewidth=2, title="Bostart Line", display=display.data_window)

my client is so angry on me, please help this newbie. i tried evrything possible, but on data window it was displaying ∅ this symbol, which was null value. on chart, it perfectly drawn the line but here n display window, it was showing null value


Solution

  • bomax might be changing its value several times in the for loop. If the loop designed to prevent this, you can just have a var variable to store its last value.

    // check bullish cup
    var float bomax_last = na
    float bomax = na
    int bostart = bar_index
    num = 0
    hgst = ta.highest(prd)[1]
    if array.size(phval) >= mintest and close > open and close > hgst
        bomax := array.get(phval, 0)
        bomax_last := bomax
        xx = 0
        for x = 0 to array.size(phval) - 1 by 1
            if array.get(phval, x) >= close
                break
            xx := x
            bomax := math.max(bomax, array.get(phval, x))
            bomax_last := bomax
            bomax
        if xx >= mintest and open <= bomax
            for x = 0 to xx by 1
                if array.get(phval, x) <= bomax and array.get(phval, x) >= bomax - chwidth
                    num += 1
                    bostart := array.get(phloc, x)
                    bostart
            if num < mintest or hgst >= bomax
                bomax := na
                bomax
    
    if not na(bomax) and num >= mintest
        line.new(x1=bar_index, y1=bomax, x2=bostart, y2=bomax, color=bocolorup, style=lstyle)
    
    plotchar(bomax_last, "bomax_last", "")