Bullish Bar Closing above 2 Bearish Bar and vice versa
Forums › ProRealTime English forum › ProBuilder support › Bullish Bar Closing above 2 Bearish Bar and vice versa
- This topic has 22 replies, 3 voices, and was last updated 4 years ago by robertogozzi.
-
-
07/14/2020 at 12:24 PM #139235
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.
Bullish bar closing above 2 Bearish bar and vice versa123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190c=closeo=openl=lowhi=highc1=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 thent=10ELSif c>=o and c1<o1 and c2>=o2 AND C3<O3 AND H1<H3 and c>h3 thent=10elsif c>=o and c1<o1 and c2<o2 and c3<o3 and h1<h3 and h2<h3 and c>h3 thent=10elsif c>=o and c1>=o1 and c2<o2 and c3<o3 and h2<h3 and c1<h3 and c>h3 thent=10elsif c>=o and c1<o1 and c2<o2 and c3<o3 and h1>h2 and h2<h3 and c>h3 thent=10ELSif 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 thent=10ELSif c>=o and c1<o1 and c2>=o2 AND C3<O3 and c4<o4 AND H3<H4 and c2<=h4 and c>h4 thent=10elsif c>=o and c1>=o1 and c2>=o2 and c3<o3 and c4<o4 and h3<h4 and c1<h4 and c>h4 thent=10elsif c>=o and c1>=o1 and c2<o2 and c3>=o3 and c4<o4 and h2<h4 and c1<h4 and c>h4 thent=10elsif c>=o and c1>=o1 and c2<o2 and c3<o3 and c4<o4 and h3<h4 and c1<h4 and c>h4 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif h4<h5 and c5<o5 and c4<o4 AND c3<=h5 and c2<=h5 and c1<=h5 and c>h5 AND C>=O thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif h3<h5 and c5<o5 and c3<o3 AND c2<=h5 and c1<=h5 and c>h5 AND C>=O thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif 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 thent=10elsif c<o and c1>=o1 and c2>=o2 and l1>l2 and c<l2 thent=-10elsif c<o and c1>=o1 and c2<o2 and c3>=o3 AND L1>L3 AND c<l3 thent=-10elsif c<o and c1<o1 and c2>=o2 and c3>=o3 and c1>l3 and c<l3 thent=-10elsif 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 thent=-10elsif c<o and c1<o1 and c2<o2 and c3>=o3 and c4>=o4 and c5>=o5 and c1>l4 and c<l5 thent=-10elsif l4>l5 and c5>=o5 and c4>=o4 and c3>=l5 and c2>=l5 and c1>=l5 and c<l5 thent=-10elsif c<o and c1>=o1 and c2<o2 and c3>=o3 and l1 and c1>l4 and c<l5 thent=-10elsif c<o and c1<o1 and c2>=o2 and c3<o3 and c4>=o4 and l2>l4 and c1>l4 and c<l4 thent=-10elsif c<o and c1>=o1 and c2<o2 and c3<o3 and c4>=o4 and l1>l4 and c<l4 thent=-10elsif c<o and c1<o1 and c2<o2 and c3>=o3 and c4>=o4 and l3>l4 and c1>l4 and c<l4 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif 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 thent=-10elsif t[7]=10 and c7>=o7 and c5>=o5 and l5<=l7 and c2>=o2 and l2<=l5 and c<l2 and c<o thent=-10endifreturn t as "2B-LS", 1 AS "L", -1 AS "S"07/14/2020 at 2:02 PM #139246COND will be true whenever your pattern is detected:
12345Bullish = close > openBearish = close < openc1 = (Summation[2](Bearish[1]) = 2)c2 = (close > highest[2](close[1]))Cond = c1 AND c207/14/2020 at 2:03 PM #139248You can add
1Return Cond07/15/2020 at 4:29 AM #139294Hello 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.
07/15/2020 at 10:08 AM #139319Attach 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:
123456789101112131415Bullish = close > openBearish = close < openc1 = (Summation[2](Bearish[1]) = 2)c2 = (close > highest[2](close[1]))CondL = c1 AND c2 AND Bullishd1 = (Summation[2](Bullish[1]) = 2)d2 = (close < lowest[2](close[1]))CondS = d1 AND d2 AND BearishCond = 0If CondL ThenCond = 1Elsif CondS thenCond = -1EndifReturn CondI also added the viceversa.
In your first post you talked about “Bullish Bar Closing above 2 Bearish Bar” but your file had more patterns.
07/16/2020 at 3:15 AM #139392Thank you Robert, but it seems you have not correctly understood the conditions. Here they are:
For identifying DOWN trend the requirement is
-
- bearish bar should close below the lowest low of the previous 2 bullish bars (they (bullish and/ or bearish) may not be consecutive and the last bullish bar’s low should be higher than the previous bullish bar’s low).
For identifying UP trend the requirement is
-
- bullish bar should close above the highest high of the previous 2 bearish bars (they (bullish and/ or bearish) may not be consecutive and the last bearish bar’s high should be lower than the previous bearish bar’s high).
Your new code is throwing wrong results (enclosed chart named robert.jpg). It should be like enclosed correct.jpg
Many thanks for your time and effort.
07/16/2020 at 4:14 AM #139395No, you wrote you wanted to find “Bullish Bar Closing above 2 Bearish Bar”.
To find something different, a different code is needed.
I’ll make it as soon as I can.
1 user thanked author for this post.
07/16/2020 at 5:55 PM #139440There you go:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061DEFPARAM CalculateOnLastBars = 1000Bullish = close > openBearish = close < open//// DOWN trend detection//Count1 = 0i = 0WHILE Count1 < 2 AND i < BarIndexi = i + 1IF Count1 = 0 THENIF Bullish[i] THENCount1 = 1MyLO1 = low[i]ENDIFELSEIF Bullish[i] THENCount2 = 2MyLO2 = low[i]d1 = MyLO1 > MyLO2MyLO2 = min(MyLO1,MyLO2)BreakENDIFENDIFWENDd2 = Bearishd3 = close < MyLO2Dcond = d1 AND d2 AND d3//// UP trend detection//Count2 = 0j = 0WHILE Count2 < 2 AND j < BarIndexj = j + 1IF Count2 = 0 THENIF Bearish[j] THENCount2 = 1MyHI1 = high[j]ENDIFELSEIF Bearish[j] THENCount2 = 2MyHI2 = high[j]u1 = MyHI1 < MyHI2MyHI2 = max(MyHI1,MyHI2)BreakENDIFENDIFWENDu2 = Bullishu3 = close > MyHI2Ucond = u1 AND u2 AND u3//Cond = 0IF Ucond THENCond = 1ELSIF Dcond THENCond = -1ENDIFRETURN Cond AS "Signal"07/17/2020 at 8:33 AM #139479Great help Robert. You are brilliant. The code is missing some of the signals as captured in the enclosed document. Can it be fixed please.
Also, can it be possible to make it continuous histograms as shown in the enclosed document.
Many thanks.
07/17/2020 at 10:36 AM #139492When you need to attach images, please use JPG or PNG files. PDF are just for documents AND TXT are for unfornatted text. Thank you 🙂
Please tell me the rules you want to add, using text, not pics.
If you remove line 55 you’ll have a continuous histogram, since the previous signal is retained when there’s currently none.
07/17/2020 at 6:04 PM #139517Roberto code above added as Log 230 here …
1 user thanked author for this post.
07/18/2020 at 3:48 PM #139578Hello Robert, thank you for your time. The requirement is the same as before as written earlier and now as below:
For identifying DOWN trend the requirement is
-
- bearish bar should close below the lowest low of the previous 2 bullish bars (they (bullish and/ or bearish) may not be consecutive and the last bullish bar’s low should be higher than the previous bullish bar’s low ignoring the inside bar in between is any).
For identifying UP trend the requirement is
-
- bullish bar should close above the highest high of the previous 2 bearish bars (they (bullish and/ or bearish) may not be consecutive and the last bearish bar’s high should be lower than the previous bearish bar’s high ignoring the inside bar in between is any).
Many thanks for your time and effort.
07/18/2020 at 5:27 PM #139586I’ll take care of it early next week.
07/19/2020 at 6:17 AM #139595Many thanks dear.
07/20/2020 at 9:33 AM #139655Try this one (not tested):
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162DEFPARAM CalculateOnLastBars = 1000Bullish = close > openBearish = close < openInsideBAR = (range < range[1]) AND (high <= high[1]) AND (low >= low[1])//// DOWN trend detection//Count1 = 0i = 0WHILE Count1 < 2 AND i < BarIndexi = i + 1IF Count1 = 0 THENIF Bullish[i] AND Not InsideBAR[i] THENCount1 = 1MyLO1 = low[i]ENDIFELSEIF Bullish[i] AND Not InsideBAR[i] THENCount2 = 2MyLO2 = low[i]d1 = MyLO1 > MyLO2MyLO2 = min(MyLO1,MyLO2)BreakENDIFENDIFWENDd2 = Bearishd3 = close < MyLO2Dcond = d1 AND d2 AND d3//// UP trend detection//Count2 = 0j = 0WHILE Count2 < 2 AND j < BarIndexj = j + 1IF Count2 = 0 THENIF Bearish[j] AND Not InsideBAR[j] THENCount2 = 1MyHI1 = high[j]ENDIFELSEIF Bearish[j] AND Not InsideBAR[j] THENCount2 = 2MyHI2 = high[j]u1 = MyHI1 < MyHI2MyHI2 = max(MyHI1,MyHI2)BreakENDIFENDIFWENDu2 = Bullishu3 = close > MyHI2Ucond = u1 AND u2 AND u3//Cond = 0IF Ucond THENCond = 1ELSIF Dcond THENCond = -1ENDIFRETURN Cond AS "Signal" -
-
AuthorPosts
Find exclusive trading pro-tools on