Announcement

Collapse
No announcement yet.

Loading Variable names and values into an array for calculation.

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

  • Loading Variable names and values into an array for calculation.

    Hi,

    I would like to load a variable and it's value into an array so I can use a post function to round the values.

    The following is my non working attempt; it returns undefined:

    Thank you.

    /****/
    /**///global array to keep track of all bars in the chart
    var aVarList = new Array();
    var aAllVals = new Array(4);

    var bInit = false;
    var aFPArray = new Array();

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("MA C(inv())");
    var x=0;
    aFPArray[x] = new FunctionParameter( "vRndTo25", FunctionParameter.BOOLEAN);
    with( aFPArray[x++] ) {
    setName( "Round to 0,25" );
    setDefault( true );
    }
    }

    var vPP = 1.1678;
    var MM = 2.398765;
    var MMM = 3.428765;
    var KE = 4.778765;

    function main(vRndTo25){
    if ( bInit == false ) {
    bInit = true;
    }
    aVarList.vPP = vPP
    aVarList.MM = MM
    aVarList.MMM = MMM
    aVarList.KE = KE
    vLen = aVarList.length;

    for (i = 0;i < vLen; i++){

    if (!vRndTo25){
    aVarList[i] = rnd(aVarList[i],2);
    }else if (vRndTo25){
    aVarList[i] = rnd25(aVarList[i]);
    }
    //debugPrintln(vPP, "vPP = ","\n",MM,"MM = ","\n",MMM,"MMM = ","\n",KE,"KE = ");
    }
    //debugPrintln(vPP, "vPP = ","\n",MM,"MM = ","\n",MMM,"MMM = ","\n",KE,"KE = ");
    debugPrintln(aVarList[0], "vPP = ","\n",aVarList[1],"MM = ","\n",aVarList[2],"MMM = ","\n",aVarList[3],"KE = ");
    }


    //ROUNDING FUNCTION
    function rnd(value, N) { //N = round to N # of digits
    var n;
    var mult=1;
    for(n=0;n<N;n++) mult*=10;
    value*=mult;
    return Math.round( value,N)/mult;
    }
    function rnd25(yValue){ // Round to nearest 0.25
    if(yValue%0.25<0.125)
    y=yValue-yValue%0.25
    else
    y=(yValue-yValue%0.25+0.25)

    return y;
    }

    /****/
    Last edited by waynecd; 04-08-2008, 03:50 PM.

  • #2
    Re: Loading Variable names and values into an array for calculation.

    waynecd
    See my reply in this post on the same topic
    Alex


    Originally posted by waynecd
    Hi,

    I would like to load a variable and it's value into an array so I can use a post function to round the values.

    The following is my non working attempt; it returns undefined:

    Thank you.

    /****/
    /**///global array to keep track of all bars in the chart
    var aVarList = new Array();
    var aAllVals = new Array(4);

    var bInit = false;
    var aFPArray = new Array();

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("MA C(inv())");
    var x=0;
    aFPArray[x] = new FunctionParameter( "vRndTo25", FunctionParameter.BOOLEAN);
    with( aFPArray[x++] ) {
    setName( "Round to 0,25" );
    setDefault( true );
    }
    }

    var vPP = 1.1678;
    var MM = 2.398765;
    var MMM = 3.428765;
    var KE = 4.778765;

    function main(vRndTo25){
    if ( bInit == false ) {
    bInit = true;
    }
    aVarList.vPP = vPP
    aVarList.MM = MM
    aVarList.MMM = MMM
    aVarList.KE = KE
    vLen = aVarList.length;

    for (i = 0;i < vLen; i++){

    if (!vRndTo25){
    aVarList[i] = rnd(aVarList[i],2);
    }else if (vRndTo25){
    aVarList[i] = rnd25(aVarList[i]);
    }
    //debugPrintln(vPP, "vPP = ","\n",MM,"MM = ","\n",MMM,"MMM = ","\n",KE,"KE = ");
    }
    //debugPrintln(vPP, "vPP = ","\n",MM,"MM = ","\n",MMM,"MMM = ","\n",KE,"KE = ");
    debugPrintln(aVarList[0], "vPP = ","\n",aVarList[1],"MM = ","\n",aVarList[2],"MMM = ","\n",aVarList[3],"KE = ");
    }


    //ROUNDING FUNCTION
    function rnd(value, N) { //N = round to N # of digits
    var n;
    var mult=1;
    for(n=0;n<N;n++) mult*=10;
    value*=mult;
    return Math.round( value,N)/mult;
    }
    function rnd25(yValue){ // Round to nearest 0.25
    if(yValue%0.25<0.125)
    y=yValue-yValue%0.25
    else
    y=(yValue-yValue%0.25+0.25)

    return y;
    }

    /****/

    Comment


    • #3
      Alex,

      Thanks again.
      Last edited by waynecd; 04-08-2008, 10:28 PM.

      Comment


      • #4
        waynecd
        My pleasure
        Alex


        Originally posted by waynecd
        Alex,

        Thanks again.

        Comment

        Working...
        X