This ProBuilder script is designed to identify potential trend reversals by analyzing patterns where a bullish bar closes above two preceding bearish bars and vice versa. The code uses loops, conditional statements, and logical operators to determine the trading signals.
DEFPARAM CalculateOnLastBars = 1000
Bullish = close > open
Bearish = close < open
//
// DOWN trend detection
//
Count1 = 0
i = 0
WHILE Count1 < 2 AND i < BarIndex
i = i + 1
IF Count1 = 0 THEN
IF Bullish[i] THEN
Count1 = 1
MyLO1 = low[i]
ENDIF
ELSE
IF Bullish[i] THEN
Count2 = 2
MyLO2 = low[i]
d1 = MyLO1 > MyLO2
MyLO2 = min(MyLO1,MyLO2)
Break
ENDIF
ENDIF
WEND
d2 = Bearish
d3 = close < MyLO2
Dcond = d1 AND d2 AND d3
//
// UP trend detection
//
Count2 = 0
j = 0
WHILE Count2 < 2 AND j < BarIndex
j = j + 1
IF Count2 = 0 THEN
IF Bearish[j] THEN
Count2 = 1
MyHI1 = high[j]
ENDIF
ELSE
IF Bearish[j] THEN
Count2 = 2
MyHI2 = high[j]
u1 = MyHI1 < MyHI2
MyHI2 = max(MyHI1,MyHI2)
Break
ENDIF
ENDIF
WEND
u2 = Bullish
u3 = close > MyHI2
Ucond = u1 AND u2 AND u3
// Cond = 0
IF Ucond THEN
Cond = 1
ELSIF Dcond THEN
Cond = -1
ENDIF
RETURN Cond AS "Signal"
The code snippet above is structured into two main parts: detecting a downward trend reversal and an upward trend reversal. Here’s a breakdown of how each part works:
This approach helps in identifying key reversal points, which are crucial for making informed trading decisions in various market conditions.