Announcement

Collapse
No announcement yet.

Back values of calculated numbers

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

  • Back values of calculated numbers

    I am translating some of my TradeStation 2000i indicators to EFS Studies. I need to reference the values of calculated variables and pricing XX bars in the past. I thought I had found a method I could use but now can't find it again. Is there a way to do this?

  • #2
    HillTop
    You can do that with arrays.
    Click here for an extensive set of examples of arrays in efs courtesy of Steve Hare.
    Alex

    Comment


    • #3
      Another way of doing it is using the ref() function. For more information on this see the EFS Help Center & Library under EFS Functions->Data Access
      Alex

      Comment


      • #4
        I tried the array method using the .unshift and .pop tunctions but I get a Microsoft Visual C++ Runtime Library - Buffer overrun detected error and e-signal shuts down. To learn this method I made a very simple study. I used the debugPrintln to check to see if my arrays were initialized. I then added the following code
        to
        function main() {
        var price;
        bclose.pop;
        bclose.unshift(close());
        price = close();
        debugPrintln(bclose);

        When I add the code, I get the error

        Comment


        • #5
          HillTop,

          If you are pop'ing your array before you have anything in there, that could be a problem, however, to figure out exactly what the problem is, please post the the entire code.

          Assuming you defined it correctly, you could try checking the length before you start pop'ing.

          if (bclose.length>5){
          bclose.pop()
          }

          Comment


          • #6
            Not quite sure what the problems is, but this may help.

            var a_Close = new Array(5);
            var fPrice;

            function preMain()
            {
            ... your code
            }

            function main()
            {
            ... your code

            fPrice = close();
            a_Close.pop();
            a_Close.unshift(fPrice);
            debugPrintln("a_Close = " + a_Close);

            ... your code
            return;
            }

            Substitute whatever you want for variable names and the array size. If you make the array really big, you could run into problems. You must declare the array outside of main(). Otherwise you start with a brand new array on every tick. Also, the array must have a size. I'm not sure what happens with an array of no elements when you try to remove an element (pop);

            In general, you should avoid using pop, push, shift, and unshift unless you have a specific need for them. They are costly in cpu cycles. If you can accomplish what you want with an assignment inside of a for loop, that would be better.

            Comment


            • #7
              since I initialize the array and have used the debugprint to verify that I assume that the array is not empty. Here is the complete code.
              //{{Description
              //
              //
              //}}Description


              //{{Declarations

              var ibclose=6;
              bclose = new Array;
              varray = new Array;
              bhigh = new Array;
              //}}Declarations
              function backvalue(varray,ibar){
              var i;

              i=0
              do {
              varray[ibar-i]=varray[ibar-1-i];
              i+=1;

              } while (i<ibar);

              return varray;
              }
              function preMain() {
              /**
              * This function is called only once, before any of the bars are loaded.
              * Place any study or EFS configuration commands here.
              */
              //{{PreMain
              setPriceStudy(false);
              setStudyTitle("bclose");
              setStudyMin(0);
              setStudyMax(100);
              setCursorLabelName("bclose", 0);
              setCursorLabelName("OB", 1);
              setCursorLabelName("OS", 2);
              setDefaultBarStyle(PS_SOLID, 0);
              setDefaultBarStyle(PS_DASH, 1);
              setDefaultBarStyle(PS_DASH, 2);
              setDefaultBarFgColor(Color.magenta, 0);
              setDefaultBarFgColor(Color.red, 1);
              setDefaultBarFgColor(Color.blue, 2);
              setDefaultBarThickness(2, 0);
              setDefaultBarThickness(1, 1);
              setDefaultBarThickness(1, 2);
              setPlotType(PLOTTYPE_LINE, 0);
              setPlotType(PLOTTYPE_LINE, 1);
              setPlotType(PLOTTYPE_LINE, 2);
              var j;
              for(j=0;j<=ibclose;j++){
              bclose[j] = 0;
              bhigh[j] = 0;
              }
              //}}PreMain

              }

              function main() {
              /**
              * The main() function is called once per bar on all previous bars, once per
              * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
              * in your preMain(), it is also called on every tick.
              */
              var price;
              //backvalue(bclose,ibclose);
              //backvalue(bhigh,ibclose);
              //bclose[0]=close();
              bhigh[0]=high();
              bclose.pop;
              bclose.unshift(close());

              debugPrintln(bclose);
              //{{Return
              return new Array(close(),high(),price);
              //}}Return

              }

              function postMain() {
              /**
              * The postMain() function is called only once, when the EFS is no longer used for
              * the current symbol (ie, symbol change, chart closing, or application shutdown).
              */
              }

              //{{Actions
              //{{Action_1
              function onAction1() {
              vLastAlert = 1;
              }
              //}}Action

              //}}Actions

              Comment


              • #8
                Just looking at the first couple of lines, your array declarations have a syntax error.

                bclose = new Array


                should be

                var bclose = new Array();

                I went ahead and downloaded what you had and cleaned it up so I could figure out where you were going. Here it is with those steps put together to fill your two arrays.



                PHP Code:
                var ibclose=6;
                var 
                bclose = new Array();
                var 
                varray = new Array();
                var 
                bhigh = new Array(); 


                function 
                preMain() {
                    
                setPriceStudy(false);
                    
                setStudyTitle("bclose");
                    
                setStudyMin(0);
                    
                setStudyMax(100);
                    
                setCursorLabelName("bclose"0);
                    
                setCursorLabelName("OB"1);
                    
                setCursorLabelName("OS"2);
                    
                setDefaultBarStyle(PS_SOLID0);
                    
                setDefaultBarStyle(PS_DASH1);
                    
                setDefaultBarStyle(PS_DASH2);
                    
                setDefaultBarFgColor(Color.magenta0);
                    
                setDefaultBarFgColor(Color.red1);
                    
                setDefaultBarFgColor(Color.blue2);
                    
                setDefaultBarThickness(20);
                    
                setDefaultBarThickness(11);
                    
                setDefaultBarThickness(12);
                    
                setPlotType(PLOTTYPE_LINE0);
                    
                setPlotType(PLOTTYPE_LINE1);
                    
                setPlotType(PLOTTYPE_LINE2);
                    var 
                j;
                    for(
                j=0;j<=ibclose;j++){//zero fills arrays
                        
                bclose[j] = 0;
                        
                bhigh[j] = 0;
                    } 
                }

                function 
                main() {
                    
                    
                bclose.unshift(close());bclose.pop;
                    
                bhigh.unshift(high());bhigh.pop;
                    
                debugPrintln(bclose);
                    return new Array(
                close(),high());


                hope this helps

                Comment


                • #9
                  RE: Reply to post 'Back values of calculated numbers'

                  I tried the code with the same results. I have perfected a more direct =
                  way
                  of updating the arrays by using standard code. It seems to work.

                  -----Original Message-----
                  From: [email protected] [mailto:[email protected]]=20
                  Sent: Sunday, February 01, 2004 8:37 PM
                  To: [email protected]
                  Subject: Reply to post 'Back values of calculated numbers'

                  Hello HillTop,

                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                  Comment


                  • #10
                    If you don't mind, please post, I like to see and learn new or different ways of accomplishing things. This board is great, new ideas and methods are posted often, I enjoy very much.

                    TIA

                    Regards,

                    Comment

                    Working...
                    X