I trade on the 5 min chart, one of my entry triggers is a pin bar. So to speed up my entry process i started looking at pin bar indicators to give me a quick visual confirmation whether a candle is a pinbar or not.
Now here comes my problem, my rules are a bit more strict as to what a valid pin bar actually is. In my rules a bullish pin bar is only valid when it prints on a bullish candle it is never valid when it prints on a bearish candle and vice versa.
//@version=2
study("PIN BAR INDICATOR",overlay=true)
//PIN BAR
body = abs(close-open)
upshadow = open>close?(high-open):(high-close)
downshadow = open>close?(close-low):(open-low)
pinbar_h = close[1]>open[1]?(body[1]>body?(upshadow>0.5*body?(upshadow>2*downshadow?1:0):0):0):0
pinbar_l = open[1]>close[1]?(body[1]>body?(downshadow>0.5*body?(downshadow>2*upshadow?1:0):0):0):0
plotshape(pinbar_h,style=shape.triangledown,color=red)
plotshape(pinbar_l,style=shape.triangleup,color=lime,location=location.belowbar)
plotchar(pinbar_h,text="BEARISH PINBAR",char="",color=red)
plotchar(pinbar_l,text="BULLISH PINBAR",char="",color=lime,location=location.belowbar)
This is the code for a standard pin bar indicator which I'm trying to adapt. As shown in the attached image the encircled pin bars are the ones I'd like to filter out.
I have zero experience with programming so instead I went to look for an indicator that fits with my rules, I've gone through quite a few of the community made pin bar indicators on TV but I haven't found any that work the way I want them to. I've also asked my brother who has some experience with programming in Python but still no success yet.
I don't know if it would be better to adapt an existing code or create a new one altogether, from my inexperienced point of view it seems adapting an existing one would be easier.
In PineScript you can detect the candle (bearish or bullish) based on the open & close price.
So if the close is higher than the open price then it's a bullish candle and if the close is lower than open it's a bearish candle.
Find below the indicator in version of 5: