Announcement

Collapse
No announcement yet.

debugPrint Parameters and Syntax

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • debugPrint Parameters and Syntax

    Researching debugPrint and debugPrintln, I found no description of parameters and syntax. I also found no description of usage (how used, how/when output is generated, etc.). Could someone provide some explanation? (or links to explanation, if it exists)

    For example:
    What's the function of the quotation marks " " and how is it used?
    What's the function of the plus sign "+" and how is it used?
    What's the function of the semi-colon ";" and how is it used?
    What's the function of the "\n" and how is it used?
    Does debug need to be in the formula main section?
    Where should the debug line be placed with respect to other formula code?
    In what circumstance does debug need its own function?

    Here's a few debug code examples that I found. Maybe an explanation of these might be useful (both code and expected output):

    debugPrintln(vMAstudy);

    debugPrintln(vStudyA+" : "+vStudyB);

    debugPrintln("index: " + getCurrentBarIndex() + " High: " + High + " Low: " + Low);

    debugPrintln((-t + getCurrentBarIndex()) + " " + aVarB[1][t] + " " + aVarB[0][t]);

    function p( a, b ) {
    debugPrint( a + ": " + b + "\n" );
    return;
    }

    Thanks in advance.

  • #2
    Hello Lancer,

    You can find some reference material on debugPrint(), debugPrintln() and debugClear() in the EFS Help Center & Library -> EFS Function Reference -> Utility Functions.

    The only difference between debugPrint() and debugPrintln() is that debugPrintln() adds a carriage return after each call so that you get a list of information down the output window. debugPrint() will just keep adding to the end of the line.

    The information that is passed to these functions appears in the Formula Output Window.

    debugClear() will clear out all the text in the output window. You can also right-click on the output window and clear the text manually.



    The parameters that you pass to these functions can be a string, number, array etc. I would try passing a study object to it however.

    A String is simply text surrounded by quotes. You can also add strings and variables together to create a larger more descriptive string. For example, debugPrintln(" the last price was " + close() ), would print out something like:

    the last price was 85.6875

    The ";" is an optional character that tells the JavaScript engine that it's reached the end of a line of code. If you use them it makes your code a little more efficient.

    The "\n" is just another way to add a carriage return. For example, debugPrint(" the last price was " + close() + "\n") would do the same thing as our example above.

    The debug statements can be used anywhere. Typically, I use the debugPrintln() within main() or the function I'm debugging. I'll usually put debugClear() just in front of main so that the output window will be cleared only when I reload the formula.

    The placement of the debug statements depends on the order of process for your code. Usually it will be placed right after the line of code that you are debugging. For example,

    PHP Code:
    var vNum .5;

    function 
    main() {
        var 
    close() * vNum;
        
    debugPrintln(" c = " c);
        return 
    c;

    If you placed the debug statement before "var c = close() * vNum;" you would get and error or a null value for c in the output window.

    Creating a function like your function p( a, b ) is handy if you have a bunch of places within your formula that you want to debug and don't want to retype the entire line each time. In this case all you would have to do is add the line; p( vVar1, vVar2); but it's not required or necessary. It's really a preference of the programmer.

    debugPrintln(vMAstudy);
    outputs: [object MAStudy]

    debugPrintln(vStudyA+" : "+vStudyB);
    if vStudyA = 10 and vStudyB = 20
    outputs: 10 : 20

    debugPrintln("index: " + getCurrentBarIndex() + " High: " + High + " Low: " + Low);
    if High = 85 and Low = 80
    outputs: index: 0 High: 85 Low: 80

    debugPrintln((-t + getCurrentBarIndex()) + " " + aVarB[1][t] + " " + aVarB[0][t]);
    if t = 1, aVarB[1][t] = 20 and aVarB[0][t] = 10
    outputs: -1 20 10

    Hope this helps. Let us know if you have any more questions.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason, thanks for the reply.

      You can find some reference material on debugPrint(), debugPrintln() and debugClear() in the EFS Help Center & Library -> EFS Function Reference -> Utility Functions.
      Looked there first. Not helpful on this topic at all.

      The information that is passed to these functions appears in the Formula Output Window.
      OK, got that. What is the procedure to output debug results to a file?

      The ";" is an optional character that tells the JavaScript engine that it's reached the end of a line of code. If you use them it makes your code a little more efficient.
      I was referring to the character within the debugPrint string parenthesis in the examples. Maybe it is a colon, not semi-colon. Hard to tell. What is the function of that character? (It appears to be a character to be returned literally rather than a character having a syntax or other function).

      debugPrintln(vMAstudy);
      So this outputs the value for the single variable "vMAstudy". Does debug print this value upon each trade (each cycle of the formula), or is it per bar period, or other?

      debugPrintln(vStudyA+" : "+vStudyB);
      In this one, why are the + symbols placed where they are? Are the + symbols separators?
      No spaces are needed between the variable and the +?
      Do the quotation marks cause the return of the contents, literally? That is, return the text exactly as shown between the quotes?

      debugPrintln("index: " + getCurrentBarIndex() + " High: " + High + " Low: " + Low);
      In this one, there is a space between the + symbol and the variable. That's apparently OK?

      debugPrintln((-t + getCurrentBarIndex()) + " " + aVarB[1][t] + " " + aVarB[0][t]);
      In this one, there is + " " +. What is the purpose of this? Is it to place a blank space between returned values? If it is to insert spaces, then for however many spaces you have between the " ", is that the spacing that will be returned?

      Thanks for the clarification.

      Comment


      • #4
        My pleasure Lancer. Good to see you diving in and learning more about JavaScript.

        Looked there first. Not helpful on this topic at all.
        The reference material assumes that you understand the basics of JavaScript, like how to build strings etc. If we tried to include everything in the reference materials, it would be the size of a book. It's only meant to be a quick reference. Once you gain a better grasp on the basics, the reference material will become easy to understand.

        OK, got that. What is the procedure to output debug results to a file?
        You need to use File I/O, which is also listed in the Help Center. You can find an example formula for this in the EFS Library -> Help Examples -> Write To File.

        I was referring to the character within the debugPrint string parenthesis in the examples. Maybe it is a colon, not semi-colon. Hard to tell. What is the function of that character? (It appears to be a character to be returned literally rather than a character having a syntax or other function).
        Yes, the " : " used in the string, vStudyA+" : "+vStudyB, has no function. It is simply a character being added to the string so that the result in the output will have the character " : " between the two numbers vStudyA and vStudyB. The plus symbol here is the operator that adds all these values and characters together to make a larger string. It doesn't mater if you include a space before or after the symbol. JavaScript is flexible that way. If vStudyA was set to a value of 25 and vStudyB was set to a value of 10 earlier in the formula, then the result that would appear in the output window would look like this:

        25 : 10

        So this outputs the value for the single variable "vMAstudy". Does debug print this value upon each trade (each cycle of the formula), or is it per bar period, or other?
        It will print the value to the output every time the formula executes. As long as the statement isn't inside some type of if statement that would prevent it's execution based some true/false condition. When you first apply the formula, one value per bar will be sent to the output window until you reach the bar index of zero. The formula executes only once per bar on the historical bars when you first apply a formula. Once you're at bar 0, or real time, then the formula executes on every trade, so you'll see a value printed to the output window on each trade.

        In this one, why are the + symbols placed where they are? Are the + symbols separators?
        No spaces are needed between the variable and the +?
        Do the quotation marks cause the return of the contents, literally? That is, return the text exactly as shown between the quotes?
        Correct. The quotation marks are used to create a string so that the contents within them are returned literally, or exactly as shown.

        In this one, there is + " " +. What is the purpose of this? Is it to place a blank space between returned values? If it is to insert spaces, then for however many spaces you have between the " ", is that the spacing that will be returned?
        This is adding a space into the string. Look at this example again:

        " : "
        Notice there is a space before and after the colon. If we used ":" instead, our example above would look like this:

        25:10


        The best way to learn more about the debugPrintln statement is to make some test formulas and experiment. You should create a new layout that just has a single advanced chart and a couple of EFS editors. Save your chart with a specific name while you don't have any formulas applied to it. Then go to the \eSignal\ directory, or wherever you saved the chart file to, and copy it to another folder on your PC outside of eSignal. Then, as you are experimenting with formula writing and you happen to resave your layout with formulas on your chart and subsequently make a change to one of the formulas that generates a crash, like an endless loop for example, all you will need to do to fix the situation is copy your backup file of the chart that wasn't running any formulas back into your \eSignal\ directory. That way, when you bring eSignal back up, the formula generating the error will not be running in the chart and generate the error again. There aren't too many scenarios that you need to be concerned with. As long as you follow this setup you'll easily be able to recover and fix the problem code.

        Hope this helps. Have fun.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X