Announcement

Collapse
No announcement yet.

Strategy.isShort() returning erroneous value?

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

  • #16
    Brad,

    Thank you. That took care of my problem.

    As far as your second post is concerned, I fully agree. The only way I know to get around this is to use
    getMostRecentAsk()
    or
    getMostRecentBid(),
    especially for intra-bar values.

    Any suggestions, advice, or thoughts you might have would be greatly appreciated.

    Comment


    • #17
      Brad,

      Thank you. That took care of my problem.

      As far as your second post is concerned, I fully agree. The only way I know to get around this is to use
      getMostRecentAsk()
      or
      getMostRecentBid(),
      especially for intra-bar values.

      Any suggestions, advice, or leading questions/thoughts you might have concerning this would be greatly appreciated. I am finding that, and more so, acquiring the actual value at which I have entered the trade, to be 2 of the most difficult problems I am having.

      Thanks again,
      Greg

      Comment


      • #18
        Hello ebr,

        As I stated previously, I'm not seeing a bug related to the return values of Strategy.isLong() and Strategy.isShort().

        If (Strategy.isLong())

        is interchangeable with

        if (Strategy.isLong() == true)

        Are you able to consistently reproduce the problem you were having? If so, please attach a copy of your formula so I can test it directly. Also, please let me know what build number you are currently using.
        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


        • #19
          I thought this was something you guys already knew about - as it was someone in here who pointed it out to me.

          I can't say that I could re-produce it consistently but my backtest did consistently have problems before I changed the code and do not now. It would consistently have problems, but they would not be the same ones every time. That is, it seemed that the isShort test was randomly producing invalid results. It did not fail all the time, just some of the time.

          The person who pointed it out to me said it had to do with bringing up the "edit studies" dialog and changing something (which happens every time you run a backtest). They said that in this instance, boolean values were transformed to strings.

          That's why the code change works. Because, if all booleans are turned to strings the code if (Strategy.isShort()) will always be true (as the string is interpreted as a true value by being non-zero i'm assuming) but the code if (Strategy.isShort() == true) will alwas evaluate properly because both booleans are transformed and so the evaluation works (by comparing the two strings).

          At least, that's how it makes sense to me...

          Comment


          • #20
            Hello ebr,

            I understand the problem you were having now. Let me try to clear some things up for you. The Strategy.isLong() method was probably not the source of your formulas problem. You most likely were using a user-defined parameter that was set up as a boolean variable with the FunctionParameter class. For example sake, let's call it bTrigger. If you were using bTrigger as part of a condition to trigger a trade, the formula would evaluate if (bTrigger) to the boolean value of true, if that was the default set in the FunctionParameter dialog. When you first apply your formula, everything was woking fine, I'm assuming. If you then went to Edit Studies and changed the bTrigger variable to true and clicked OK, now the value of bTrigger being sent to your formula is a string value of "true." Therefore, if (bTrigger) no longer evaluates to true. It evaluates to false because the string, "true" does not equal the boolean value of true. The solution is to change your if statement to if (bTrigger == true || bTrigger == "true). But only if you use the boolean type of the FunctionParameter class.

            The return value of Strategy.isLong() is not affected by changes made to user-defined parameters via Edit Studies. It will always return a boolean value of true or false.

            We do know about this bug related to the boolean FunctionParameter type. Until it can be fixed, it can be avoided by doing the following. Instead of using the boolean type, use the string type and create two options, "T" and "F." Then, in your formula code, check for the "T" and "F" strings.

            PHP Code:
            function preMain() {
                
            setStudyTitle("Test");
                
                var 
            fp1 = new FunctionParameter("bTrigger"FunctionParameter.STRING);
                
            fp1.setName("The Trigger");
                
            fp1.addOption("T");
                
            fp1.addOption("F");
                
            fp1.setDefault("T");
            }

            function 
            main(bTrigger) {
                if (
            bTrigger == "T") {
                    
            debugPrintln("bTrigger is " bTrigger);
                }
                if (
            bTrigger == "F") {
                    
            debugPrintln("bTrigger is " bTrigger);
                }

            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


            • #21
              Unfortunately, I'm on the road and don't have access to the formulas in question. However, while I did have a boolean function parameter - it had nothing to do with this logic (it dealt with whether or not to write stats to my own file).

              Near the end of debugging this problem, I put in debug lines and confirmed that the Strategy.isLong/isShort functions were returning incorrect values - but only in some instances. It was not consistent except in that, over a sample period of at least 30 or more days (against a 5min chart so hundreds of iterations) it would happen at least once.

              The only thing I changed was the test logic to those function calls and it started working correctly all the time. So, I'm not sure what was really going on but I did work around it.

              Comment

              Working...
              X