AFL for Bar Count for Rally/Decline

SR_TA

Active Member
#1
Sorry, creating a thread as my earlier post in other thread got lost..

Team..Need help.. Does anyone has a code to count the number of bars in Rally/Decline..

Rally (higher high and higher low) & decline (lower high and lower low)..

For every 3,4,5 consecutive rally bars it should mark 1,2,3 respectively as support and vice versa..i.e. 1,23 as resistence in decline..

tks for help
 

SR_TA

Active Member
#2
Finally, I wrote it after some struggle.. if anyone knows how to optimize, will be grateful

_SECTION_BEGIN("SR_rally_Decline");
upbar1 = H >= Ref( H, -1 ) AND Ref( H, -1 ) >= Ref ( H, -2 ) AND Ref( H, -2 ) >= Ref ( H, -3 ) AND L >= Ref( L, -1 ) AND Ref( L, -1 ) >= Ref ( L, -2 ) AND Ref( L, -2 ) >= Ref ( L, -3 );
upbar2 = upbar1 AND Ref( H, -3 ) >= Ref ( H, -4 ) AND Ref( L, -3 ) >= Ref ( L, -4 );
upbar3 = upbar2 AND Ref( H, -4 ) >= Ref ( H, -5 ) AND Ref( L, -4 ) >= Ref ( L, -5 );
upbar4 = upbar3 AND Ref( H, -5 ) >= Ref ( H, -6 ) AND Ref( L, -5 ) >= Ref ( L, -6 );

PlotShapes( IIf(upbar4,shapeDigit4,IIf(upbar3, shapeDigit3,IIf( upbar2, shapeDigit2, IIf( upbar1, shapeDigit1, shapeNone )))), colorGreen, 0, L, -20 );


dnbar1 = H <= Ref( H, -1 ) AND Ref( H, -1 ) <= Ref ( H, -2 ) AND Ref( H, -2 ) <= Ref ( H, -3 ) AND L <= Ref( L, -1 ) AND Ref( L, -1 ) <= Ref ( L, -2 ) AND Ref( L, -2 ) <= Ref ( L, -3 );
dnbar2 = dnbar1 AND Ref( H, -3 ) <= Ref ( H, -4 ) AND Ref( L, -3 ) <= Ref ( L, -4 );
dnbar3 = dnbar2 AND Ref( H, -4 ) <= Ref ( H, -5 ) AND Ref( L, -4 ) <= Ref ( L, -5 );
dnbar4 = dnbar3 AND Ref( H, -5 ) <= Ref ( H, -6 ) AND Ref( L, -5 ) <= Ref ( L, -6 );

PlotShapes( IIf(dnbar4,shapeDigit4,IIf(dnbar3, shapeDigit3,IIf( dnbar2, shapeDigit2, IIf( dnbar1, shapeDigit1, shapeNone )))), colorRed, 0, H, 20 );
_SECTION_END();
 

Similar threads