Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compare three bar and plot a shape (by using plotshape) above or below the middle Candle

I am just starting out learning PineScript and sorry if this question is very elementary.
I want to compare three bars. If the middle bar’s high is greater than two others, then plot a shape above it by ‘plotshape’ command. The problem is that in the code below if the condition is true then a shape is plotted on the first bar. How can I change this code?

//@version=5
indicator("My script" , overlay = true)
swing_highs=(high[1]>high[0] and high[1]>high[2]) 
plotshape(swing_highs)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can add not barstate.islast into your plot statement to avoid plotting on the last bar of the chart. Using the offset will also place the shape above the peak bar.

plotshape(not barstate.islast and swing_highs, offset = -1)

Before:

Before

After:
After

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading