ProRealCode - Trading & Coding with ProRealTime™
Hello,
This simple code (if it can be simplified) can be used for identifying earliest reversals. The approach is to identify Bullish Bar Closing above 2 Bearish Bar and vice versa as shown in the document. The issue is if we use “if” statement then the program is becoming very big. Any simplification will be highly appreciated.
Regards.
c=close
o=open
l=low
hi=high
c1=c[1]
c2=c[2]
c3=c[3]
c4=c[4]
c5=c[5]
c6=c[6]
c7=c[7]
c8=c[8]
C9=C[9]
c10=c[10]
C12=C[12]
o1=o[1]
o2=o[2]
o3=o[3]
o4=o[4]
o5=o[5]
o6=o[6]
o7=o[7]
o8=o[8]
O9=O[9]
o10=o[10]
O12=O[12]
l1=l[1]
l2=l[2]
l3=l[3]
l4=l[4]
l5=l[5]
l6=l[6]
l7=l[7]
l8=l[8]
L9=L[9]
h1=hi[1]
h2=hi[2]
h3=hi[3]
h4=hi[4]
h5=hi[5]
h6=hi[6]
h7=hi[7]
h8=hi[8]
H9=HI[9]
h10=hi[10]
H12=HI[12]
if c>=o and c1<o1 and c2<o2 AND H1<H2 and c>h2 then
t=10
ELSif c>=o and c1<o1 and c2>=o2 AND C3<O3 AND H1<H3 and c>h3 then
t=10
elsif c>=o and c1<o1 and c2<o2 and c3<o3 and h1<h3 and h2<h3 and c>h3 then
t=10
elsif c>=o and c1>=o1 and c2<o2 and c3<o3 and h2<h3 and c1<h3 and c>h3 then
t=10
elsif c>=o and c1<o1 and c2<o2 and c3<o3 and h1>h2 and h2<h3 and c>h3 then
t=10
ELSif c>=o and c1>=o1 and c2<o2 AND C3<O3 and c4<o4 AND H3<H4 and h2<=h4 and c1<=h4 and c>h4 then
t=10
ELSif c>=o and c1<o1 and c2>=o2 AND C3<O3 and c4<o4 AND H3<H4 and c2<=h4 and c>h4 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4<o4 and h3<h4 and c1<h4 and c>h4 then
t=10
elsif c>=o and c1>=o1 and c2<o2 and c3>=o3 and c4<o4 and h2<h4 and c1<h4 and c>h4 then
t=10
elsif c>=o and c1>=o1 and c2<o2 and c3<o3 and c4<o4 and h3<h4 and c1<h4 and c>h4 then
t=10
elsif c>=o and c1>=o1 and c2<o2 and c3<o3 and c4<o4 and h2>h3 and l2<l3 and h3<h4 and c1<h4 and c>h4 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4>=o4 and c5<o5 and h3<h5 and c1<h5 and c>h5 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4<o4 and c5<o5 and h4<h5 and c3<h5 and c2<h5 and c1<h5 and c>h5 then
t=10
elsif c>=o and c1<o1 and c2>=o2 and c3>=o3 and c4<o4 and c5<o5 and h4<h5 and c3<h5 and c2<h5 and c>h5 then
t=10
elsif h4<h5 and c5<o5 and c4<o4 AND c3<=h5 and c2<=h5 and c1<=h5 and c>h5 AND C>=O then
t=10
elsif c>=o and c1<o1 and c2<o2 and c3>=o3 and c4>=o4 and c5<o5 and c6<o6 and H5<h6 and c3<h6 AND C4<H6 and c>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4<o4 and c5>=o5 and c6>=o6 AND C7<O7 and H4<h7 and c3<=h7 AND C2<=H7 and c1<=H7 AND C>h7 then
t=10
elsif c>=o and c1>=o1 and c2<o2 and c3>=o3 and c4>=o4 and c5<o5 and c6<o6 and H5<h6 and h2<h6 and c4<=h6 and c3<=h6 AND c1<=H6 AND C>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4>=o4 and c5<o5 and c6<o6 and H5<=h6 and h3>=h6 and c4<=h6 and c2<=h6 AND c1<=H6 AND C>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4>=o4 and c5<o5 and c6<o6 AND C7<O7 and H6<h7 and h5>=h6 and c4<=h7 and c3<=h7 AND C2<=H7 and c1<=H7 AND C>h7 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4<o4 and c5>=o5 and c6<o6 AND C7<O7 and H6<h7 and c5<=h7 AND C3<=H7 AND C2<=H7 and c1<=H7 AND C>h7 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4<o4 and c5>=o5 and c6<o6 and h3=h4 and h4<h6 and c1<h6 and c>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4>=o4 and c5<o5 and c6<o6 and h5<h6 and c2<h6 and c1<h6 and c>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4<O4 and c5<o5 and c6<o6 AND H4>H5 and h5<h6 and c2<h6 and c1<h6 and c>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4>=O4 and c5<o5 and c6<o6 AND h5<h6 AND C4<=H6 AND C3<=H6 and c2<=h6 and c1<=h6 and c>h6 then
t=10
elsif c>=o and c1<o1 and c2>=o2 and c3>=o3 and c4<O4 and c5>=o5 and c6<o6 AND h4<h6 AND C3<=H6 AND C2<=H6 and c>h6 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4>=O4 and c5>=o5 and c6<o6 AND h3<h6 AND C2<=H6 AND C1<=H6 ANd c>h6 then
t=10
elsif h5<h6 and c6<o6 and c5<o5 AND c4<=h6 and c3<=h6 and c2<=h6 and c1<=h6 and c>h6 AND C>=O then
t=10
elsif c>=o and c1<o1 and c2>=o2 and c3>=o3 and c4>=o4 and c5>=o5 and c6<o6 and c7<o7 and h6<h7 and c2<=h7 and c3<=h7 and c4<=h7 and c5<=h7 and c>h7 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4>=o4 and c5<o5 and c6>=o6 and c7<o7 and h5<h7 and h3<h7 and c2<=h7 and c4<=h7 and c6<h7 and c1<=h7 and c>h7 then
t=10
elsif c>=o and c1<o1 and c2>=o2 and c3>=o3 and c4<o4 and c5<o5 and c6>=o6 and c7<o7 and h5<h7 and h4>=h5 and H1>=H5 AND c2<=h7 and c3<=h7 AND c>h7 then
t=10
elsif h5<h7 and c7<o7 and c5<o5 AND C6>O6 and c4<=h7 and c3<=h7 and c2<=h7 and c1<=h7 and c>h7 AND C>=O then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3>=o3 and c4>=o4 and c5<o5 and c6>=o6 and c7>=o7 and c8<o8 and h5<h8 and c1<h8 and c2<h8 and c3<h8 and c4<h8 and c>h8 then
t=10
elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4>=o4 and c5<o5 and c6>=o6 and c7>=o7 and c8<o8 and h5<h8 and c1<h8 and c2<h8 and c4<h8 and c>h8 then
t=10
elsif c>=o and c1>=o1 AND c5<o5 and c6>=o6 and c7>=o7 and c8<o8 and h5<h8 and c1<h8 and c>h8 then
t=10
elsif c>=o and c1>=o1 AND c2<o2 and c3>=o3 and c4>=o4 and c5<o5 and h2<h5 and c1<h5 and c>h5 then
t=10
elsif c>=o and c1>=o1 AND c2>=o2 and c3<o3 and c4>=o4 and c5<o5 AND C6<O6 and h5<h6 AND C4<=H6 AND C2<=H6 and c1<=h6 and c>h6 then
t=10
elsif c>=o AND C1<O1 and c2>=o2 and c3>=o3 and c4<o4 and c5>=o5 and c6>=o6 and c7>=o7 and c8<o8 and h4<h8 and c2<h8 and c>h8 then
t=10
elsif c>=o AND C1>=O1 and c2>=o2 and c3<o3 and c4>=o4 and c5>=o5 and c6<o6 and c7<o7 and h6<h7 and c5<=h7 AND C4<=H7 and c2<=h7 AND C1<=H7 and c>h7 then
t=10
elsif c>=o AND C1>=O1 and c2>=o2 and c3<o3 and c4>=o4 and c5>=o5 and c6>=o6 and c7<o7 and h3<h7 and c2<=h7 AND C1<=H7 and c>h7 then
t=10
elsif c>=o and c1>=o1 and c2<o2 and c3<o3 and c4>=o4 and c5>=o5 and c6>=o6 and c7>=o7 and c8<o8 AND C9<O9 and h8<H9 AND H2>H3 and c1<h9 AND C>H9 then
t=10
elsif h3<h5 and c5<o5 and c3<o3 AND c2<=h5 and c1<=h5 and c>h5 AND C>=O then
t=10
elsif h6<h7 and c7<o7 and c6<o6 AND C5<=H7 and c4<=h7 and c3<=h7 and c2<=h7 and c1<=h7 and c>h7 AND C>=O then
t=10
elsif h5<h8 and c8<o8 and c5<o5 AND c4<=h8 and c3<=h8 and c2<=h8 and c1<=h8 and c>h8 AND C>=O then
t=10
elsif h6<h8 and c8<o8 and c6<o6 AND C5<=H8 and c4<=h8 and c3<=h8 and c2<=h8 and c1<=h8 and c>h8 AND C>=O then
t=10
elsif h7<h8 and c7<o7 and c8<o8 and h6<h8 and c5<=h8 and c4<=h8 and c3<=h8 and c2<=h8 and c1<=h8 and c>h8 then
t=10
elsif h7<h10 and c10<o10 and c7<o7 and c6<=h10 and c5<=h10 and c4<=h10 and c2<=h10 AND C1<=H10 and c>h10 then
t=10
elsif h8<h9 and c9<o9 and c8<o8 and c7<=h9 and c6<=h9 and c5<=h9 and c4<=h9 and c3<=h9 and c2<=h9 and c1<=h9 and c>h9 then
t=10
elsif h9<h10 and c10<o10 and c9<o9 and c8<=h10 and c6<=h10 and c5<=h10 and c4<=h10 and c2<=h10 and c>h10 then
t=10
elsif h10<h12 and c10<o10 and c12<o12 and C9<=H12 AND c8<=h12 and C7<=H12 AND c6<=h12 and c5<=h12 and c4<=h12 AND c3<=h12 and c2<=h12 and c1<=h12 and c>h12 then
t=10
elsif c<o and c1>=o1 and c2>=o2 and l1>l2 and c<l2 then
t=-10
elsif c<o and c1>=o1 and c2<o2 and c3>=o3 AND L1>L3 AND c<l3 then
t=-10
elsif c<o and c1<o1 and c2>=o2 and c3>=o3 and c1>l3 and c<l3 then
t=-10
elsif c<o and c1>=o1 and c2<o2 and c3>=o3 and c4>=o4 and l3>l4 and c2>l4 and c<l1 and c<l4 then
t=-10
elsif c<o and c1<o1 and c2<o2 and c3>=o3 and c4>=o4 and c5>=o5 and c1>l4 and c<l5 then
t=-10
elsif l4>l5 and c5>=o5 and c4>=o4 and c3>=l5 and c2>=l5 and c1>=l5 and c<l5 then
t=-10
elsif c<o and c1>=o1 and c2<o2 and c3>=o3 and l1 and c1>l4 and c<l5 then
t=-10
elsif c<o and c1<o1 and c2>=o2 and c3<o3 and c4>=o4 and l2>l4 and c1>l4 and c<l4 then
t=-10
elsif c<o and c1>=o1 and c2<o2 and c3<o3 and c4>=o4 and l1>l4 and c<l4 then
t=-10
elsif c<o and c1<o1 and c2<o2 and c3>=o3 and c4>=o4 and l3>l4 and c1>l4 and c<l4 then
t=-10
elsif c<o and c1<o1 and c2>=o2 and c3<o3 and c4<o4 and c5>=o5 and c6>=o6 and l5>l6 and c3>l6 and c1>l6 and c<l6 then
t=-10
elsif c<o and c1<o1 and c2>=o2 and c3<o3 and c4>=o4 and c5<o5 and c6>=o6 and l4>l6 and c3>l6 and c1>l6 and c<l6 then
t=-10
elsif c<o and c1>=o1 and c2<o2 and c3>=o3 and c4<o4 and c5<o5 and l3>l6 and c2>l6 and c<l6 then
t=-10
elsif c<o and c1>=o1 and c2<o2 and c3<o3 and c4>=O4 and c5>=o5 and l4>l5 and c2>=L5 AND C3<=L5 and c<l5 then
t=-10
elsif c<o and c1<o1 and c2>=o2 and c3<o3 and c4>=o4 and c5<o5 and c6<o6 and c7>=o7 and l4>l7 and l2>l7 and c1>l7 and c<l7 then
t=-10
elsif l6>l7 and c7>=o7 and c6>=o6 and c5>=l7 and c4>=l7 and c3>=l7 and c2>=l7 and c1>=l7 and c<l7 then
t=-10
elsif l7>l8 and c8>=o8 and c7>=o7 and c6>=l8 and c5>=l8 and c4>=l8 and c3>=l8 and c2>=l8 and c1>=l8 and c<l8 then
t=-10
elsif l8>l9 and c8>=o8 and c9>=o9 AND C7>=L9 and c6>=l9 and c5>=l9 and c4>=l9 and c3>=l9 and c2>=l9 and c1>=l9 and c<l9 then
t=-10
elsif t[7]=10 and c7>=o7 and c5>=o5 and l5<=l7 and c2>=o2 and l2<=l5 and c<l2 and c<o then
t=-10
endif
return t as "2B-LS", 1 AS "L", -1 AS "S"
COND will be true whenever your pattern is detected:
Bullish = close > open
Bearish = close < open
c1 = (Summation[2](Bearish[1]) = 2)
c2 = (close > highest[2](close[1]))
Cond = c1 AND c2
You can add
Return Cond
Hello Robert, thank you for your response, however,
Code is throwing error: as per the first chart in the attachment.
When modified by remarking the “Bullish” line, it is not working as desired: as per the second chart in the attachment.
The desired behaviour should be like the below: (as per my lengthy code, which I want to be shortened): as per the last chart in the attachment.
Attach image file types for images, JPG or PNG extensions, please. Thank you.
I couldn’t detect what you wanted to highlight in your second pic.
I forgot to use the BULLISH variable. There you go:
Bullish = close > open
Bearish = close < open
c1 = (Summation[2](Bearish[1]) = 2)
c2 = (close > highest[2](close[1]))
CondL = c1 AND c2 AND Bullish
d1 = (Summation[2](Bullish[1]) = 2)
d2 = (close < lowest[2](close[1]))
CondS = d1 AND d2 AND Bearish
Cond = 0
If CondL Then
Cond = 1
Elsif CondS then
Cond = -1
Endif
Return Cond
I also added the viceversa.
In your first post you talked about “Bullish Bar Closing above 2 Bearish Bar” but your file had more patterns.
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"
DEFPARAM CalculateOnLastBars = 1000
Bullish = close > open
Bearish = close < open
InsideBAR = (range < range[1]) AND (high <= high[1]) AND (low >= low[1])
//
// DOWN trend detection
//
Count1 = 0
i = 0
WHILE Count1 < 2 AND i < BarIndex
i = i + 1
IF Count1 = 0 THEN
IF Bullish[i] AND Not InsideBAR[i] THEN
Count1 = 1
MyLO1 = low[i]
ENDIF
ELSE
IF Bullish[i] AND Not InsideBAR[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] AND Not InsideBAR[j] THEN
Count2 = 1
MyHI1 = high[j]
ENDIF
ELSE
IF Bearish[j] AND Not InsideBAR[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"
Bullish Bar Closing above 2 Bearish Bar and vice versa
This topic contains 22 replies,
has 3 voices, and was last updated by
robertogozzi
5 years, 6 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 07/14/2020 |
| Status: | Active |
| Attachments: | 13 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.