New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.

CCI above 0 for 80% of the last 120 trading days

This one is a bit complicated but wondering if anyone knows if this is possible. I basically want to see whether the CCI has been above 0 for the majority of the last 120 trading days. I used 80% to give a percentage value to the majority but yeah i was just wondering if such a scan is possible.

Much appreciated!


  • I don't think so.

    There are functions like Count Up ( ) and Count Down( ), and Streak Up ( ) and Streak Down ( ), but I don't think those would do it. The Count functions only deal with the number of times a previous value was higher or lower, and the Streak functions only deal with the number of consecutive values changing in one direction.

    The function you want is something like Count Above( ) and Count Below( ), but as far as I know there is no such function, and I don't think there is a way to use existing functions and/or indicators to synthesize them.

    That leaves testing each of the 120 bars in various combinations of above and below zero, but the number of combinations, while not infinite, would be considerable, and beyond the character limit of the scan window.
  • A thought may be to use the MA of the CCI. If the CCI is above 0 the vast majority of the time (80%) the MA should, most likely be above 0, while allowing for a minor dip.

    As @markd mentioned, the formula for testing 120 bars would be a bear and probably undesirable. Another option could be to change to weekly or monthly time frames. CCI defaults to 20 days or approximately 1 month. 120 days is approximately 6 months. Still a bear, and I don't know what you are trying to accomplish, but just a thought. If you looked at months 1-5 (ignoring current month 6) a nested code would look at

    // at least 4 out of 5 months over 0

    and [
    [monthly 1-5 >= 0] // 100% above 0

    // these lines allow 20% of the months in the range to be less than 0
    or [monthly 1-4 >= 0] // allows month 5 to be less than 0
    or [[monthly 1-3 >= 0] and [monthly 5 >= 0]] //allows month 4 to be less than 0
    or [[monthly 1-2 >= 0] and [monthly 4-5 >= 0]] //allows month 3 to be less than 0
    or [[monthly 1 >= 0] and [monthly 3-5 >= 0]] //allows month 2 to be less than 0
    or [monthly 2-5 >= 0] // allows month 1 to be less than 0

    You could include the current month if desired, but remember, the current month isn't final until the last close of the month. Changing to weekly you would employ the same "logic" and be looking at 24 weeks or so and would be a fun exercise in scan code writing.

Sign In or Register to comment.