Announcement

Collapse
No announcement yet.

Reference error and getValue error Please Help

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

  • Reference error and getValue error Please Help

    Cut and past the script then load it and you will get a reference error message; "myDCHstudy1 is not defined" .

    I have written many script that are very similiar in form and I don't know why this error is occuring.

    Next cut; vVClose = getValue("Close", 0, -Lgth);
    //if (vVClose == null) return;
    and paste it below; if (vValueH1 == null|| vValueL1 == null ) return;

    Then load the script and you will get no error message but there will be no values for vVClose.

    I am stumped. As I said I have written a varity of scriptd that follow the same form and have not had these problems.

    Thanks for the help.




    function preMain(){
    setStudyTitle("DCH ROC");
    setCursorLabelName("ROC",0);
    setDefaultBarFgColor(Color.red,0);
    setPriceStudy(false);


    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setName("DCH Length");
    fp1.setDefault(4);
    fp1.setLowerLimit(1);

    var fp2 = new FunctionParameter("Lgth", FunctionParameter.NUMBER);
    fp2.setName("Close Length");
    fp2.setDefault(8);
    fp2.setLowerLimit(1);

    }

    var vVClose = null;//vValueH1 = null, vValueL1 = null,

    function main(Length, Lgth){
    var vSm, vValueH1, vValueL1;

    vVClose = getValue("Close", 0, -Lgth);
    //if (vVClose == null) return;

    if (getBarState() == BARSTATE_ALLBARS) {
    myDCHstudy1 = new DonchianStudy(Length, 0);
    }

    vValueH1 = myDCHstudy1.getValue(DonchianStudy.UPPER);
    vValueL1 = myDCHstudy1.getValue(DonchianStudy.LOWER);
    if (vValueH1 == null|| vValueL1 == null ) return;


    // vSm = 0;
    //for(i = 0; i < Lgth+1; i++) {
    // vSm += vC[i] - vC[i + 1];
    // }

    //vSm = vSm/(vValueH1-vValueL1);

    return new Array ( vVClose );
    }

  • #2
    whatever
    Try the enclosed revision of your efs.
    In the return I selected to use the current value of the array but if you remove the [0] it will plot all the values in the array
    Alex

    PHP Code:
    var myDCHstudy1 null;

    function 
    preMain(){
        
    setStudyTitle("DCH ROC");
        
    setCursorLabelName("ROC",0);
        
    setDefaultBarFgColor(Color.red,0);
        
    setPriceStudy(false);
        
        
        var 
    fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    fp1.setName("DCH Length");
        
    fp1.setDefault(4);
        
    fp1.setLowerLimit(1);
        
        var 
    fp2 = new FunctionParameter("Lgth"FunctionParameter.NUMBER);
        
    fp2.setName("Close Length");
        
    fp2.setDefault(8);
        
    fp2.setLowerLimit(1);
        
    }

    function 
    main(LengthLgth){

        var 
    vVClose getValue("Close"0, -Lgth);
        
        if(
    myDCHstudy1==nullmyDCHstudy1 = new DonchianStudy(Length0);

        var 
    vValueH1 myDCHstudy1.getValue(DonchianStudy.UPPER);
        var 
    vValueL1 myDCHstudy1.getValue(DonchianStudy.LOWER);
        if (
    vValueH1 == null|| vValueL1 == null ) return; 


        
    //vSm = 0;
        //for(i = 0; i < Lgth+1; i++) {
        //     vSm += vC[i] - vC[i + 1];
        // }

        //vSm = vSm/(vValueH1-vValueL1);

        
    return vVClose[0];

    Comment


    • #3
      Doh!!!

      Got it. Thanks for the help.

      Comment

      Working...
      X