Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I found a bug that appears every so often...

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

    I found a bug that appears every so often...

    When ever I EnterLong() or EnterShort() from within a strategy, there are times when the Position.AvgPrice gives back a number of "0.0018" or something like this. Now there is NO WAY the position could have been opened at that low of number especially when the bid is more like 1.4019.

    Any ideas on how to work around this, or somehow help you guys figure out why then happens??? It doesn't do it EVERYTIME, but it does happen frequently.
    Last edited by VagyokC4; 09-28-2007, 07:46 AM.

    #2
    a) Position.AvgPrice is not aligned to ticksize but could be any "odd" price dependent on the prices of the execution building up the position
    b) Please provide a reproducible scenario in order to analyze. Thanks

    Comment


      #3
      Here's my code...

      Could it be that I'm checking that property too quickly. I.E. I enter the position then immediatly check that property.

      Do I need to wait for a second or two before checking the AvgPrice property?

      Here's my code:

      {
      EnterLong();
      double EntryPrice = Position.AvgPrice;
      Print(EntryPrice); // Somtimes is not an accurate number
      }

      Comment


        #4
        >> Could it be that I'm checking that property too quickly.
        Absolutely.
        a) realtime: market orders are not filled right away. Exchanges take a few milli seconds to fill orders (same on sim account).
        b) backtest: market order are only filled after you returned from the OnBarUpdate method.

        Comment


          #5
          Originally posted by NinjaTrader_Dierk View Post
          >> Could it be that I'm checking that property too quickly.
          Absolutely.
          a) realtime: market orders are not filled right away. Exchanges take a few milli seconds to fill orders (same on sim account).
          b) backtest: market order are only filled after you returned from the OnBarUpdate method.
          Ok,

          So my next two questions are:

          1) Does using Thread.Sleep have any adverse effect on the system?
          2) How long should I put the thread to sleep before checking the AvgPrice property so that I'm 99.9% guaranteed I get an accurate value?

          Ie.
          {
          EnterLong();
          System.Threading.Thread.Sleep(1000);
          double EntryPrice = Position.AvgPrice;
          }

          or do I need to wait for the next OnBarUpdate to be 100% accurate?
          Last edited by VagyokC4; 09-28-2007, 08:06 AM.

          Comment


            #6
            Thread.Sleep will not do what you are looking for. The only solution is checking Position.Quantity on every OnBarUpdate call if it has the expected quantity and then trigger next actions.

            Note: Upcoming NT6.5 (available in a few weeks) provides position update events which you could handle for finer granularity of control.

            Comment


              #7
              Originally posted by NinjaTrader_Dierk View Post
              Thread.Sleep will not do what you are looking for. The only solution is checking Position.Quantity on every OnBarUpdate call if it has the expected quantity and then trigger next actions.

              Note: Upcoming NT6.5 (available in a few weeks) provides position update events which you could handle for finer granularity of control.
              Can I do something like this???

              {
              // Assert Position.Quantity == 0
              EnterLong(5);
              While (Position.Quantity != 5)
              {
              }
              double EntryPrice = Position.AvgPrice;
              }

              Comment


                #8
                No, as pointed out below.

                Comment


                  #9
                  Originally posted by NinjaTrader_Dierk View Post
                  No, as pointed out below.
                  Thank-you for your help

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  563 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  329 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  547 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  548 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X