REJHAM
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Kliphten

//@version=4
study(title="REJHAM", overlay=true)

range = high - low
candlecheck = (close > open) ? 1 : 0
UpWick = candlecheck == 1 ? (high - close) : (high - open)
DownWick = candlecheck == 0 ? (close - low) : (open - low)
isCandleOpenCloseEqual = (open == close) ? 1 : 0
tbl = table.new(position.top_right, 2, 4)
table.cell(tbl, 0, 0, "C.Key",  bgcolor = #aaaaaa, width = 7, height = 6)
table.cell(tbl, 1, 0, "C.Value", bgcolor = #aaaaaa, width = 7, height = 6)

table.cell(tbl, 0, 1, "Time Period",  bgcolor = color.green, width = 7, height = 6)
table.cell(tbl, 1, 1, timeframe.period + " Mins", bgcolor = color.red,   width = 7, height = 6)

table.cell(tbl, 0, 2, "Up Wick",  bgcolor = color.green, width = 7, height = 6)
table.cell(tbl, 1, 2, tostring(UpWick), bgcolor = color.red,   width = 7, height = 6)
     
table.cell(tbl, 0, 3, "Down Wick",  bgcolor = color.green, width = 7, height = 6)
table.cell(tbl, 1, 3, tostring(DownWick), bgcolor = color.red,   width = 7, height = 6)


isRejectionExists = (UpWick > 0.001 and DownWick > 0.001) ? 1 : 0

timeperiod = timeframe.period 
isBuyHammerexists = (isRejectionExists == 1 and candlecheck == 1)  ? (DownWick > 2.1 * UpWick) ? (isCandleOpenCloseEqual == 1) ? 0 : 1 : 0 : 0
isSellHammerExists = (isRejectionExists == 1 and candlecheck == 0) ?  (UpWick > 2.1 * DownWick) ? (isCandleOpenCloseEqual == 1) ? 0 : 1 : 0 : 0
//isAnyHammerexists = (isBuyHammerexists == 1 and timeperiod >= 15) ? 1 :  (isSellHammerExists == 1 and timeperiod >= 15) ? 1 : 0
plotshape(isBuyHammerexists,location=location.belowbar,color= color.green , style=shape.triangleup)
plotshape(isSellHammerExists,location=location.abovebar,color= color.red , style=shape.triangledown)
//plotshape(isAnyHammerexists,location=location.belowbar,color= color.orange , style=shape.triangleup)