Announcement

Collapse
No announcement yet.

loading string return as an array

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

  • loading string return as an array

    How do I load this string return as a multi-element array?

    PHP Code:
    vRSI null;

    function 
    main() {
        
    // RSI
        
    if (vRSI == nullvRSI = new RSIStudy(8"Close");

        
    //var aryRSI = vRSI.getValue(RSIStudy.RSI, 0, -2);  // loads as a single variable, not an array
        
    var aryRSI = [vRSI.getValue(RSIStudy.RSI0, -2)];  // loads as a one element array
        
    debugPrint "aryRSI = " aryRSI "\n");
        
    debugPrint "\naryRSI[0] = " aryRSI[0] + "\n");



    like the following does:
    PHP Code:
    var aryClose getValue("Close"0, -2); // [0] is close(), [1] is close(-1), etc. 

    Thanks,
    -Ted.

  • #2
    Please explain in more detail

    Ted,

    What, exactly, are you trying to accomplish??

    Do you want to build an array of the RSI data??

    or do you want to build an array of the STRINGS??

    And how many of the data items are you trying to store?

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      B,
      I would like to populate an ARRAY just like this command does:
      var aryClose = getValue("Close", 0, -2);

      The 'getValue("Close", 0, -2)' command appears to automatically create an ARRAY 'aryClose' of the size returned. Size being extracted from the third parameter, -2, passed to getValue. I can access aryClose[0]. A debugPrint of aryClose shows all requested values.

      However, the 'var aryRSI = vRSI.getValue(RSIStudy.RSI, 0, -2);' command appears to return a STRING datatype instead of an ARRAY. I cannot access aryRSI[0], while a printDebug of aryRSI shows all requested values in comma delimited format. It seems that the proper values are returned, just not populated in an ARRAY datatype.

      Is there a way to get the RSI getValue command to autocreate and populate an ARRAY like the Close getValue command does?

      Thanks,
      -Ted.

      Comment


      • #4
        Ted,

        Make sure you are doing a check for a null return before you try to access any element of the array:


        var aryRSI = vRSI.getValue(RSIStudy.RSI, 0, -2);
        if (aryRSI == null)
        return;
        debugPrintln("aryRSI[0] = " aryRSI[0]);

        Garth
        Garth

        Comment


        • #5
          Ted,

          To clarify, RSI() will return null until there is enough data available to honor the requested length. If you don't do the null check you will get an error on execution when there isn't enough data to fulfill the RSI request.

          I'm guessing that is your problem, since you don't state why you can't access it (ie: what error you might be seeing).

          Garth
          Garth

          Comment


          • #6
            Garth,
            That did it.
            (What a forehead slapper!)

            This EFS was just a test to resolve my issue. The error was 'TypeError: aryRSI has no properties.'.

            Sorry for the hassle. I'll try to be clearer with the initial post next time.

            Thanks,
            -Ted.

            for posterity... the resolution was:
            PHP Code:
            var vBarCount   0;
            var 
            vRSI null;

            var 
            fp01 = new FunctionParameter("vRSILength"FunctionParameter.NUMBER);
                
            fp01.setName("RSI Length");
                
            fp01.setDefault(8);  

            var 
            fp02 = new FunctionParameter("vRSISource"FunctionParameter.STRING);
                
            fp02.setName("RSISource");
                
            fp02.addOption("Close");
                
            fp02.addOption("High");
                
            fp02.addOption("Low");
                
            fp02.addOption("Open");
                
            fp02.addOption("HL/2");
                
            fp02.addOption("HLC/3");
                
            fp02.addOption("OHLC/4");
                
            fp02.setDefault("Close");

            var 
            fp03 = new FunctionParameter("vRSIHistoryLength"FunctionParameter.NUMBER);
                
            fp03.setName("RSI History Length");
                
            fp03.setUpperLimit(1);
                
            fp03.setDefault(2);  


            function 
            main(vRSILengthvRSISourcevRSIHistoryLength) {

                
            // BarCount
                
            if ( getBarState() == BARSTATE_NEWBAR vBarCount += 1;

                
            // RSI
                
            if (vRSI == nullvRSI = new RSIStudy(vRSILengthvRSISource);

                
            // Load an array of RSI history on each tick, when valid values are available
                
            if (vBarCount >= vRSILength vRSIHistoryLength) {
                    var 
            aryRSI vRSI.getValue(RSIStudy.RSI0, -vRSIHistoryLength);
                    
            // aryRSI[0] is current value, aryRSI[1] is last value, etc.
                    
            debugPrint "aryRSI = " aryRSI "\n");
                    
            debugPrint "\naryRSI[0] = " aryRSI[0] + "\n");
                }


            Comment

            Working...
            X