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

AvgFillPrice During Backtest

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

    AvgFillPrice During Backtest

    When I run backtest a strategy, the AvgFillPrice for all my orders (long or short, enter or exit) are zero.

    During market replay or live (real or sim) trading they are not zero.

    I am guessing that AvgFillPrice doesn't work in backtest? If that is the case, what is the best proxy?

    If that is not the case, what might the problem be?

    Note that the Status of the orders during backtest all show "Working" as described in NT7 documentation.

    Please advise.

    #2
    Hello x703jko,

    I have create a simple script to test this.

    Follow these steps to import the NinjaScript:
    1. Download the script to your desktop, keep it in the compressed .zip file.
    2. From the Control Center window select the menu File > Utilities > Import NinjaScript
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

    The script will output to the Output window. (Tools -> Output Window...)

    Please open this first, then add the script to a chart that has data on it.

    Then save the output from the output window. (Right-click the output window -> click Save As... -> select a place to save this where you can find it -> click Save)

    Then please attach the output to your next post.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea. Many thanks for the help. I see what I was doing incorrectly. I was assuming that during backtest the OrderStatus never reached Filled. However, I believe that what the NT7 documentation was saying was that during backtesting, the OrderStatus always reaches Working immediately after entry. Then, once OnOrderUpdate is called, OrderState during backtest then reaches Filled.

      My code is now doing what I expected.

      Many thanks!

      Comment


        #4
        Hello x703jko,

        OnOrderUpdate is triggered multiple times for an order.

        Below is a link to the help guide on OnOrderUpdate which lists the order states. OnOrderUpdate will be called for every order state that the order changes to. (Pending Submit -> Accepted -> Working -> Filled or Cancelled)

        http://ninjatrader.com/support/helpG...rderupdate.htm

        If the order has not filled or part filled, there will not be an AvgFillPrice. If the order has filled or part filled there will be an AvgFillPrice.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello x703jko,

          OnOrderUpdate is triggered multiple times for an order.

          Below is a link to the help guide on OnOrderUpdate which lists the order states. OnOrderUpdate will be called for every order state that the order changes to. (Pending Submit -> Accepted -> Working -> Filled or Cancelled)



          If the order has not filled or part filled, there will not be an AvgFillPrice. If the order has filled or part filled there will be an AvgFillPrice.
          This I understand. What I was referring to is the guidance in the help file for IOrder objects:

          "* In a historical backtest, orders will always reach a "Working" state."

          My incorrect assumption was that in a backtest the OrderState remained in the Working state and never progressed to Filled, etc.

          My code is working correctly now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 04-23-2024, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          193 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,235 views
          0 likes
          Last Post xiinteractive  
          Working...
          X