Page 1 of 1

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

Posted: Mon Mar 21, 2022 11:07 pm
by clockwor
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!

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

Posted: Fri Mar 25, 2022 9:32 pm
by processingclouds
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.