简体   繁体   中英

Add mid point to pivot high low indicator

Hi Stack overflow community.

I'm not a great coder yet and should probably be doing more tutorials but I have found I learn more by just solving problem I have. Currently having and issue which I'm sure is very basic for many of you but I have tried a range of things and just cant get it right.

Currently have the below code, its just the basic pivot point high low indicator. I'm trying the mark the mid point between the current high and current low and plot it on the chart. I feel so dumb asking this question but I'm just out of ideas.

Any help with this is very much appreciated, Thanks.

https://www.tradingview.com/x/oqrq4nDj/

study("Pivot Points High Low", shorttitle="Pivots HL", overlay=true)
lenH = input(title="Length High", type=input.integer, defval=10, minval=1)
lenL = input(title="Length Low", type=input.integer, defval=10, minval=1)
fun(src, len, isHigh, _style, _yloc, _color) =>
    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 isFound
        label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color)
fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.lime)
fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.red) ```
//@version=4
study("Help (Pivot Points High Low) v3", shorttitle="Pivots HL", overlay=true)
lenH = input(title="Length High", type=input.integer, defval=10, minval=1)
lenL = input(title="Length Low", type=input.integer, defval=10, minval=1)

lastHP = 0.0
lastLP = 0.0
var ln = line.new(na, na, na, na, extend=extend.left)

fun(src, len, isHigh, _style, _yloc, _color) =>
    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 isFound
        label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color)
        p
    else
        float(na)


lastHP := fixnan(fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.lime))
lastLP := fixnan(fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.red))

//plot((lastHP + lastLP)/2, offset=-lenH)

line.set_xy1(ln, bar_index[1], (lastHP + lastLP)/2)
line.set_xy2(ln, bar_index[0], (lastHP + lastLP)/2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM