Announcement

Collapse
No announcement yet.

Does anybody really know....

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

  • Does anybody really know....

    what time it is?

    I have a study running on a 5 min chart. I issue a stoplimit buy order and wait for a fill. As soon as I get filled, I want to enter my stoplimit orders to close the position.

    If I use getCurrentBar=-1, the fill is not detected til the bar closes, maybe some 5 minutes later. I want to enter the stop order sooner than that.

    So I decided to use Date.getMinutes(), which apparently is a cpu hog.

    I was watching the minutes and check for a fill if the minutes increased. ie once per minute.

    Any one have any other ideas on how to monitor for an intra bar fill and then issue the stop limit orders mid bar with some other strategy?

  • #2
    Hm. Seems to me you don't need the one minute interval between checking for your fill. What's wrong with checking for the fill after every tick?

    Comment


    • #3
      Checking Order status every Tick

      David , what I use that appears to be working is the following :

      I let my EFS run on every tick (remove setComputeonClose)

      var BarState = getBarState();
      // This line gets the stat of your bar (1 minute or 100 Tick...)

      Only look for signals once per bar :

      if (BarState == BARSTATE_NEWBAR)
      // This statement allows entry to signal checking routines at the beginning of each new bar or in effect at the close of previous bar
      - if signal detected set Step =0 to kick-off orders .

      if (getCurrentBarIndex()==0) // runs every tick of current bar
      switch(Step)
      case 0: place order
      case 1: check order filled
      case 2: place stops & target orders

      // the above switch statement will run on every tick and you can complete the whole process in about 10 seconds or less .

      Hope this helps , Bill

      Comment


      • #4
        Dion and Bill

        Thanks for the ideas.

        Dion - I trade the ES and NQ so I was trying to minimize the amount of calcs on EVERY tick and just do it at some interval - balancing cpu usage with timely orders.

        Bill - I like some of the ideas you brought up, I never really understood the getbarstate stuff till y ou showed your example, I may try some of that.

        Comment


        • #5
          how about this?

          Hey Dave,

          I came across your post . . . I am not familiar with the switch statement, but I would love to see a more complete example here if Dion or Bill can post something up.

          I have the same exact problem, and the way I solved it was with the progressive states of several flags. I just trap the code in a section and keep it there until my condition is filled. Like . . . .

          ### ORDER IS ACTIVE AND OUT THERE
          if (order_fl==1) {
          whatever commands

          ### ORDER NOT FILLED
          if (filled==0) {
          check_if_filled;
          filled=1; ### if the fill went through
          }

          ### ORDER FILLED
          if (filled==1) {
          issue_stop_order;
          }
          }

          If anyone has a better idea, please let me know, but since this processes on every tick, I find it runs dirt fast, and the logic always hops back to where it left off. I know it seems simple, but does the trick nicely for me.

          Thomas.

          Comment


          • #6
            Here is what seems to work for me, and it only checks the situation once every minute, I can prolly write something to check every x seconds, but maybe later.

            //get current time in minutes, 0-59
            var today= new Date;
            var CurMin=today.getMinutes();

            //recalc all if the minute has increased
            if(CurMin>OldMin)
            {
            OldMin=CurMin; //save CurMin

            do the work...


            Here is the every x seconds code...

            //get current time in seconds, 0-59
            var today= new Date;
            var CurSec=today.getSeconds();

            //recalc all if the minute has increased
            if(CurSec>OldSec+xSecs)
            {
            OldSec=CurSec; //save CurSec

            PS Needs a var OldSec; and var OldMin; command somewhere

            Comment


            • #7
              PS - The routine only updates if the price changes - either up or down. If the last price = the current price, I don't think the efs file updates.

              In other words, an uptick or down tick is required to set off the efs calculations.

              Still seems like a bug to me.

              Comment


              • #8
                Order Checking on a Tick Basis

                There is a good example of how to use the Switch statement
                (like a Pascal Case statement) to cycle through order
                handling stuff in a filled call MomentumV1[1].53 posted on this site by Matt Briand . It has examples of order handling stuff +++. To make it run every tick remove the statement setComputeOnClose() from premain . Then in main add :

                var BarState = getBarState();

                if (BarState == BARSTATE_NEWBAR)
                - any code after this will run only once per bar such as checking
                for new signals
                - set the first state (Step =1) to kick off order handling
                else
                if (getCurrentBarIndex()==0)
                Switch(Step) // will run every tick
                {case 1 : send in Order ; Step =2
                case 2 : Monitor for fill : If filled Step =3
                This code will run on every tick until order filled
                Place Stops & Target orders if fill received
                case 3 : When Stop or Target filled set Step = 0 and go back
                and waite for next signal .

                Almost forgot : set up a Global Variable called Step to save order state between ticks .
                Let me know if you need more help . I am still debugging my stuff but I have seen this work many times so know the logic is sound .

                If you are trading a liquid item such as ES waiting for the next tick to check something should not be a concern at all . I would NOT have code loop until something happens as it gives you no way to handle other events like what if you don't get a fill for some reason and you get a signal that takes you in the other direction while your code waits on an event that will not happen .

                Let me know if you need further info or have some other ideas .

                Comment

                Working...
                X