The screener returns either a positive (for Bullish Pinbar) or negative (for Bearish Pinbar) value.
The value returned is based upon the number of bounces from the Lowest Close (for Bullish Pinbar) or the number of bounces from the Highest Close (for Bearish Pinbar).
The whole algorithm is based upon a look back period of 30.
There is also a parameter called t which says how far back to look for the pinbar (Default Value = 0 meaning only results where a pinar just formed is displayed).
Also, to increase the probability of success only bullish pinbars above the 200MA and bearish pinbars below the 200MA will be returned.
//Defparam cumulateorders = False
once t = 0
LBP = 30 //Look Back Period
PSH = Highest[LBP](close)[2+t] //Previous Swing High
PSL = Lowest[LBP](close)[2+t] //Previous Swing Low
LMA = Average[200](close)[t] //Long Moving Avearge (Primary Trend)
STC = Stochastic[14,3](close)[t]
RS2 = RSI[2](close)[t]
//PB = PinBar
BullishPB = close[2+t] < open[2+t] and low[t] > low[1+t] and high[t] > high[1+t] and close[t] > close[1+t]//and close > open[2]
BearishPB = close[2+t] > open[2+t] and low[t] < low[1+t] and high[t] < high[1+t] and close[t] < close[1+t]//and close < open[2]
//PBHeight = High[1+t] - Low[1+t]
PBBody = abs(close[1+t]-open[1+t])
If close[1+t] > open[1+t] Then
PBTShadow = (high[1+t] - close[1+t])
PBBShadow = (open[1+t] - low[1+t])
ElsIf close[1+t] < open[1+t] Then
PBTShadow = (high[1+t] - open[1+t])
PBBShadow = (close[1+t] - low[1+t])
EndIF
PBRatio = 3
If BullishPB and PBBShadow > (PBTShadow*PBRatio) and PBBShadow > (PBBody*PBRatio) and low[1+t] < PSL and close[t] > PSL Then //and PBBody < (PBHeight/PBRatio)
BullishPB = 1
BearishPB = 0
ElsIf BearishPB and PBTShadow > (PBBShadow*PBRatio) and PBTShadow > (PBBody*PBRatio) and high[1+t] > PSH and close[t] < PSH Then //and PBBody < (PBHeight/PBRatio)
BearishPB = 1
BullishPB = 0
Else
BearishPB = 0
BullishPB = 0
EndIf
SupportB = 0
ResistanceB = 0
For i = (1+t) to (LBP+t) Do
If low[i] < PSL Then
SupportB = SupportB + 1
ElsIf high[i] > PSH Then
ResistanceB = ResistanceB + 1
EndIf
Next
BullPinbar = (BullishPB = 1 and close[t] > LMA and STC < 30 and RS2 > 50)
BearPinbar = (BearishPB = 1 and close[t] < LMA and STC > 70 and RS2 < 50)
If BullPinbar Then
Pinbar = SupportB*1 //Number of Bounces from Support
ElsIf BearPinbar Then
Pinbar = ResistanceB*-1 //Number of Bounces from Resistance x -1 to denote Bearish Pinbar
EndIf
Condition = (BullPinbar Or BearPinbar)
SCREENER[Condition] (Pinbar AS "Pinbar")