Trend identification code for inside candle with rsi

I am a Newbie ..Could you please share the code for the following logic ..

I have three candles candles say candle1 , candle2 and candle3 ...My aim is find our INSIDE CANDLE OUT candle with following characteristics for my selected scripts 

For Eg : Candle1 at 10.15AM price range is high-low is 10-2 . Candle2 at 11.15AM price range is 7-5 . Rsi should be less than 20 and greater than 0 and stoc should be in oversold region . CCI should be less than 0 . Currently i am in Candle3 at 12.15PM which is processing and it should NOT consider this candle for the above processing

Please share GENERIC CODE SNIPPETS and NOT with any above hard coded values . 

For the above given condition

 RSI(CLOSE,14)<20 AND RSI(CLOSE,14)>0 AND (SOPK(9, 3, 9, SIMPLE) > 80 
OR SOPD(9, 3, 9, SIMPLE) > 80) AND CCI(12, SIMPLE) < 0