Announcement

Collapse
No announcement yet.

Array Problem

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

  • Array Problem

    Gentlemen,

    Would you kindly take a look at the following code and see what is wrong with it? It gives nothing ... actually the debugprintlns don't even print...confused ....

    var MAVt = new Array();
    var MAVt1 =new Array();
    var MAVt_1 = 0;
    var MAVt1_1 = 0;
    var nLength=7;var nSmoothing=4;var nSmoothings=10;var aCntr=3;
    //
    function preMain() {
    setStudyTitle("zTest");
    setCursorLabelName("zTest");
    setPriceStudy(false);
    }

    function main() {
    var percentK; var Mt1=0;var Mt2=0;
    var ll = 0, hh = 0;
    var sum = 0;
    var vHigh = getValue("High", 0, -nLength);
    var vLow = getValue("Low", 0, -nLength);
    var temp = 0; tmp1=0;

    if(vHigh == null || vLow == null)
    return;


    for(j = 0; j < nLength; j++) {
    if(j == 0) {
    ll = vLow[j];
    hh = vHigh[j];
    } else {
    hh = Math.max(hh, vHigh[j]);
    ll = Math.min(ll, vLow[j]);
    }
    }
    percentK = ((close() - ll) / (hh - ll)) * 100;
    if (isNaN(percentK) == false) Mt1 = MAVt_1 + (percentK - MAVt_1) / nSmoothing;
    if (MAVt.length<aCntr) tmp1=MAVt.unshift(Mt1);
    else {tmp1=MAVt.pop(); tmp1=MAVt.unshift(Mt1);}
    if (getBarState() == BARSTATE_NEWBAR) MAVt_1 = MAVt(0);
    if (isNaN(percentK) == false) Mt2 = MAVt1_1 + (MAVt(0) - MAVt1_1) / nSmoothings;
    if (MAVt1.length<aCntr) tmp1=MAVt1.unshift(Mt2);
    else {tmp1=MAVt1.pop(); tmp1=MAVt1.unshift(Mt2);}
    if (getBarState() == BARSTATE_NEWBAR) MAVt1_1 = MAVt1(0);
    var pK0=MAVt(0);
    var pK1=MAVt(1);
    var pK2=MAVt(2);
    var pD0=MAVt1(0);
    var pD1=MAVt1(1);
    var pD2=MAVt1(2);
    debugPrintln("in Main zTest");
    debugPrintln("pk1 pd1: "+pK1+" "+pD1);
    if (pK0>pD0){
    setBarFgColor(Color.black);
    setBarBgColor(Color.blue);
    }else if (pK0>pD0) {
    setBarFgColor(Color.black);
    setBarBgColor(Color.red);
    }else {
    setBarFgColor(Color.black);
    setBarBgColor(Color.yellow);
    }
    }


    ...the feeble mind

  • #2
    Try this...

    I don't have time to help you right now, but what I do is put debugPrintln() statements at various points in my code to find out where it is "hanging".

    I would suggest starting near the top and moving the debug line lower and lower till you identify the problem area. Then, you can fix the code and make sure it all works properly.

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Z11,

      the arrays should have square brackets is one problem

      MAVt(0); ==> MAVt[0];
      MAVt1(0); ==> MAVt1[0];

      liberal use of debug statements would help as well
      Last edited by Guest; 11-05-2004, 06:36 PM.

      Comment


      • #4
        Steve, what can I say...thanks...the brackets did it!

        the feeble mind...(maybe a bit tired from all night of FX trading)

        Comment

        Working...
        X