Announcement

Collapse
No announcement yet.

CCI cross code improvment help

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

  • CCI cross code improvment help

    Hi,

    I have a CCI Arrow Alert that is not working excatly the way I would like. The Alert puts an arrow at the 1st tick of a new bar after a plus or minus 100 cross. I would also like to get an Arrow Alert if the CCI crosses the plus or minus 100 within a bar.

    For example: If the CCI is below -100 for a few bars then and within one of the bars the CCI goes above -100 then back though, I would also like to get an Arrow Alert also.

    Below is the code I'm using, any suggestions would be greatly appreciated

    Thank you,
    Mac

    var vFlag = false;

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("CCI Alert");
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.RGB(255,255,255));
    setShowCursorLabel(false);
    }

    var bInit = false;

    var wCCI = null;

    function main() {

    if (bInit == false) {
    Symbol = getSymbol();
    Interval1 = getInterval();
    var vSymbol1 = Symbol+","+Interval1;
    wCCI = cci(20,sym(vSymbol1));
    bInit = true;
    }

    if (getBarState() == BARSTATE_NEWBAR)
    vFlag = false;

    var gCCI = wCCI.getValue(0);
    var gCCI_1 = wCCI.getValue(-1);

    if (
    gCCI == null || gCCI_1 == null
    ) return;

    if(vFlag == false){
    if (gCCI > 100 && gCCI_1 < 100) {
    drawShape(Shape.UPARROW, BelowBar1, Color.RGB(0,255,0));
    vFlag = true;
    }
    else if (gCCI < -100 && gCCI_1 > -100) {
    drawShape(Shape.DOWNARROW, AboveBar1, Color.RGB(0,255,0));
    vFlag = true ;
    }
    }

    return;
    }

  • #2
    Re: CCI cross code improvment help

    Hi Mac,
    I tried in tick replay and it seems ok.
    I changed only the scope of variables.
    Bye
    Max


    var vFlag = false;
    var gCCI = null;
    var gCCI_1 = null;
    var vSymbol1 = null;
    var bInit = false;
    var wCCI = null;

    function preMain() {
    debugClear();
    setPriceStudy(true);
    setStudyTitle("CCI Alert");
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.RGB(255,255,255));
    setShowCursorLabel(false);
    }

    function main() {

    if (bInit == false) {
    Symbol = getSymbol();
    Interval1 = getInterval();
    vSymbol1 = Symbol+","+Interval1;
    wCCI = cci(20);
    bInit = true;
    }

    if (getBarState() == BARSTATE_NEWBAR) vFlag = false;
    if (getBarState() == BARSTATE_NEWBAR) debugPrintln("------------- NEW BAR");
    debugPrintln("vFlag = "+vFlag);

    gCCI = wCCI.getValue(0);
    gCCI_1 = wCCI.getValue(-1);
    debugPrintln("gCCI = "+gCCI+" gCCI_1 = "+gCCI_1);

    if (gCCI == null || gCCI_1 == null) return;

    if(vFlag == false){
    if (gCCI > 100 && gCCI_1 < 100) {
    drawShape(Shape.UPARROW, BelowBar1, Color.RGB(0,255,0));
    vFlag = true;
    debugPrintln("UPARROW VERDE vFlag ="+vFlag);
    } else if (gCCI < -100 && gCCI_1 > -100) {
    drawShape(Shape.DOWNARROW, AboveBar1, Color.RGB(255,0,0));
    vFlag = true ;
    debugPrintln("DOWNARROW ROSSA vFlag ="+vFlag);
    }
    }

    return;
    }

    Comment


    • #3
      Hi Max,

      Thank you for your reply. Your code is a definitely an improvement over mine and I'm going to use it to replace what I had.

      There is one thing that I'm also looking for also that neither code accomplishes. If for example the prevous bar is trading with the CCI above +100 at the close and coming into the open of the present bar the CCI is +100 If within the present bar the CCI crosses below +100 then sometime later it crosses back above +100 I don't get an arrow. Which is also what I'm looking for.

      If you have any suggestions please advise.

      Below is code Alex worte a couple of years ago that may offer a clue. I don't really understand the code or how covvert it to work on a CCI:

      Thanks Much,
      Mac

      //Alexis C. Montenegro © March 2006
      //Please include the above line when modifying this code

      function preMain() {
      setPriceStudy(true);
      setStudyTitle("MAx2(one alert)");
      setCursorLabelName("MA1", 0);
      setCursorLabelName("MA2", 1);
      setDefaultBarFgColor(Color.blue, 0);
      setDefaultBarFgColor(Color.red, 1);
      }

      var vMA1 = null;
      var vMA2 = null;
      var vFlag1 = 0;
      var vFlag2 = 0;

      function main(MALength1, MALength2) {

      if(MALength1==null) MALength1 = 5; else MALength1 = MALength1;
      if(MALength2==null) MALength2 = 10; else MALength2 = MALength2;

      if(getBarState()==BARSTATE_ALLBARS){
      vMA1 = new MAStudy(MALength1, 0, "Close" , MAStudy.SIMPLE);
      vMA2 = new MAStudy(MALength2, 0, "Close" , MAStudy.SIMPLE);
      }

      if(vMA1.getValue(MAStudy.MA,-1) ==null || vMA2.getValue(MAStudy.MA,-1) == null) return;

      //this section determines the relative position of the averages at the prior bar
      //and sets the Flags accordingly
      if(getBarState() == BARSTATE_NEWBAR){
      if(vMA1.getValue(MAStudy.MA,-1) > vMA2.getValue(MAStudy.MA,-1)){
      vFlag1 = 1;
      vFlag2 = 1;
      }
      if(vMA1.getValue(MAStudy.MA,-1) < vMA2.getValue(MAStudy.MA,-1)){
      vFlag1 = -1;
      vFlag2 = -1;
      }
      }

      //the following section triggers alerts only in the direction determined by the code above

      //if crossing over
      if(vFlag1 == -1){
      if(vMA1.getValue(MAStudy.MA) > vMA2.getValue(MAStudy.MA) && vFlag2 == -1){
      Alert.playSound("ding.wav");
      vFlag2 = 1;
      }
      if(vMA1.getValue(MAStudy.MA) < vMA2.getValue(MAStudy.MA) && vFlag2 == 1){
      vFlag2 = -1;
      }
      }
      //if crossing under
      if(vFlag1 == 1){
      if(vMA1.getValue(MAStudy.MA) < vMA2.getValue(MAStudy.MA) && vFlag2 == 1){
      Alert.playSound("buzz.wav");
      vFlag2 = -1;
      }
      if(vMA1.getValue(MAStudy.MA) > vMA2.getValue(MAStudy.MA) && vFlag2 == -1){
      vFlag2 = 1;
      }
      }


      return new Array (vMA1.getValue(MAStudy.MA),vMA2.getValue(MAStudy.M A));

      Comment


      • #4
        Hi Mac,
        if I have understood right you don't mind the previous bar but the cross +100 or -100 within the bar, so I would simplify the EFS this way.
        Let me know.
        Ciao
        Massimo



        var vFlag = false;
        var gCCI = null;
        var gCCI_1 = null;
        var bInit = false;
        var wCCI = null;

        function preMain() {
        debugClear();
        setPriceStudy(true);
        setStudyTitle("CCI Alert");
        setColorPriceBars(true);
        setDefaultPriceBarColor(Color.RGB(255,255,255));
        setShowCursorLabel(false);
        }

        function main() {

        if (bInit == false) {
        wCCI = cci(20);
        bInit = true;
        }
        debugPrintln("New Tick Arrived ......");
        debugPrintln("Previous Tick: gCCI = "+gCCI+" gCCI_1 = "+gCCI_1);

        gCCI_1 = gCCI;
        gCCI = wCCI.getValue(0);

        if (getBarState() == BARSTATE_NEWBAR) vFlag = false;
        if (getBarState() == BARSTATE_NEWBAR) debugPrintln("------------- NEW BAR");

        debugPrintln("New Tick: gCCI = "+gCCI+" gCCI_1 = "+gCCI_1+" vFlag = "+vFlag);


        if (gCCI == null || gCCI_1 == null) return;

        if(vFlag == false){
        if (gCCI > 100 && gCCI_1 < 100) {
        drawShape(Shape.UPARROW, BelowBar1, Color.RGB(0,255,0));
        vFlag = true;
        debugPrintln("UPARROW VERDE vFlag ="+vFlag);
        } else if (gCCI < -100 && gCCI_1 > -100) {
        drawShape(Shape.DOWNARROW, AboveBar1, Color.RGB(255,0,0));
        vFlag = true ;
        debugPrintln("DOWNARROW ROSSA vFlag ="+vFlag);
        }
        }

        return;
        }

        Comment


        • #5
          Max,

          Your new version is working the way I want.

          Thank you for all your help!

          Mac

          Comment

          Working...
          X