Announcement

Collapse
No announcement yet.

saving an array in Global Memory? How To?

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

  • saving an array in Global Memory? How To?

    Looking for some help with a thorny issue.

    Is it possible to create an array in global memory (as in setGlobalValue() ) populate it with data, reload the script and then reference the values set in global memory while the script reloads?

    Why would I want to do such nonsense? Basically to solve the problem of data syncronization between two data sets that are on the same timeframe but one dataset does not have a data record for each bar (specifically the "ES #F=2,1" & "$TRIN,1" placed on a RTH time template chart). The $TRIN dataset has numerous holes that I can fill if I can create a global array and then trigger a reload of the study and reference the "fixed" TRIN data in the global data array.

    If anyone can point me to a sample or docs that shows ...
    - How to create the array
    - How to add values to the array
    - How to retrieve values from the array

    I can take it from there as long as someone points me in the right direction.

    I'm pretty sure I can solve this problem using FileI/O but Global memory sounds like a better solution if it's possible.

    Thanks,
    Rick

  • #2
    Rick,

    Yes it can be done, here is a link to my fileshare area that has some array examples. I'll post something tomorrow about the setting ang getting of the global arrays. It is pretty straight forward, but I can't put anything together tonight. link

    Comment


    • #3
      Hello Rick,

      You can pass arrays to the global space with setGlobalValue(). Here's a code example that will demonstrate some of the basics. It's not a direct solution for the routine your attempting to code but it should help get you going. You might want to visit this link, which covers the core functionality of the Array Object.

      PHP Code:
      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("set/get global array ");
          
      setShowCursorLabel(false);
      }

      var 
      myArray = new Array(3);
      myArray[0] = 100;
      myArray[1] = 200;
      myArray[2] = 300;
      var 
      bDisplayed false;

      function 
      main() {
          if (
      getCurrentBarIndex() == -10) { // occurs during initial load
              
      setGlobalValue("DataArray"myArray);
          }
          
          if (
      getCurrentBarIndex() == && bDisplayed == false) {
              var 
      globalArray getGlobalValue("DataArray");
              if (
      globalArray != null) {
                  
      debugPrintln(globalArray);
                  
      debugPrintln("Array Length = " globalArray.length);
                  
      bDisplayed true;
              }
          }
          
          return;

      Here's an example of the formula results in the output window.

      Jason K.
      Project Manager
      eSignal - an Interactive Data company

      EFS KnowledgeBase
      JavaScript for EFS Video Series
      EFS Beginner Tutorial Series
      EFS Glossary
      Custom EFS Development Policy

      New User Orientation

      Comment

      Working...
      X