clockwor
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: March 21st, 2022

Find opening price of last green (close above the open) candle or last red candle (close below the open) from current

Hello

I am looking for Pinescript code to find the last (most recent) green ( close above open) or red (close below open) candle from the current candle. I want to return the opening price in either scenario.
Thank you for any help!

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Find opening price of last green (close above the open) candle or last red candle (close below the open) from curren

Hey,

You can use the function, 'valuewhen' to achieve this.

Something like:

Code: Select all

ta.valuewhen(close>open, open, 1)  
This will return the open price when it was last green.

Return to “Pine Script Q&A”