Announcement

Collapse
No announcement yet.

Stochastics WMA

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

  • Stochastics WMA

    Greetings,

    This script smooths the K and D lines using a weighted moving average. Although the ouptut is correct, I usually fall asleep waiting for it to load. Any suggestions on optimizing this script or any other alternatives would be greatly appreciated.

    TIA
    Attached Files

  • #2
    Hi,

    My first suggestion would be to use the Builtin study.
    See the bultin Formula reference doc Here


    Garth
    Garth

    Comment


    • #3
      Thanks for the reply. I replaced callFunction() with the built-in study but there was no improvement. Unfortunately, StochStudy only supports SMA smoothing so I still I have to do my own WMA calculation.
      Attached Files

      Comment


      • #4
        Sorry to hear that, I've had some very good luck with speed bumps converting some of my older formulas to use the builtin's.

        I just loaded this up to take a look at it...I bet you use a black background

        This wasn't so bad loading, it look 1280 ms to load it on my IBM daily (Daynamic 0:00-24:00). Not even time to get a cup, much less fill it with coffee. It does suck a fair amount of CPU, but again not outragous (In fact, it is number two on my list of formula's that eat up CPU on my charts right now - and that means I wouldn't run too many copies of this...my #1 CPU user I can only run on one chart). My old #2 (now #3), I can run on multiple charts no problem - and you land someplace close to exactly inbetween the two. Not sure why at this point, that will take some more playing...

        In order to determine all of this I had to test on 7.2 build 506, so there way be some difference there.

        This is on a 2.4GH P4 with 1GB Mem...so that might be another point of difference.
        Garth

        Comment


        • #5
          Hi again,

          Part of the problem is the multiple requests for redundant data that GetD makes. It makes nice clean code, but is inefficiant use of data calls.

          I made some mods to the formula, and it works much faster now (about 1/2 the time and 1/2 the CPU load). However it isn't as clean looking code (oh well).

          There is some small problem that I haven't debuged yet, in that the %D is very close to, but somewhat off from the %D in the original. If you don't mind the code looking like this, I can follow up a bit more and debug (or maybe you can figure it out at a glance...I suspect it has something to do with the loop counts).
          Attached Files
          Garth

          Comment


          • #6
            Hm, I'm not sure, but you guys may be able to get a little more performance out of this by not creating the StochStudy() object twice for each bar tick.

            Try moving the 'var raw_k = new StochStudy(...)' out of the individual function calls, and put it on the first line of your EFS.

            Comment


            • #7
              Gspiker,
              Thanks a lot. I was actually thinking along the same lines and rewrote the script. I store the K values in an array and iterate through it in GetD. Although past values are plotted correctly, current ticks mess up the D line. Also, the array will grow unneccesarily large. I like your method and will play around with it. Thanks again.

              DionLoy,
              You're absolutely right, if you know the length that you want to use. But if you want to change the length dynamically through "Edit Studies", the argument gets passed to main() (which gets called for every tick). I still don't understand why arguments that don't change for every tick (such as length,color etc.) aren't passed through premain().
              Attached Files

              Comment


              • #8
                I am kind of surprised that you were able to create the stoch object in a function and have it work - there are some known issues with trying to do this. However, I do have a work around for everyone (thanks to Matt G - who answered a question on how to do this a bit ago):

                Code:
                var raw_K = null;
                
                function main(){
                
                .
                Stuff here
                .
                .
                if (getBarState() == BARSTATE_ALLBARS){ // Should only execute once per symbol,interval
                   study = new StochStudy(nLength, 1, 1);
                }
                .
                .
                More stuff here 
                .
                .
                Garth

                Comment


                • #9
                  You were only missing one line of code: reset sum_K to 0. Cleaned it up a little and it works great! Thank you !!
                  Attached Files

                  Comment


                  • #10
                    I'd make one change...

                    Code:
                    var raw_K = null;
                    
                    function main(nLength){
                        if(nLength == null)
                            nLength=??;
                    
                        if(study == null)
                           study = new StochStudy(nLength, 1, 1);
                    
                    }
                    Matt Gundersen

                    Comment

                    Working...
                    X