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

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.

    #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
    Brandon H.NinjaTrader Customer Service

    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

      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.


        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
          Brandon H.NinjaTrader Customer Service

          Comment


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

            Cheers

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by agclub, 04-21-2024, 08:57 PM
            4 responses
            18 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Irukandji, Today, 04:58 AM
            0 responses
            3 views
            0 likes
            Last Post Irukandji  
            Started by fitspressoburnfat, Today, 04:25 AM
            0 responses
            2 views
            0 likes
            Last Post fitspressoburnfat  
            Started by Skifree, Today, 03:41 AM
            1 response
            4 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by usazencort, Today, 01:16 AM
            0 responses
            4 views
            0 likes
            Last Post usazencort  
            Working...
            X