Contiguous up movement for N bars, was: Smarter Coding Hack

Evening all,
Looking to the smart coders as there is normally some hacks that allow code to be shrunk a bit, I have tried the SUM function but it doesn't seem to work.
WHat I want to do in a shorter version is have a condition where a moving average has risen over a period of bars and not just higher than it was XX bars ago. My code works in the long format but hopefully there is a shorter version of it I can learn.
As you can see I want to see the the SMA3 rise consistently over 22 bars and not just be above it 22 bars ago.
Hopefully there is a coding hack someone knows.

TideRise = Ref(SMA3, 0) > Ref(SMA3,-1) AND Ref(SMA3, -1) > Ref(SMA3,-2) AND Ref(SMA3, -2) > Ref(SMA3,-3) AND Ref(SMA3, -3) > Ref(SMA3,-4) 
AND Ref(SMA3, -4) > Ref(SMA3,-5) AND Ref(SMA3, -5) > Ref(SMA3,-6) AND Ref(SMA3, -6) > Ref(SMA3,-7) AND Ref(SMA3, -7) > Ref(SMA3,-8) 
AND Ref(SMA3, -8) > Ref(SMA3,-9) AND Ref(SMA3, -9) > Ref(SMA3,-10) AND Ref(SMA3, -10) > Ref(SMA3,-11) AND Ref(SMA3, -11) > Ref(SMA3,-12) 
AND Ref(SMA3, -12) > Ref(SMA3,-13) AND Ref(SMA3, -13) > Ref(SMA3,-14) AND Ref(SMA3, -14) > Ref(SMA3,-15) AND Ref(SMA3, -15) > Ref(SMA3,-16) 
AND Ref(SMA3, -16) > Ref(SMA3,-17) AND Ref(SMA3, -17) > Ref(SMA3,-18) AND Ref(SMA3, -18) > Ref(SMA3,-19) AND Ref(SMA3, -19) > Ref(SMA3,-20) 
AND Ref(SMA3, -20) > Ref(SMA3,-21) AND Ref(SMA3, -21) > Ref(SMA3,-22);

Cheers
Greg

This has been asked dozens of times in the past.

NBars = 21; // number of bars for contiguous movement
UpOneBar = SMA3 > Ref( SMA3, -1 );
TideRise = Sum( UpOneBar, NBars  ) == NBars ; // N up bars within last N bars

Hint: make sure that your SUBJECT line matters and accurately describes the issue at hand. "Smart coding hack" isn't good choice for others to find your question later.

Thanks for that Tomasz,
Yeah was struggling to think of a way to title it. Appreciate the help mate. Will remember that for next time.

Cheers

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.