Announcement

Collapse
No announcement yet.

Pattern recognition

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pattern recognition

    I am trying to recognize a certain pattern in a study (in this case CCI). Specifically, I would like to know when the CCI comes from above 100 and crosses through 0 without "backing up" meaning it has only gone in a down direction from a high above 100.

    It was easy to determine when the CCI crosses thru zero. Is there an elegant way to recognize that it also has traveled from +100 down thru zero without having an up bar (or from below -100 to above zero without a down bar)?

    here is the code that recognizes the zero crossover.

    function main(Length,Source,Symbol,Interval,Upper,Lower,Par ams) {

    if(bInit == false){

    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xCCI = cci(Length, eval(Source)(sym(vSymbol)));
    setShowTitleParameters(eval(Params));
    addBand( Upper, PS_DOT, 3, Color.red,"Upper");
    addBand( Lower, PS_DOT, 3, Color.lime,"Lower");
    addBand(0, PS_SOLID, 2, Color.black,"Zero");

    bInit = true;

    }

    if (xCCI.getValue(-1) < 0 && xCCI.getValue(0) > 0) && {
    setBarThickness(2);
    setBarFgColor(Color.yellow);
    }
    else if (xCCI.getValue(-1) > 0 && xCCI.getValue(0) < 0) {
    setBarThickness(2);
    setBarFgColor(Color.red);
    }
    else {
    setBarThickness(2);
    setBarFgColor(Color.blue);
    }

    return getSeries(xCCI);
    }

  • #2
    possible solution.

    in my opinion, the easiest way to handle this is with a conditional mechanism that tracks the CCI.. Think of it like a little ongoing verification of the conditions you are looking for..

    Here, I've tried to modify your code to do what you want..


    PHP Code:

    //  Added new conditional mechanism variables.
    var CCIConditional 0;
      
    //  0 = neutral
      // 1 = below -100 and moved up continuously
      // -1 = above 100 and moved down continuously

    function main(Length,Source,Symbol,Interval,Upper,Lower,Par
    ams
    ) {

    if(
    bInit == false){
      if(
    Symbol == nullSymbol getSymbol();
      if(
    Interval == nullInterval getInterval();
      var 
    vSymbol Symbol+","+Interval;
      
    xCCI cci(Length, eval(Source)(sym(vSymbol)));
      
    setShowTitleParameters(eval(Params));
      
    addBandUpperPS_DOT3Color.red,"Upper");
      
    addBandLowerPS_DOT3Color.lime,"Lower"); 
      
    addBand(0PS_SOLID2Color.black,"Zero");

      
    bInit true;
    }

    if (
    xCCI.getValue(-1) < && xCCI.getValue(0) > 0) && {
      
    setBarThickness(2);
      
    setBarFgColor(Color.yellow);
    } else if (
    xCCI.getValue(-1) > && xCCI.getValue(0) < 0) {
      
    setBarThickness(2);
      
    setBarFgColor(Color.red);
    } else {
      
    setBarThickness(2);
      
    setBarFgColor(Color.blue);
    }

    if (
    xCCI.getValue(-1) <= -100) {
      
    //  meets our setup condition for #1
       
    CCIConditional 1;
    }
    if ((
    xCCI.getValue(-1) > -100) && (CCIConditional 0) &&  
        (
    xCCI.getValue(-1) < xCCI.getValue(-2)) ) {
      
    //  Fails to meet our continuous upward trending after #1
       
    CCIConditional 0;
    }

    if (
    xCCI.getValue(-1) >= 100) {
      
    //  meets our setup condition for #-1
       
    CCIConditional = -1;
    }
    if ((
    xCCI.getValue(-1) < 100) && (CCIConditional 0) &&  
        (
    xCCI.getValue(-1) > xCCI.getValue(-2)) ) {
      
    //  Fails to meet our continuous downward trending after #-1
       
    CCIConditional 0;
    }

    //  Now all you have to do is look for one of these conditions and the cross above ZERO..

    if ((xCCI.getValue(-1) < 0) && (CCIConditional 0) ) {
      
    //  Meets our DOWNWARD condition with a cross below ZERO
      //  Do something
       
    CCIConditional 0;
    }
    if ((
    xCCI.getValue(-1) > 0) && (CCIConditional 0) ) {
      
    //  Meets our UPWARD condition with a cross above ZERO
      //  Do something
       
    CCIConditional 0;
    }


    return 
    getSeries(xCCI);

    Last edited by Doji3333; 09-27-2006, 12:22 AM.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment

    Working...
    X