Mathematical Calculation To Find Pinbars?

Hello Guys,

got stuck with this problem
i want to find and mark pinbars either hammer or shooting stars
i find few indicators do this but they dont even mark same bars!
and they wrote it on way to complex way for me to understand :15: :46:

i appreciate it if anyone help me out and write mathematical method to find them without making in it too complicate to understand

thank you in advance :slight_smile:

β€œThe Pin bar pattern is characterized by a long upper or lower wick with a small body relative to the size of the wick with little to no lower or upper shadows.”

I think it is quite easy to calculate if you define the parameter what the body size is compared to the wick.
diffH = PRICE_HIGH - max(PRICE_OPEN,PRICE_CLOSE)
diffL = min(PRICE_OPEN,PRICE_CLOSE) - PRICE_LOW

if((diffH/abs(PRICE_OPEN-PRICE_CLOSE) > p || diffL/abs(PRICE_OPEN-PRICE_CLOSE) > p)
barIsPinBar=True

where p is the fraction of differences between the two lengths that define a pinbar, so for example p=3 means that the wick is 3 times the length of the body.
You can also stick in the definition that the second wick is smaller than the body to get closer to the original definition.

Thank you for code and explaining :slight_smile: