Announcement

Collapse
No announcement yet.

Help with an array

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

  • Help with an array

    The following script uses BARSTATE_NEWBAR and uses it to store previous values for later calculations. I would like to change to ALLBARS and use an array to store the old value. I have looked at pop and upshift but I am not sure how to set up the array or where to place all the elements of the array in the script.

    Thanks for your help
    Attached Files

  • #2
    whatever
    FWIW you may want to use this revised version of rvi.efs that will plot correctly also in real time.
    Alex
    Attached Files

    Comment


    • #3
      Thank you Alexis for the new file I still however would like to learn how to do an array instead of what is being used in the script. I use Jurik and to call values the way the script does uses a lot of computing power. I believe using an array would lessen the load. I have already read several threads on arrays but I'm still not catching on.

      If someone could recommend a script with arrays were the oldest value is discarded an the newest loaded I would appreciate it.

      Comment


      • #4
        here are a couple of functions that I use to initialize arrays


        PHP Code:
        function Initialize_1X_Array(n1){//initialize 1 dim array
            
        var i;    var newArray = new Array();
            if (
        n1 == null){n1 =2;}
            for (
        0;n1i++){newArray[i] = 0;}
            return 
        newArray;
        }
            
        function 
        Initialize_2X_Array(n1,n2){//initialize 2 dim array
            
        var i; var j;var newArray = new Array;
            if (
        n1 == null){n1 =2;}if (n2 == null){n2 =2;}
            for (
        i=0;i<n1i++){newArray[i] =  new Array();
                for (
        j=0;j<n2j++){newArray[i][j]=0;
            }}
            return 
        newArray;

        If you wanted to initialize a 1 dimensional array, 10 records long, call this function. Assuming it is a global, define the array before preMain()

        nArray;

        Then in premain, call the function

        nArray = Initialize_1X_Array(10);

        you now have a global array, 10 records long. As long as you add and subtract a variable from it every time

        nArray.pop(); nArray.unshift(close());

        , it will always stay 10 records long. Extra pops will reduce the length.

        The same applies to a 2 dimensional array.

        Brad Matheny showed me a similar function he uses to create global objects.
        Define this as a global above preMain

        var SampleArray = new Array();

        when you have the data to add to the array

        fPopObjArray(10, 10, 10, 10);

        and here is your function which is called

        function fPopObjArray(Input1, Input2, Input3, Input4)
        {
        var vArrayObj = new Object;
        vArrayObj.aItem1 = Input1;
        vArrayObj.aItem2 = Input2;
        vArrayObj.aItem3 = Input3;
        vArrayObj.aItem4 = Input4;

        SampleArray.pop();SampleArray.push(vArrayObj);

        }


        There are a number of ways to handle arrays, here is a link to a demonstration file in my fileshare area "Functions" http://share.esignal.com/download.js...ing Arrays.efs

        Comment


        • #5
          Here is my attempt but it does not work. It draws nothing. Could someone please tell me what is wrong.

          Thanks
          Attached Files

          Comment


          • #6
            I'll look at, but I don't have the Jurik indicators, so unless it is something obvious...

            Comment


            • #7
              I looked at what you have, I'm assuming this is just an attempt to see if you can get the arrays to work, since in this simple application, there are much easier alternatives.

              I would suggest that to aid in your troubleshooting try either using a number of debugPrintln statements, or alternatively use the trace() application in the "Function" file share area under debug tools

              Comment

              Working...
              X