Announcement

Collapse
No announcement yet.

Returning Select Data Values from an Array

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

  • Returning Select Data Values from an Array

    What is the best way to return only selected elements from an array (not the entire array)? (When returning only selected individual elements, the correct color, line-type, etc. characteristics (0, 1, 2, indexing) in preMain must remain associated with each element returned from the array.) For example, for the array:

    var vArray = new Array(v0, v1, v2, v3, v4, v5, v6, v7);

    1) To display only certain array elements on a chart, for example only v0, v1, v4 and v6, what is the best way to express that in code? ( return <what?>)

    2) If for each variable, an "if (vX == null) return;" statement exists;

    var v0 = <something>
    if (v0 == null)
    return;

    Then is the following an acceptable way to return only certain elements in an array?

    return new Array(v0, v1, null, null, v4, null, v6, null);

    ("null" is used to return nothing for v2, v3, v5, and v7 while acting as place-holder in the array to keep correct line color, etc. characteristics associated with v0, v1, v4 and v6 which are displayed on the chart)

    Thanks.
    Last edited by Lancer; 12-14-2004, 05:34 PM.

  • #2
    Hello Lancer,

    You've got the right idea. Passing null values is one solution that will work. What I typically do in this case is convert the values I don't want to plot on the chart to strings. Strings data types will not appear on the chart, but it allows the string of the number to be included in the cursor window so it can still be referenced visually as needed. To convert to a string I use the .toFixed(2) method. Try the following.

    PHP Code:
    return new Array(v0v1v2.toFixed(2), v3.toFixed(2), v4v5.toFixed(2), v6v7.toFixed(2)); 
    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


    • #3
      Hi Lancer,

      Are you trying to return the values to the chart?

      for example

      var vArray = new Array(v0, v1, v2, v3, v4, v5, v6, v7);
      return vArray;

      would return all 8 values to the chart

      return new Array(vArray[0],vArray[1],vArray[4],vArray[6]);

      would return those 4 elements to the chart.


      return new Array(vArray[0],vArray[1],""+vArray[2],""+vArray[3],vArray[4],""+vArray[5],vArray[6],""+vArray[7]);


      would return the same 4 elements to the chart and the others to the cursor window (since I made them test values by adding ""+).

      Comment


      • #4
        Thanks Jason and Steve. Yes, array elements are returned to display as lines on a chart. I just tried that "return new Array(vArray[0],vArray[1],vArray[4],vArray[6]);" method, and it does not maintain proper indexing . . . lines display in the wrong color and style. There's also a new wrinkle regarding line display; the selected array elements displaying as lines on the chart (lines which are supposed to start and stop at points per current bar conditions), now want to connect by spanning (straight line) from the stop endpoint to the start endpoint many bars later. If the chart is scrolled forward or back to where one or the other stop/start endpoints is not visible, then the spanning line disappears. Any ideas on why that occurs and how to fix it?

        Next, will try the other mentioned array solutions.

        Comment


        • #5
          I think I understand now what you are trying to do. Here is an excerpt from one of my efs's where I used arrays to define colors and sizes, what I did to maintain sequencing is just align the different array values in the premain section, notice I did not use the [0] and [1] array elements for the chart.


          PHP Code:
              setPriceStudy(true);
              
          setShowTitleParameters(false);
              
          setComputeOnClose();
              
          setStudyTitle(v[12]);
              
          setShowCursorLabel(true);
              
          setCursorLabelName(v[2], 0);
            
          setCursorLabelName(v[3], 1);
            
          setCursorLabelName(v[4], 2);
            
          setCursorLabelName(v[5], 3);
            
          setCursorLabelName("U_Trend.bars_out"4);
            
          setCursorLabelName("D_Trend.bars_out"5);

              
          setDefaultBarFgColor(c[2], 0);
            
          setDefaultBarFgColor(c[3], 1);
            
          setDefaultBarFgColor(c[4], 2);
            
          setDefaultBarFgColor(c[5], 3);

              
          setDefaultBarThickness(2,0);
              
          setDefaultBarThickness(1,1);
              
          setDefaultBarThickness(2,2);
              
          setDefaultBarThickness(1,3); 

          Comment


          • #6
            OK, tried the ".toFixed(2)" string method and that works. It produces results same as my "null" approach except that ".toFixed(2)" displays array element values in the cursor window, as Jason said. Wasn't sure how to apply information in your last reply Steve, so I didn't try that one.

            I am still getting that end-point to start-point line spanning behavior which is very curious. (lines display properly per conditions between start and end points, but when the next start point triggers (and only as long as the last end point is visible on the chart), a straight line appears spanning from the last end point to the new start point.) Anyone have any ideas on that? I've never seen that before... only now when displaying lines with these select-element arrays.

            Comment


            • #7
              I am still getting that end-point to start-point line spanning behavior which is very curious.
              Every value you return to the chart is connected, so they have to be continuous. If you stop returning values at any point, I believe they will be enterpreted as zero and you will see the "spanning behavior". To display data that has start and end points, you must draw those points, e.g. using drawLineRelative.

              You can see where I had to draw lines in this image

              Comment


              • #8
                The plotted lines that are designed to start/end (per conditions) are not straight lines.... they're moving averages, variable trigger levels, and other similar non-linear products based on price data. The only straight line is the unwanted span line which connects the last visible end point with the next visible start point. It is possible that drawLineRelative can somehow be used to display a moving average line?

                Using that curving orange line in your attached image for example, say you have a condition that starts display of that orange line when <Condition> == True, and ends display of the line when <Condition> == False..... how could drawLineRelative be used to display the orange line?

                Comment


                • #9
                  You have to plot a line from one point to the next using a for loop

                  Comment


                  • #10
                    New thread for question regarding lines:

                    Comment

                    Working...
                    X