Announcement

Collapse
No announcement yet.

hhv

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

  • hhv

    just testing hhv but not getting expected results, can anyone advise?

    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

  • #2
    try:
    PHP Code:
    function main(){
        if(
    getBarState() == BARSTATE_NEWBAR){
            var 
    nh high(0);
            for(var 
    i=0i<20; ++i){
                if(
    high(-i) > nhnh high(-i);
            }
            var 
    sh hhv(20,high());
            var 
    ah highest(20,high());
            return new Array(
    nh,sh.getValue(0),ah.getValue(0));
        }

    All 3 (nh, sh, ah) return the same value. Also, hhv() returns the highest value of the applied series, in your case "high()".

    Wayne
    Last edited by waynecd; 01-29-2012, 06:08 AM.

    Comment


    • #3
      ok thanks Wayne, so all is working well with you? which version are you using?
      Paul Williams
      Strategy & Applications
      www.futurenets.co.uk

      Comment


      • #4
        today all is working ok for me too.
        Paul Williams
        Strategy & Applications
        www.futurenets.co.uk

        Comment


        • #5
          Wayne, that code you posted is okay so long as you realize that all those variables are not declared and initialized at the points in the code where you typed them in. They are all hoisted to the very top of the function and initialized to whatever the default is.

          This won't bite you until much later when your function(s) get longer / more complex and you use a variable declared like that *above* where you specifically assigned them. Then you'll wonder why the variable is null when you least expect it.

          This is the crazy world of Javascript, not a block-scoped variable declaration C/C++ one.

          Comment


          • #6
            Thanks Steve, I have heeded your advise in regular scripts, here I didn't as I coded it quickly. But you are right, even in samples it's best to do it right so those who might use it do so correctly.

            Wayne

            Comment

            Working...
            X