Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 TraderBCL, Today, 04:38 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  105 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  607 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X