i use this script to find highs and lows: https://www.tradingview.com/script/eH0vkSBy-Swing-Highs-and-Lows/. I want to plot a line between two last points(2 swing highs or 2 swing lows) so that in the future, if price close above/under line i get an entry signal. One more nuance - i use renko bars. How i can do this? Something like that:
strategy(title='My first strategy')
//code provided in the link
prhigh=valuewhen(isSwingHigh,high,0)
l = line.new(barindex, prhigh, barindex[1], prhigh[1], width = 4)// I don't know how to get barindex
alertcondition(crossover(l,close), 'Swing High', 'New SwingHigh')
There are numerous scripts that aim to draw lines from swing high's swing low's.
However remember that you can't create alerts involving a series interacting with a line object, as this one don't have numerical values.
One option to get a line connecting two values without using line.new
is to use plot(isSwingHigh ? close : na)
, when you plot a series containing na values plot
will connect the two last non na values with a line.