Custom Candlestick

Iam a novice. I require a simple snippet to define candlesticks based on which part of the whole range they close at. For example, a hammer is a candlestick in which price trades to low and closes in the upper part. Now, i want the definition to be flexible as in which part of the candle it closes namely upper 10%, upper 20% of the range of the candle. (Updating the question with the answer i got elsewhere)

Answer - 


n     = Param("Wick_Body_Ratio",3,1,5,0.1);

Body = abs(O - C);
Wick = IIf(O > C, H - O, H - C);
Tail  = IIf(O > C, C - L, O - L);
PB  = (Wick >= n * Body) OR (Tail >= n * Body);
IB  = H < ref(H,-1) AND L > ref(L,-1);

Hi Manjunath,
Could u explain Ur Q in detail?..U want to add Specific color to the candle if it closes upper or Bottom…?