Great work juanj re the Screener, I have a question and I have made an attachment to make it easier for you to answer so I started this Thread based on your Library post here
https://www.prorealcode.com/prorealtime-market-screeners/advanced-bullishbearish-pinbar-screener/
How are bounces counted please? The image attached shows a pinbar result value = -4. I’ve numbered 7 bars for you to refer to. Are bounces counted if they are within a certain % of highest or how do you count 4 bounces from attached?
Everything is as your original code. Lookback is 30, but bars bars 1, 2, 3 and 4 (which are are bouncing / rejecting a level) would be within a Lookback of 7 so I am confused.
I can’t see exactly how the code arrives at a count of 4 in the code. If anyone else can see it then let me know please?
Thank You
GraHal
I’m prob gonna answer my own question again (best way to learn! 🙂 )
Pinbar that has been detected is Bar 6 (bar 7 hasn’t closed yet and isn’t a pinbar anyway) but current mid-price is 9446 and there are 4 other pinbars (bars 1, 2, 3, and 4) showing a high within ‘1’ of 9446 … so is that how Juanj code gives a count of – 4??
GraHal
juanj (as code author on the link in OP) or anybody (who can read other’s complex code!?) … are my assumptions correct?
Or how are bounces counted please?
Thank You
GraHal
The best way to understand how the code works is to make it as an indicator, to better visualize when a new pinbar occurs and how it makes the bounces count:
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)
return condition style(histogram) as "new pinbar", pinbar as "bounces"
New pinbar condition is histogram, bounces count is a line.
I don’t know if it works correctly though…
I did a reply to this at about 12:20 pm today, I pressed submit and then all I saw was ‘no reply submitted’ and I was logged out. Strange??
Happened to me once before over 12 months ago, not ever since. Thought I’d say anyway for the record.
Same ever happen to anybody reading this??
This a shortened version of the reply I lost (maybe shorter is better! 😉 ) … I don’t think the Indicator is working Nicolas?
The line shows -4 (see attached) so 4 bounces supposedly (?) but I can see only 1 bounce within the lookback period of 30 … the pinbar before the ‘histo pinbar’?
GraHal
Sorry GraHal, I made so many little modifications on the website actually, that sometimes I need to reboot/purge/delete/replace files, etc.. and I can’t do it at night while people are sleeping ’cause I’m sleeping too 🙂
Well, this screener’s code is not mine and I’m hardly understand how
@juanj has made it. I know he’s on vacation and he’ll be back in January. In the meantime I may have a look between other things like eating roasted turkeys and opening my christmas gifts (if I got some … not sure I been kind enough this year ..).
HAHAHAHA Thank you Nicolas … You’ve been kind enough to all of us anyway … so I hope you get many presents to open!!
Thank you for letting me know Juanj is on hols, cos sometimes I get involved where I see that a member of the Community has put in a lot of effort re coding us a great Screener or Strategy etc and no-one seems to be using the code / even care / say thank you etc. In this instance (as I started a Forum Thread for Juanj Screener) I was thinking … why won’t you answer Juanj … now I know why – he’s on hols! 🙂
Also you have answered me a question (that was in my ‘lost comment’ earlier) … often I think, why am I struggling to decipher how this code works, a skilled coder on here could tell me in 2 or 3 mins! But seems it’s not even easy when you are as good as you are! I know you could of course, but even for you it can take time so I might struggle a bit more now!
All the Best for Christmas
GraHal
a skilled coder on here could tell me in 2 or 3 mins! But seems it’s not even easy when you are as good as you are!
Sometimes I got problems to understand things I’ve coded myself many months before!
About the pinbar pattern bounces on support/resistance, the easier way for me would be to recode the whole concept my own style, but I don’t want to throw away the work
@juanj has made with his own view.
Sure let’s leave it until Junaj gets back off hols … maybe he’s skiiing or soaking up the sun on Bora Bora … all paid for with winnings from his Screener! 🙂
I’m running the Screener and it sure does look like I said in
#55811 Screener detects a pinbar and if the price level + or – ‘1’ (of high or low bull / bear pin) has been hit by a previous pinbar then the Screener counts 1, 2, 3 0r -1, -2, -3 etc. Seems it doesn’t have to be hitting the same price level to add to the count, just so long as it is within ‘1’ of the previous pinbar / bounce … very clever!?
So a higher count could mean a higher confidence of a reversal!? However, if the price level at which the bounce occurs is progressively
increasing (for a bearish reversal
) then it may just shoot through (the price zone) after all and become a bullish breakout!? Always wait for the next bar for confirmation of direction.
Thought I’d say above to save skilled coders spending too much time working out Juanj original code.
Best to All
GraHal
Ha I dont think the criteria is
‘1’ from previous (as I suggest above) but look at attached … the count is -6 and hey presto 6 rejections of a price zone … I’m impressed.
Spread is 20 points so I won’t be shorting! 🙂
GraHal