Announcement

Collapse
No announcement yet.

stochastic sorting...

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

  • stochastic sorting...

    hi guys, im wondering if you could tell me why this sample code doesnt work:

    var stochastic = new StochStudy(14, 3, 3);
    var stocharray;

    stocharray = stochastic.getValue(StochStudy.FAST, 0, -5);
    stocharray.sort(); <- this is the error: "stocharray has no properties"

    what im trying to do is take the last 5 fast values, put em in an array and sort that array so i easily can get the highest / lowest "stochastic fast" values cause i need em in an calculation. i hope "stochastic fast" means the fast line not stochastic indicator fast version...

    would be glad if you guys could help me out!

  • #2
    If I wanted the hi/lo of the stoch array, I would look at java command Math.max or Math.min

    or even

    for(i = 0; i < Length; i++) {
    if(i == 0) {
    hh = stochastic.getValue(StochStudy.FAST, 0, -i);
    } else {
    hh = Math.max(hh, stochastic.getValue(StochStudy.FAST, 0, -i);
    }
    }

    Comment


    • #3
      thanks for the help, i was hoping to use sort cause you need less code. then you use array[0] for min or array[lenght] for max value. but since it doesnt work its not a good solution but i will try yours. thanks!

      Comment


      • #4
        sorry, dude, now ive been here for quiet some time and tried some various versions of your code and neither work. remember ... getValue(xx, 0, -5) causes to return a array but when it compares in max it should only be a number but now its an array vs a number = error.

        i still cant understand why that sort function doesnt work. anyone else who got any ideas? heres anyway a sample code where i checked highs and bottoms ...

        var malong = getValue("High", 0, -20);
        var mashort = getValue("Low", 0, -20);

        malong.sort();
        mashort.sort();

        this code works all fine .. but ..

        var stochastic = new StochStudy(14, 3, 3);
        var stocharray;

        stocharray = stochastic.getValue(StochStudy.FAST, 0, -5);
        stocharray.sort(); <- this is the error: "stocharray has no properties"

        what does the error code mean? how come the first code works but not the second? any suggestions to solution would be appreciated

        Comment


        • #5
          If you want to see what is going on, try


          if(getBarState()==BARSTATE_NEWBAR)
          debugPrintln(stocharray )

          and compare to the values drawn on the chart.

          Perhaps the issue wil expose it self that way.

          Comment


          • #6
            ill try that, thanks for the tip. but ive now tried some output and:

            stocharray = stochastic.getValue(StochStudy.FAST, 0, -5);

            statement works. stocharray gets the right values (5 StochStudy.FAST values), but how can i manipulate stocharray? it seems like i cant use it like an array. what i want to do is to get the highest or lowest value from stocharray. my guess is that stocharray becomes a pointer. but do you know .. if my point is correct .. if theres anyway i can copy these values returned from the studygetValue into an array not a pointer to the values.

            Comment


            • #7
              chris1
              Put a null check after defining the variable

              var stocharray = stochastic.getValue(StochStudy.FAST, 0, -5);
              if(stocharray == null)
              return;
              stocharray.sort();
              debugPrintln(stocharray);


              and you should no longer get any errors
              Alex

              Comment


              • #8
                thanks alexis for the help. but ive now solved it but in another way...

                Comment

                Working...
                X