0

Chart of what I am trying to achieve

Hi!

I've tried to define a swing top as an upbar followed by a downbar. And the swing top being the high of the first bar, the upbar that is.

The ST in green is where my indicator paints the Swing Top

upbar = high>high[1] and low>low[1] downbar = low<low[1]

//Up Bar Down Bar barcolor(showdubar and upbar[1] and downbar? color.gray: na, title='Swing top') plotchar(upbar[1] and downbar, title = 'swing top', location=location.belowbar, color=color.new(color.lime, 50), size=size.tiny, text='ST')

I'm happy with the results but I need it to move one bar to the left. Also how to define that it is the high of that bar that is the swing top?

Johan
  • 3
  • 2

1 Answers1

0

Moving one bar to the left is done using plotchar( ..., offset = -1) parameter. Also, changing location to location=location.abovebar will mark the high of the bar.

Please see the script below.

//@version=5
indicator("My script", overlay = true, max_boxes_count = 500)

upbar = high>high[1] and low>low[1] 
downbar = low<low[1]

//Up Bar Down Bar 
barcolor(upbar[1] and downbar? color.gray: na, title='Swing top') 
plotchar(upbar[1] and downbar, title = 'swing top', location=location.abovebar, color=color.new(color.lime, 50), size=size.tiny, text='ST', offset = -1)
Moebius
  • 329
  • 1
  • 7
  • Thank you Moebius, it worked great. Now is it possible to create a strategy.entry long.condition where a buy order is created when price=> high of ST candle? – Johan Mar 25 '23 at 14:23