Announcement

Collapse
No announcement yet.

Different values for CCI if source if a variable?

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

  • Different values for CCI if source if a variable?

    Hi,
    I get a different value for the CCI if I hard code the source or use a variable. How come?

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("CCI");
    setCursorLabelName("CCI",0);
    setCursorLabelName("CCI Var",1);
    setDefaultBarFgColor(Color.blue,0);
    setDefaultBarThickness(2,0);
    }

    var cbCCI_Var = 0;
    var cbCCI = 0;
    var nCCIPeriod = 14;
    var nCCISource = "hlc3()";

    function main() {

    cbCCI = cci(14,hlc3()).toFixed(2)*1;
    cbCCI_Var = cci(14,nCCISource).toFixed(2)*1;

    var retArray = new Array(2);

    setBarFgColor(Color.blue, 0);
    setBarFgColor(Color.red, 1);
    retArray[0] = cbCCI;
    retArray[1] = cbCCI_Var;

    return retArray;
    }

    Attached should be a screen shot.

    How do you get a screen shot into the text?

    Tom

  • #2
    Tom
    That is happening because the syntax used in the cci() function in the following line of code
    cbCCI_Var = cci(14,nCCISource).toFixed(2)*1;
    is incorrect for what you are trying to accomplish. The cci() function expects a series object as the source parameter and if it does not find one it reverts to its default source which is close().
    In your case nCCISource is a string ie "hlc3()" and not a series object so you need to evaluate it to be able to use it as the source parameter. Try replacing that line of code with the following
    cbCCI_Var = cci(14,eval(nCCISource)).toFixed(2)*1;
    and you should see the plot match the one returned by the other cci() function.
    Alex

    Comment


    • #3
      Thank You Alexis

      I did not know about the method eval(). I have a good use for it in another application.

      Comment

      Working...
      X