'Add plot when croos

I want to add a circles when 2 lines cross.

study(title="Williams %R", shorttitle="The Willy")

// Williams %R
length = input(defval=21, minval=1)
upper = highest(length)
lower = lowest(length)

output = 100 * (close - upper) / (upper - lower)
ema = ema(output, input(defval=13, title="EMA"))

// Plot   
h1 = hline(-20, title="Upper Band")
h2 = hline(-80, title="Lower Band")
fill(h1, h2, title="Background")

plot(output, title="%R", color=yellow, linewidth=2)
plot(ema, title="EMA", color=aqua, linewidth=2)
plot(ta.cross(output, ema) ? signal : na, color= #00ff0a, style = plot.style_circles, linewidth = 2)

I have try this last line but don't work.

Thanks by advance for your help.



Solution 1:[1]

Your code is a mixture of v3, v4 and v5. You should fix that first.

After that, you are looking for ta.cross() to see if there is a cross and plotshape() function to display the circles.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius

//@version=5
indicator(title="Williams %R", shorttitle="The Willy")

// Williams %R
length = input.int(defval=21, minval=1)
ema_len = input(defval=13, title="EMA")
upper = ta.highest(length)
lower = ta.lowest(length)

output = 100 * (close - upper) / (upper - lower)
_ema = ta.ema(output, ema_len)
is_cross = ta.cross(output, _ema)

// Plot   
h1 = hline(-20, title="Upper Band")
h2 = hline(-80, title="Lower Band")

plot(output, title="%R", color=color.yellow, linewidth=2)
plot(_ema, title="EMA", color=color.aqua, linewidth=2)
plotshape(is_cross ? _ema : na, "Cross", shape.circle, location.absolute, color=#00ff0a)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vitruvius