Announcement

Collapse
No announcement yet.

Instructional efs

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

  • Instructional efs

    I was putting together a function tonight and realized that it may demonstrate concepts to other efs users. The efs involves a number of relatively easy, and some not so easy concepts. The first copy attached to this post is a working efs laced with trace steps (a debug utility I put together) which record the output of various steps (with associated step number) to a file. In this case, the file will be written to the formula output directory (unless modified from the default, it will be C:\Program Files\eSignal\FormulaOutput) and is named Trace find hi.txt. The output file contains the variable values throughout execution of the efs.

    The code populates an array in the getBarState() == BARSTATE_ALLBARS section which is true once during initial load of the efs. It then calls a function called find_hi which processes the array to find the high values of the array. Here is where it differs slightly from other pivot code (and is why I wrote it). If there are multiple highs, it identifies them, calculates the average bar value, and returns the average bar and the high.

    After you run the efs, the file it writes can be opened up and the variable values can be seen throughout the execution of the code. One and 2 dimension arrays are used, data is passed to a function, if statements, while loops and other manipulations are performed. An interesting phenomina regarding the use of variables and populating arrays can be seen by commenting out line 79.

    Each time the efs is run, the file is overwritten, so I would encourage the modification of the array values in lines 24 to 31, and re-running the efs to see how execution order is changed. If desired change other lines to see what changes (and don't forget line 79).

    I will make another post after this one. This will include the same efs without all the trace statements. That will be much more readable and probably should be used when reviewing the steps of the efs versus the file output.

    For those of you wondering, putting all these trace statements in my code is how I normally develope code which has so many twists and turns in it (and does not work right the first time). I take them out when I have verified it functions correctly.
    Attached Files

  • #2
    Here is the copy of the efs without all the trace statements. It is much more readable. It still outputs several lines to to a file entitled Trace find hi without trace.txt but that is to verify the results are the same.
    Attached Files

    Comment


    • #3
      Thanks Steve, great work as always.
      Excellent book on JavaScript for beginners

      Comment


      • #4
        Followup to trace efs

        I have been using the trace function for a while since I "rediscovered" the debugging tool of writing to files. Along the way I have cycled between making it more and less complex.

        Several associates (Alex, Roger and Chris) have provided me invaluable feedback, and with their help, I believe the current version is a good compromise between complexity and simplicity.

        For those unfamiliar, the intent is to have a portable section of code that can be copied into any efs without modification for use as a debugging tool. The section must be located outside the main and preMain sections.

        I am attaching a copy of a sample efs I have put together as part of the development process. This efs is stand alone and can be run by itself for demo purposes. I will also post the code.



        The "portable" section is between these lines

        //########### trace section required to be copied complete ##############

        Over the next several days, I will generate some additional posts to discuss some of the "features" of the function and which show how this can be applied to a sample efs.

        Two features are new.

        1. I have added a line that prints everything you send the trace function to the formula output window. This will minimize keystrokes. This should be commented out if extensive troubleshooting is required, but is handy if minor troubleshooting is required.

        2. I have added a button to the screen. By clicking on this button, notepad (or default editor) will open up the trace.txt file without you having to track the file down (extremely handy).



        PHP Code:
        /***********************************************
        Steve Hare © January 2004                          
        Use and/or modify this code freely. If you redistribute it
        please include this and/or any other comment blocks and a 
        description of any changes you make.                      
        ***************************************************/
        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        The purpose of this efs is to record the data from an efs wherever you choose to place "trace()" .The data 
        must be within the parenthesis.  Care should be taken, as too much data can be overwhelming.  Depending
        on how your code is written, and how much branching is used, the order of the recorded information may vary.
        Therefore, always put the line numbers or otherwise label to assist in helping understand where the data being recorded is from. The
        recorded data is saved in the default formula output directory, modify filename of the trace output file as required
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

        /*=============================================
        Fix History:
        1.0.0  -  1/30/2003 -    Initial Release
        1.0.1  -  2/6/2004 -     Revised steps to flush the variables in the trace function
        1.0.2  -  2/7/2004 -     Revised minor typo, changed order of trace commands, output more readable
        1.1.0  -  2/17/2004 -     Decreased number of required sections to be added to code, marked them with # signs
                                  does not create a file unless you are using functionallity
        1.2.0 -  7/6/2004      Simplified function to just one section of code to be copied into your efs
                                  Added option to also output with debugPrintln to formula output window
                                  Added option to use a button to open the text file
        =============================================*/

        //--------support variables ---------
        var barcount 0;

        function 
        preMain() { 
        setShowCursorLabel(false);
        setPriceStudy(true);
          
        trace("33: clock time = "+(new Date().getHours()*100+new Date().getMinutes()+new Date().getSeconds()/100));
        }

        function 
        main(){

          if (
        getCurrentBarIndex()<-10)return;// step here is to prevent the code from taking forever to load
          
        if (getBarState() == BARSTATE_NEWBAR) {//runs portion of code every bar     
            
        barcount++;

            
        trace("42: barcount = "+barcount);
            
            
        trace("44: getCurrentBarIndex() = "+getCurrentBarIndex());
                
            
        trace("46:"+open(0));
              
            var 
        sTradeStatus 0;
            
        trace("49: sTs = "+sTradeStatus);// output text and variable
            
            
        trace("51: getSymbol() = "+getSymbol()); 
            
        trace("52: getInterval() = "+getInterval()); 
            
            
        trace("54: bar time = "+(getHour(0)*100+getMinute(0)+getSecond(0)/100)); 
            
            
        // note ==> the next step is computationally intensive, put here for demo purposes only 
            
        trace("57: clock time = "+(new Date().getHours()*100+new Date().getMinutes()+new Date().getSeconds()/100)); 
          }

        }

        //########### trace section required to be copied complete ##############
        var traceon true;// previous tracefile is overwritten if this is true
        //var traceon = false;// previous tracefile is added to if this is false
        var nStudy "Trace.txt";// -  name to be used to name tracefile and button
        var  tracefile = new File(nStudy);
        function 
        trace(data1){
          
        debugPrintln(data1);//comment this line out if you do not want the output echoed to the formula output window
          
        if (traceon){//first use is true, overwrites previous trace file
            
        traceon false;
            
        tracefile.open("wt+");tracefile.close();//opens and overwrites previous file
          
        }
          
        tracefile.open("at+");
          
        tracefile.writeln(data1);
          
        tracefile.close();
          
        debugPrintln (trace.caller.name);
          if ( 
        trace.caller.name == "main" )
            if (
        trace.caller.name!="preMain" && trace.caller.name!="postMain")tButton();//call to the button that allows opening text file
        }

        function 
        tButton(){
        drawTextAbsolute(1020, (" click here to see the trace file " "@URL=C:\/Program\ Files\/eSignal\/FormulaOutput\/"+nStudy),  Color.rednullText.RELATIVETOLEFT Text.RELATIVETOBOTTOM|Text.FRAME"Comic Sans MS"13,"test0");
        }
        //########## section required to be copied complete ################ 
        Attached Files
        Last edited by ; 07-06-2004, 04:15 PM.

        Comment


        • #5
          thanks for the great script steve.

          I am trying to learn EFS and I have some questions.

          I never saw the "FUNCTION.caller.name" anywhere else and I can not find it in the help files. I wonder if there are others as well and is there any documentation where I can find info about these properties?

          Another thing is the URL= command. Is there anyway that I can invoke a URL=command without clicking a button? (like opening the text file when 50 lines are written to it etc)

          thanks again,

          Comment


          • #6
            plucky,

            Thanks for the kind words, http://docs.sun.com/source/816-6410-10/function.htm this link has info on the .caller.name property, although it refers to arguments.caller.name.

            Chris Kryza had helped me on that one, he had remembered it from an article he had read a while back. Try looking up "Javascript caller callee" in google or another search engine. Since it is part of the Javascript language, it will probably not go into the efs help file (plus it's usefulness is limited).

            Regarding the URL = command, that is the only way to invoke that method. Chris has a method in this link that you could use as an alternative means. http://share.esignal.com/groupconten...es&groupid=114.

            Personally, instead of trying to get that to work, I would just ensure your formula output window was opened and you have the line with debugPrintln enabled in the trace function. That way, everything that you send to trace will be mirrored in the output window.

            Regards,

            Comment

            Working...
            X