Announcement

Collapse
No announcement yet.

trades not behaving as anticipated

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

  • trades not behaving as anticipated

    Hi,

    I found that the trades are not behaving as I wanted it to. Could someone help please?

    Attache (and below is a test efs).

    PHP Code:
    var study = new MAStudy(400"Close"MAStudy.SIMPLE);

    var 
    barcount=0;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setColorPriceBars(true);
        }

    function 
    main() {

        if (
    year(0)==2007 && month(0)==&& day(0)==&& hour(0)==&& minute(0)==53)
        {
            
    debugPrintln(high(0)+" "+low(0));
            
    barcount=getCurrentBarCount();
            
    Strategy.doLong("Re-E"Strategy.LIMITStrategy.NEXTBAR261.21);
        }
        if (
    getCurrentBarCount()>barcount && getCurrentBarCount()<=barcount+3)
        {
            if (
    Strategy.isLong())
            {
                
    Strategy.doSell("SL"Strategy.LIMITStrategy.NEXTBARStrategy.ALL61.17);
                
    debugPrintln("doSell is issued at bar "+getCurrentBarCount());
            }
            
    debugPrintln(getCurrentBarCount()+" "+high(0)+" "+low(0));
        }    

    This test efs is applied to CL #F using 1 minute interval. Time span must include Jan 02 2007, 9:53am and 3 subsequent bars.

    Below is the Formula Output, with the bottom line printed first in time and top line last in time.

    11 61.22 61.2
    10 61.21 61.19
    9 61.2 61.2
    doSell is issued at bar 9
    61.22 61.2
    3 61.27 61.26
    2 61.28 61.27
    1 61.27 61.27
    Attached is the image from Strategy Analyser.

    The problems are the following:

    1. when a doLong is issued for the nextbar at 9:53am on 1/2/2007 at limit price of 61.21, it entered at the next bar (9:54am) at 61.21 eventhough the next bar's high and low are both 60.20.

    2. When a doSell is issued at bar 9 (the bar the the Long order is executed) to exit next bar at limit 61.17, it executed at exactly 61.17 eventhough bar 10's high and low are 61.21 and 61.19.

    Did I do something wrong, or have I omitted something here?

    William
    Attached Files

  • #2
    Hello wwong112,

    When limit prices are specified with the Strategy methods, the Strategy Analyzer does not perform any price validation for you as you are expecting. This must be performed by your formula code. Please review the Back Testing tutorials where you can find more detailed information about this and how to write back testing formulas using limit orders.
    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
      I see. Thank you.

      W

      Comment


      • #4
        You're most welcome.
        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


        • #5
          By the way, Jason, I tried to specify the amount of contracts in Strategy.doLong, but is keeps on using the default fo 100. Do you how I can overide this?

          Thanks,
          William

          Comment


          • #6
            Hello William,

            If you are specifying a different lot amount in the .doLong() method, it should override the default lot size. Please post the code you are working with so I can see what might be happening.
            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


            • #7
              Below is the test code.

              PHP Code:
              var study = new MAStudy(400"Close"MAStudy.SIMPLE);

              var 
              barcount=0;

              function 
              preMain() {
                  
              setPriceStudy(true);
                  
              setColorPriceBars(true);
                  }

              function 
              main() {
              var 
              numcontract=500.123;
                  if (
              year(0)==2007 && month(0)==&& day(0)==&& hour(0)==&& minute(0)==53)
                  {
                      
              debugPrintln(high(0)+" "+low(0));
                      
              barcount=getCurrentBarCount();
                      
              Strategy.doLong("Re-E"Strategy.LIMITStrategy.THISBARnumcontract.toFixed(0), 61.21);
                  }
                  if (
              getCurrentBarCount()>barcount && getCurrentBarCount()<=barcount+3)
                  {
                      if (
              Strategy.isLong())
                      {
                          
              Strategy.doSell("SL"Strategy.LIMITStrategy.NEXTBARStrategy.ALL61.17);
                          
              debugPrintln("doSell is issued at bar "+getCurrentBarCount());
                      }
                      
              debugPrintln(getCurrentBarCount()+" "+high(0)+" "+low(0));
                  }    

              Comment


              • #8
                Hello William,

                It's not working because the result of numcontract.toFixed(0) is a string. The .toFixed() method converts the result to a string. The lot size parameter for the Strategy methods needs to be a number. You have two solutions available. The first is to multiply the expression by 1.

                Strategy.doLong("Re-E", Strategy.LIMIT, Strategy.THISBAR, numcontract.toFixed(0)*1, 61.21);

                Or you can apply the Math.round() method to the numcontract variable.

                Strategy.doLong("Re-E", Strategy.LIMIT, Strategy.THISBAR, Math.round(numcontract), 61.21);
                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


                • #9
                  Thank you, Jason.

                  By the way, how do I round a floating point variable to 2 decimal places? Which method is available?

                  Comment


                  • #10
                    Hello William,

                    In addition to the methods illustrated in my prior reply, you could also try the formatPriceNumber() function.
                    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