Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OrderState always in state "working"

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

    OrderState always in state "working"

    Hello everyone,

    I have created a strategy and I started working on creating Orders and Positions now.

    When I open a chart and then add a strategy and enable it, I can see all

    EnterShort()
    EnterLong() 's!

    Click image for larger version  Name:	2021-06-24 14_38_47-Chart - BBA_BTCUSD.png Views:	0 Size:	83.3 KB ID:	1161247


    But within the the strategy I need to identify the entire position volume.

    When I therefore try to use this.Account.Positions count, then these are always 0!
    Additionally the upper EnterLong/Short Orders are always in "working" state, never filled.

    Can you help me, to get this running?

    Thanks in advance.
    Airwave
    NinjaTrader Ecosystem Vendor - Airwave

    #2
    Hello Airwave,

    Thanks for your post.

    Getting the position quantity on your account could be accomplished by looping through positions in Account.Positions and printing out the position.Quantity. For example, please see the attached script which demonstrates looping through the positions in Account.Positions and printing out the account position Quantity, MarketPosition, and AverageFillPrice. Prints will appear in a New > NinjaScript Output window.

    I understand that you are saying the EnterLong/EnterShort orders are always in a Working state and never fill. However, in the screenshot you shared, I see that the orders are being filled. Please answer the following questions so that I may further investigate.
    • What data provider are you connected to? This is displayed in green on the lower-left corner of the Control Center window.
    • Who is your broker?
    • What instrument symbol (and expiry if applicable) have you selected? For example, ES 09-21, AAPL, EURUSD, etc.
    • (For a chart) what interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
    • When are you seeing the 'Working' state occur?
    See the help guide documentation below for more information.
    Account.Positions: https://ninjatrader.com/support/help...ns_account.htm

    Let us know if we may assist further.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello,

      So Im using Coinbase, Status is green (connected), Symbol is BTCUSD.
      Chart in 30 Minute.

      As I was looking into your code I saw, that you used account.positions in OnStateChange.
      I'm using it in OnBarUpdate, because I wanted to evaluate how "big" my current position is and depended on this, define how big the amount should be for the next EnterLong / EnterShort.


      I also found out now, that the OrderState is changing from working to filled. But the account.positions.count is always 0. Also if I have a filled position.

      Am I on the wrong way with account.positions? I want to use this also only for strategy performance testing.

      Thanks in advance.

      Cheers
      Airwave
      NinjaTrader Ecosystem Vendor - Airwave

      Comment


        #4
        Okay got it, think I was using wrong Object.

        It's this.Position, what I was searching for.


        But here I have an additional question.
        If there was executed only one order:
        order = EnterLong(100, "name");

        I was expecting
        this.Position.AveragePrice and
        order.AverageFillPrice should be the same value, but that isn't the case.

        Why not?

        Thanks in advance.


        Airwave
        NinjaTrader Ecosystem Vendor - Airwave

        Comment


          #5
          Hello Airwave,

          Thanks for your note.

          After testing placing an order using EnterLong() with a quantity of 100, I am seeing this.Position.AverageFillPrice printing the same value as order.AverageFillPrice. See the attached screenshot demonstrating this.

          Please see the attached test strategy, MyTestStrategy, which calls EnterLong(100, "MyEntry") to place an order and then prints out this.Position.AverageFillPrice and order.AverageFillPrice to the NinjaScript Output window. When testing the attached strategy example, do you see the same values printing in the Output window for this.Position.AverageFillPrice and order.AverageFillPrice?

          Let us know if we may assist further.
          Attached Files
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Thank you. That helped a lot :-)

            Cheers
            Airwave
            NinjaTrader Ecosystem Vendor - Airwave

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            44 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            65 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X