Need help in coding

 
hello guy!

Anyone can help me about coding. What I'm trying to accomplish here? A bar setup on a down trend. I am looking for code for three consecutive bars making lower/high and lower/lows, if the third bar high is reach" set buy top" Thanks for your help.
Reason: